This repository has been archived on 2018-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
sotdbot/bot.py

57 lines
1.7 KiB
Python
Raw Normal View History

import teambot, sys
2018-11-15 01:04:44 +00:00
USAGE = dict(admin="Stop trying to use this command!",sotd="{}sotd <link> <name>")
PUBLIC_COMMANDS = ["sotd"]
SOTDS = dict()
def get_title(link):
return link # TODO: actually make this get the title of a link.
2018-11-15 00:26:43 +00:00
class SOTDBot(teambot.Handler,teambot.CommandHandlerMixin):
2018-11-15 01:07:05 +00:00
def __init__(self,*args):
self.prefix = "!"
self.botop = "khuxkm"
2018-11-15 01:07:05 +00:00
super(SOTDBot,self).__init__(*args)
2018-11-15 00:26:43 +00:00
def handle_command(self,target,nick,text):
if not text.startswith(self.prefix):
return
self.target = target if target!=self._bot.nick else nick
self.sourcenick = nick
args = text[len(self.prefix):].split()
cmd = args.pop(0)
if hasattr(self,"do_"+cmd.lower()):
try:
getattr(self,"do_"+cmd.lower())(*args)
except TypeError as e:
2018-11-15 01:04:44 +00:00
self.say(self.target,"{}: Usage: {}".format(nick,USAGE[command.lower()].format(self.prefix)))
elif text in ("!botlist","!rollcall"):
self.do_botlist()
def do_admin(self,*args):
2018-11-15 01:04:44 +00:00
if self.sourcenick!=self.botop:
self.say(target,self.sourcenick+": You can't tell me what to do!")
return
args = list(args)
subcmd = args.pop(0)
if subcmd=="down":
self._bot.die("Bye bye!")
elif subcmd=="prefix":
self.prefix = args[0]
def do_botlist(self):
self.say(self.target,"Maintainer: khuxkm | commands: {}".format(", ".join("{}{}".format(self.prefix,cmd) for cmd in PUBLIC_COMMANDS)))
2018-11-15 00:26:43 +00:00
2018-11-15 01:04:44 +00:00
def do_sotd(self,link,*name):
if name:
name = " ".join(name)
else:
name = get_title(link)
SOTDS[self.sourcenick] = (name,link)
self.say(self.target,self.sourcenick+": Your SOTD has been set to {}.".format(name))
2018-11-15 00:26:43 +00:00
if __name__=="__main__":
channels = "#bots".split()
bot = teambot.TeamBot(channels,"sotdbot","localhost",chandler=SOTDBot)
bot.start()