from sys import exit 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 pass in the request handler.""" self.irc = IRC() self.irc.debug = cfg.debug self.irc.run(self.handle, cfg) def handle(self, msg, channel): """Listen for requests in a channel and match them to functions.""" self.msg = msg if self.msg["req_chan"] == cfg.bot_nick: # Respond to some commands only from admin user if self.msg["user"].lower() == cfg.admin_user.lower() and \ cfg.admin_code in self.msg["req"]: self.handle_admin_req(self.msg["req"], cfg.admin_user) # Respond only in the channel the request was made if channel == self.msg["req_chan"]: # General commands if self.msg["req"] == "rollcall" or self.msg["req"] == "help": self.handle_rollcall() elif self.msg["req"] == ("water " + cfg.bot_nick): self.handle_water() elif self.msg["req"] == ("botsnack " + cfg.bot_nick): self.handle_botsnack() def handle_admin_req(self, req, admin_user): """Perform admin functions.""" if "exit" in req: self.irc.send("PRIVMSG", "Okay, okay, I'll leave. (´・ω・`)", \ recvr=admin_user) self.irc.send("QUIT", ":noodling off") exit("Shutting down ...") def handle_rollcall(self): resp = ( "一、二、三、らーめん缶! " "Hello, I am a ramen vending machine. " "Please type a code for service: " "!help " "Support: +81 012-700-1MIO どうぞめしあがれ。" ) self.irc.send("PRIVMSG", resp, recvr=self.msg["req_chan"]) def handle_water(self): resp = [ ("\x01ACTION happily pours the hot liquid into a bowl of noodles " "and offers it to ") + self.msg["nick"] + "\x01", "( ^_^)o自自o(^_^ )Cheers!", "Water Level [/////////] 200% - Thanks! (^▽^)" ] self.irc.send("PRIVMSG", resp[randint(0, len(resp)-1)], \ recvr=self.msg["req_chan"]) def handle_botsnack(self): self.irc.send("PRIVMSG", "Ramen time anytime! ヽ(´▽`)/", \ recvr=self.msg["req_chan"]) app = Ramen() app.main()