2018-09-13 20:12:18 +00:00
|
|
|
|
from sys import exit
|
2018-09-13 06:10:50 +00:00
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
|
|
import config as cfg
|
|
|
|
|
from irc import IRC
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Ramen:
|
2018-09-14 05:54:21 +00:00
|
|
|
|
"""Requests with a ramen theme."""
|
2018-09-13 06:10:50 +00:00
|
|
|
|
|
2018-09-14 05:54:21 +00:00
|
|
|
|
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)
|
2018-09-13 06:10:50 +00:00
|
|
|
|
|
2018-09-14 05:54:21 +00:00
|
|
|
|
def handle(self, msg, channel):
|
|
|
|
|
"""Listen for requests in a channel and match them to functions."""
|
|
|
|
|
self.msg = msg
|
2018-09-13 20:12:18 +00:00
|
|
|
|
if self.msg["req_chan"] == cfg.bot_nick:
|
2018-09-13 06:10:50 +00:00
|
|
|
|
# Respond to some commands only from admin user
|
2018-09-13 20:12:18 +00:00
|
|
|
|
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)
|
2018-09-13 06:10:50 +00:00
|
|
|
|
|
|
|
|
|
# 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()
|
2018-09-13 20:12:18 +00:00
|
|
|
|
elif self.msg["req"] == ("water " + cfg.bot_nick):
|
2018-09-13 06:10:50 +00:00
|
|
|
|
self.handle_water()
|
2018-09-13 20:12:18 +00:00
|
|
|
|
elif self.msg["req"] == ("botsnack " + cfg.bot_nick):
|
2018-09-13 06:10:50 +00:00
|
|
|
|
self.handle_botsnack()
|
|
|
|
|
|
|
|
|
|
def handle_admin_req(self, req, admin_user):
|
2018-09-13 20:12:18 +00:00
|
|
|
|
"""Perform admin functions."""
|
2018-09-13 06:10:50 +00:00
|
|
|
|
if "exit" in req:
|
|
|
|
|
self.irc.send("PRIVMSG", "Okay, okay, I'll leave. (´・ω・`)", \
|
2018-09-13 20:12:18 +00:00
|
|
|
|
recvr=admin_user)
|
|
|
|
|
self.irc.send("QUIT", ":noodling off")
|
|
|
|
|
exit("Shutting down ...")
|
2018-09-13 06:10:50 +00:00
|
|
|
|
|
|
|
|
|
def handle_rollcall(self):
|
|
|
|
|
resp = (
|
|
|
|
|
"一、二、三、らーめん缶! "
|
|
|
|
|
"Hello, I am a ramen vending machine. "
|
|
|
|
|
"Please type a code for service: "
|
|
|
|
|
"!help "
|
|
|
|
|
"Support: +81 012-700-1MIO どうぞめしあがれ。"
|
|
|
|
|
)
|
2018-09-13 20:12:18 +00:00
|
|
|
|
self.irc.send("PRIVMSG", resp, recvr=self.msg["req_chan"])
|
2018-09-13 06:10:50 +00:00
|
|
|
|
|
|
|
|
|
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)], \
|
2018-09-13 20:12:18 +00:00
|
|
|
|
recvr=self.msg["req_chan"])
|
2018-09-13 06:10:50 +00:00
|
|
|
|
|
|
|
|
|
def handle_botsnack(self):
|
|
|
|
|
self.irc.send("PRIVMSG", "Ramen time anytime! ヽ(´▽`)/", \
|
2018-09-13 20:12:18 +00:00
|
|
|
|
recvr=self.msg["req_chan"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = Ramen()
|
2018-09-14 05:54:21 +00:00
|
|
|
|
app.main()
|