64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import yaml
|
||
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.links = self.util.yml("ramenkan/links.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, "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 !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",
|
||
"( ^_^)o自自o(^_^ )Cheers!",
|
||
"Water Level [/////////] 200% - Thanks! (^▽^)"
|
||
]
|
||
self.irc.reply(cxt, resp[randint(0, len(resp)-1)])
|
||
|
||
def botsnack(self, cxt):
|
||
self.irc.reply(cxt, "Ramen time anytime! 自o(´▽`)/")
|
||
|
||
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()
|
||
app.main()
|