itte/ramenkan.py

126 lines
4.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from random import randint
from itte import IRC, Util
class Ramen:
"""Requests with a ramen theme."""
def main(self):
"""Instantiate an IRC object and attach the listeners."""
# Load yaml sources used by request handlers
self.util = Util()
self.rand = self.util.rand
self.links = self.util.yml("ramenkan/links.yml")
self.dishes = self.util.yml("ramenkan/dishes.yml")
# Init irc object
self.irc = IRC()
self.cfg = self.irc.config("ramenkan/config.sample.yml")
self.irc.run(self.add_listeners)
def add_listeners(self, cxt):
"""Map triggers to handlers."""
self.irc.listen(cxt, "exit " + self.cfg["admin"]["code"], self.quit, \
admin=True)
self.irc.listen(cxt, "rollcall", self.rollcall)
self.irc.listen(cxt, "help", self.rollcall)
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, "ramen", self.ramen)
self.irc.listen(cxt, "rk", self.ramen)
self.irc.listen(cxt, "rklink", self.link)
def quit(self, cxt):
"""Disconnect from the server and quit."""
self.irc.disconnect("Okay, okay, I'll leave. (´・ω・`)", "noodling off")
def rollcall(self, cxt):
resp = (
"一、二、三、らーめん缶! "
"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):
resp = [
("\x01ACTION happily pours the hot liquid into a bowl of noodles "
"and offers it to ") + cxt["msg"]["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* ┐('∀`)┌")
]
self.irc.reply(cxt, self.rand(resp))
def botsnack(self, cxt):
resp = [
"CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!",
"Ramen time anytime! 自o(´▽` )/"
]
self.irc.reply(cxt, self.rand(resp))
def make_ramen_combo(self):
dish = self.dishes
combo = "ramen in "
# Noodle type and broth richness
if randint(0, 1):
combo = self.rand(dish["noodle-shape"]) + ", " + \
self.rand(dish["noodle-broth-type"]) + " "
combo = combo.capitalize()
# Broth type
combo += self.rand(dish["broth"] + dish["broth-veggie"]) + " broth"
# Topping
n_top = randint(2, 4)
for n in range(2, n_top+1):
if n == 2:
prev_top = self.rand(dish["topping"] + dish["meat"])
combo += " with " + prev_top
else:
if n > 2 and n < n_top:
combo += ", "
else:
combo += " and "
next_top = self.rand(dish["topping"] + dish["meat"])
# Check for duplicate
if next_top == prev_top:
next_top = self.rand(dish["topping"])
combo += next_top
prev_top = next_top
# Condiment and side dish
if randint(0, 1):
combo += ", garnished with " + self.rand(dish["condiment"]) + "."
else:
combo += "."
if randint(0, 1):
combo += " Served with " + self.rand(dish["tapa"] + \
dish["tapa-veggie"]) + "."
return combo
def ramen(self, cxt):
roll = randint(1, 100)
# 1% possibility of regional preset
if roll == 100:
resp = (self.rand(self.dishes["set"] + \
self.dishes["set-veggie"]) + ".").capitalize()
else:
resp = self.make_ramen_combo()
self.irc.reply(cxt, resp)
def link(self, cxt):
index = randint(0, len(self.links)-1)
self.irc.reply(cxt, self.links[index]["title"] + " " + \
self.links[index]["link"])
app = Ramen()
app.main()