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

44 lines
1.3 KiB
Python

import teambot, sys
USAGE = dict(admin="Stop trying to use this command!")
PUBLIC_COMMANDS = []
class SOTDBot(teambot.Handler,teambot.CommandHandlerMixin):
def __init__(self):
self.prefix = "!"
self.botop = "khuxkm"
super(SOTDBot,self).__init__()
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:
self.say(self.target,"{}: Usage: {}".format(nick,USAGE[command.lower()]))
elif text in ("!botlist","!rollcall"):
self.do_botlist()
def do_admin(self,*args):
if nick!=self.botop:
self.say(target,nick+": 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)))
if __name__=="__main__":
channels = "#bots".split()
bot = teambot.TeamBot(channels,"sotdbot","localhost",chandler=SOTDBot)
bot.start()