Add veggie ramen handler, move other handler text to yml

trunk
mio 2018-09-17 05:22:18 +00:00
parent 542976eb9d
commit 0c3ba15173
4 changed files with 72 additions and 34 deletions

View File

@ -19,6 +19,7 @@ class Util:
"""Return a random item from a given list.""" """Return a random item from a given list."""
return lst[randint(0, len(lst)-1)] return lst[randint(0, len(lst)-1)]
class IRC: class IRC:
"""Methods for basic IRC communication.""" """Methods for basic IRC communication."""

View File

@ -11,6 +11,7 @@ class Ramen:
# Load yaml sources used by request handlers # Load yaml sources used by request handlers
self.util = Util() self.util = Util()
self.rand = self.util.rand self.rand = self.util.rand
self.std = self.util.yml("ramenkan/standard.yml")
self.links = self.util.yml("ramenkan/links.yml") self.links = self.util.yml("ramenkan/links.yml")
self.dishes = self.util.yml("ramenkan/dishes.yml") self.dishes = self.util.yml("ramenkan/dishes.yml")
# Init irc object # Init irc object
@ -27,7 +28,9 @@ class Ramen:
self.irc.listen(cxt, "water " + self.cfg["bot_nick"], self.water) self.irc.listen(cxt, "water " + self.cfg["bot_nick"], self.water)
self.irc.listen(cxt, "botsnack " + self.cfg["bot_nick"], self.botsnack) self.irc.listen(cxt, "botsnack " + self.cfg["bot_nick"], self.botsnack)
self.irc.listen(cxt, "ramen", self.ramen) self.irc.listen(cxt, "ramen", self.ramen)
self.irc.listen(cxt, "veggieramen", self.ramen_veggie)
self.irc.listen(cxt, "rk", self.ramen) self.irc.listen(cxt, "rk", self.ramen)
self.irc.listen(cxt, "rkveg", self.ramen_veggie)
self.irc.listen(cxt, "rklink", self.link) self.irc.listen(cxt, "rklink", self.link)
def quit(self, cxt): def quit(self, cxt):
@ -35,41 +38,28 @@ class Ramen:
self.irc.disconnect("Okay, okay, I'll leave. (´・ω・`)", "noodling off") self.irc.disconnect("Okay, okay, I'll leave. (´・ω・`)", "noodling off")
def rollcall(self, cxt): def rollcall(self, cxt):
resp = ( """Handle request for app info."""
"一、二、三、らーめん缶! " self.irc.reply(cxt, self.std["rollcall"])
"Hello, I am a ramen vending machine. "
"Please type a code for service: "
"!help !ramen !rklink - "
"Support: +81 012-700-1MIO どうぞめしあがれ。"
)
self.irc.reply(cxt, resp)
def water(self, cxt): def water(self, cxt):
resp = [ """Handle water offer."""
("\x01ACTION happily pours the hot liquid into a bowl of noodles " resp = self.std["water"]
"and offers it to ") + cxt["msg"]["nick"] + "\x01", for index, r in enumerate(resp):
"Cheers! 自o^_^ ", if "{{ nick }}" in r:
"Water Level [/////////] 200% - Thanks! (^▽^ )", resp.append(r.replace("{{ nick }}", cxt["msg"]["nick"]))
("Thanks. Some people say I have a CRABby tempeRAMENt. " resp.pop(index)
"I wonder why. ´-` "),
("Q. What do you call noodles made from the core of a tree? "
"A. DuRAMEN. *ba dum tss* ┐('∀`)┌"),
("Q. What do you call noodles eaten on bulletin boards? "
"A. FoRAMEN. *ba dum tss* ┐('∀`)┌"),
("Q. What kind of noodles can be found at TV stations? "
"A. CameRAMEN. *ba dum tss* ┐('∀`)┌")
]
self.irc.reply(cxt, self.rand(resp)) self.irc.reply(cxt, self.rand(resp))
def botsnack(self, cxt): def botsnack(self, cxt):
resp = [ """Handle snack offer."""
"CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!", self.irc.reply(cxt, self.rand(self.std["botsnack"]))
"Ramen time anytime! 自o(´▽` )/"
]
self.irc.reply(cxt, self.rand(resp))
def make_ramen_combo(self): def make_ramen_combo(self, *args, **kwargs):
"""Generate a ramen dish. Optionally pass `veggie=True` for a
vegetarian dish."""
dish = self.dishes dish = self.dishes
# Check vegetarian flag
is_veggie = kwargs.get("veggie", False)
combo = "ramen in " combo = "ramen in "
# Noodle type and broth richness # Noodle type and broth richness
if randint(0, 1): if randint(0, 1):
@ -77,19 +67,29 @@ class Ramen:
self.rand(dish["noodle-broth-type"]) + " " self.rand(dish["noodle-broth-type"]) + " "
combo = combo.capitalize() combo = combo.capitalize()
# Broth type # Broth type
combo += self.rand(dish["broth"] + dish["broth-veggie"]) + " broth" if is_veggie:
combo += self.rand(dish["broth-veggie"])
else:
combo += self.rand(dish["broth"] + dish["broth-veggie"])
combo += " broth"
# Topping # Topping
n_top = randint(2, 4) n_top = randint(2, 4)
for n in range(2, n_top+1): for n in range(2, n_top+1):
if n == 2: if n == 2:
prev_top = self.rand(dish["topping"] + dish["meat"]) if is_veggie:
prev_top = self.rand(dish["topping"])
else:
prev_top = self.rand(dish["topping"] + dish["meat"])
combo += " with " + prev_top combo += " with " + prev_top
else: else:
if n > 2 and n < n_top: if n > 2 and n < n_top:
combo += ", " combo += ", "
else: else:
combo += " and " combo += " and "
next_top = self.rand(dish["topping"] + dish["meat"]) if is_veggie:
next_top = self.rand(dish["topping"])
else:
next_top = self.rand(dish["topping"])
# Check for duplicate # Check for duplicate
if next_top == prev_top: if next_top == prev_top:
next_top = self.rand(dish["topping"]) next_top = self.rand(dish["topping"])
@ -101,11 +101,15 @@ class Ramen:
else: else:
combo += "." combo += "."
if randint(0, 1): if randint(0, 1):
combo += " Served with " + self.rand(dish["tapa"] + \ combo += " Served with "
dish["tapa-veggie"]) + "." if is_veggie:
combo += self.rand(dish["tapa-veggie"]) + "."
else:
combo += self.rand(dish["tapa"] + dish["tapa-veggie"]) + "."
return combo return combo
def ramen(self, cxt): def ramen(self, cxt):
"""Handle ramen request."""
roll = randint(1, 100) roll = randint(1, 100)
# 1% possibility of regional preset # 1% possibility of regional preset
if roll == 100: if roll == 100:
@ -115,7 +119,17 @@ class Ramen:
resp = self.make_ramen_combo() resp = self.make_ramen_combo()
self.irc.reply(cxt, resp) self.irc.reply(cxt, resp)
def ramen_veggie(self, cxt):
"""Handle vegetarian ramen request."""
roll = randint(1, 100)
if roll == 100:
resp = (self.dishes["set-veggie"] + ".").capitalize()
else:
resp = self.make_ramen_combo(veggie=True)
self.irc.reply(cxt, resp)
def link(self, cxt): def link(self, cxt):
"""Handle to display a link."""
index = randint(0, len(self.links)-1) index = randint(0, len(self.links)-1)
self.irc.reply(cxt, self.links[index]["title"] + " " + \ self.irc.reply(cxt, self.links[index]["title"] + " " + \
self.links[index]["link"]) self.links[index]["link"])

View File

@ -17,4 +17,4 @@ admin:
req_prefix: "!" req_prefix: "!"
# Print messages to stdout # Print messages to stdout
debug: True debug: False

View File

@ -0,0 +1,23 @@
rollcall:
"一、二、三、らーめん缶!
Hello, I am a ramen vending machine. Please type a code for service:
!help !ramen !veggieramen !rklink
- Support: +81 012-700-1MIO どうぞめしあがれ。"
water:
- "\x01ACTION happily pours the hot liquid into a bowl of noodles
and offers it to {{ nick }}\x01"
- "Cheers! 自o^_^ "
- "Water Level [/////////] 200% - Thanks! (^▽^ )"
- "Thanks. Some people say I have a CRABby tempeRAMENt.
I wonder why. ´-` "
- "Q. What do you call noodles made from the core of a tree?
A. DuRAMEN. *ba dum tss* ┐('∀`)┌"
- "Q. What do you call noodles eaten on bulletin boards?
A. FoRAMEN. *ba dum tss* ┐('∀`)┌"
- "Q. What kind of noodles can be found at TV stations?
A. CameRAMEN. *ba dum tss* ┐('∀`)┌"
botsnack:
- "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!"
- "Ramen time anytime! 自o(´▽` )/"