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

25 lines
979 B
Python

import teambot,network,prefer,time
ROOT = "/home/khuxkm/code/auditbot/"
opts = prefer.Preferences(ROOT+"prefs.json")
bbj = network.BBJ(port=opts.get("port",7099))
if not bbj.set_credentials(opts.get("username"),opts.get("password")):
raise Exception("Incorrect details provided")
if not opts.get("thread_id"):
thread = bbj.thread_create(opts.get("title"),opts.get("text"))
opts.set("thread_id",thread["thread_id"])
trigger = lambda x: "{}: ".format(x)
log = lambda x,e: e[len(trigger(x)):]
class AuditBot(teambot.Handler,teambot.CommandHandlerMixin):
def handle_command(self,target,nick,text):
if nick.split("|")[0] in opts.get("sudoers") and text.startswith(trigger(self.bot.bot_nick)):
bbj.thread_reply(opts.get("thread_id"),opts.get("format").format(time.strftime("%Y-%m-%d %H:%M:%S"),nick,log(self.bot.bot_nick,text)))
if __name__=="__main__":
channels = "#sudoers".split()
bot = teambot.TeamBot(channels,"auditor","localhost",chandler=AuditBot)
bot.start()