from random import randint import config as cfg from irc import IRC class Ramen: """Requests with a ramen theme.""" def main(self): """Instantiate an IRC object and attach the listeners.""" self.irc = IRC() self.irc.debug = cfg.debug self.irc.run(self.add_listeners, cfg) def add_listeners(self, cxt): """Map triggers to handlers.""" self.irc.listen(cxt, "exit " + 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 " + cfg.bot_nick, self.water) self.irc.listen(cxt, "botsnack " + cfg.bot_nick, self.botsnack) 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 " "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(´▽`)/") app = Ramen() app.main()