itte/ramenkan.py

64 lines
2.1 KiB
Python
Raw Normal View History

2018-09-16 04:48:50 +00:00
import yaml
from random import randint
2018-09-16 04:48:50 +00:00
from itte import IRC, Util
class Ramen:
2018-09-14 05:54:21 +00:00
"""Requests with a ramen theme."""
2018-09-14 05:54:21 +00:00
def main(self):
2018-09-14 23:37:47 +00:00
"""Instantiate an IRC object and attach the listeners."""
2018-09-16 04:48:50 +00:00
# Load yaml sources used by request handlers
self.util = Util()
self.links = self.util.yml("ramenkan/links.yml")
# Init irc object
2018-09-14 05:54:21 +00:00
self.irc = IRC()
2018-09-16 04:48:50 +00:00
self.cfg = self.irc.config("ramenkan/config.sample.yml")
2018-09-15 23:18:44 +00:00
self.irc.run(self.add_listeners)
2018-09-14 23:37:47 +00:00
def add_listeners(self, cxt):
"""Map triggers to handlers."""
2018-09-15 23:18:44 +00:00
self.irc.listen(cxt, "exit " + self.cfg["admin"]["code"], self.quit, \
admin=True)
2018-09-14 23:37:47 +00:00
self.irc.listen(cxt, "rollcall", self.rollcall)
self.irc.listen(cxt, "help", self.rollcall)
2018-09-15 23:18:44 +00:00
self.irc.listen(cxt, "water " + self.cfg["bot_nick"], self.water)
self.irc.listen(cxt, "botsnack " + self.cfg["bot_nick"], self.botsnack)
2018-09-16 04:48:50 +00:00
self.irc.listen(cxt, "rklink", self.link)
2018-09-14 23:37:47 +00:00
def quit(self, cxt):
"""Disconnect from the server and quit."""
self.irc.disconnect("Okay, okay, I'll leave. (´・ω・`)", "noodling off")
2018-09-14 23:37:47 +00:00
def rollcall(self, cxt):
resp = (
"一、二、三、らーめん缶! "
"Hello, I am a ramen vending machine. "
"Please type a code for service: "
2018-09-16 04:48:50 +00:00
"!help !rklink - "
"Support: +81 012-700-1MIO どうぞめしあがれ。"
)
2018-09-14 23:37:47 +00:00
self.irc.reply(cxt, resp)
2018-09-14 23:37:47 +00:00
def water(self, cxt):
resp = [
("\x01ACTION happily pours the hot liquid into a bowl of noodles "
2018-09-14 23:37:47 +00:00
"and offers it to ") + cxt["msg"]["nick"] + "\x01",
" ^_^o自自o^_^ Cheers!",
"Water Level [/////////] 200% - Thanks! (^▽^)"
]
2018-09-14 23:37:47 +00:00
self.irc.reply(cxt, resp[randint(0, len(resp)-1)])
2018-09-14 23:37:47 +00:00
def botsnack(self, cxt):
self.irc.reply(cxt, "Ramen time anytime! 自o(´▽`)/")
2018-09-16 04:48:50 +00:00
def link(self, cxt):
rand = randint(0, len(self.links)-1)
self.irc.reply(cxt, self.links[rand]["title"] + " " + \
self.links[rand]["link"])
app = Ramen()
2018-09-14 05:54:21 +00:00
app.main()