2018-07-20 19:48:06 +00:00
|
|
|
import teambot,network,prefer,time,sys
|
|
|
|
from colorama import init, Fore, Style
|
|
|
|
ENDF = Style.RESET_ALL
|
2018-07-20 19:20:55 +00:00
|
|
|
|
|
|
|
ROOT = "/home/khuxkm/code/auditbot/"
|
|
|
|
|
|
|
|
opts = prefer.Preferences(ROOT+"prefs.json")
|
2018-07-20 19:48:06 +00:00
|
|
|
|
|
|
|
VERBOSE = opts.get("verbose")
|
|
|
|
COLORS = {"*":"cyan","!":"yellow","X":"red"}
|
|
|
|
def say_log(s,p="*",c=None):
|
|
|
|
if c is None:
|
|
|
|
c = COLORS.get(p,None)
|
|
|
|
c = getattr(Fore,c.upper())
|
|
|
|
print(c+"[{}] {}".format(p,s)+ENDF)
|
|
|
|
|
2018-07-20 19:20:55 +00:00
|
|
|
bbj = network.BBJ(port=opts.get("port",7099))
|
2018-07-20 19:48:06 +00:00
|
|
|
say_log("Logging in with username {} and password {}...".format(opts.get("username"),opts.get("password")))
|
2018-07-20 19:20:55 +00:00
|
|
|
if not bbj.set_credentials(opts.get("username"),opts.get("password")):
|
2018-07-20 19:48:06 +00:00
|
|
|
say_log("Incorrect details provided","X")
|
|
|
|
sys.exit(1)
|
2018-07-20 19:20:55 +00:00
|
|
|
if not opts.get("thread_id"):
|
2018-07-20 19:48:06 +00:00
|
|
|
say_log("Creating thread...")
|
2018-07-20 19:20:55 +00:00
|
|
|
thread = bbj.thread_create(opts.get("title"),opts.get("text"))
|
|
|
|
opts.set("thread_id",thread["thread_id"])
|
2018-07-20 19:48:06 +00:00
|
|
|
say_log("...and BBJ is all set up!")
|
2018-07-20 19:20:55 +00:00
|
|
|
|
|
|
|
trigger = lambda x: "{}: ".format(x)
|
|
|
|
log = lambda x,e: e[len(trigger(x)):]
|
|
|
|
|
2018-07-20 20:58:07 +00:00
|
|
|
class AuditBot(teambot.Handler):
|
|
|
|
def on_pubmsg(self,target,nick,text):
|
2018-07-20 19:48:06 +00:00
|
|
|
nick = nick.split("|")[0]
|
2018-07-20 20:58:07 +00:00
|
|
|
say_log("[{}] {}: {}".format(target,nick,text))
|
2018-07-21 11:57:08 +00:00
|
|
|
if text.startswith(trigger(self._bot.bot_nick)):
|
|
|
|
if nick in opts.get("sudoers"):
|
|
|
|
say_log("{} is auditing \"{}\"".format(nick,log(self._bot.bot_nick,text)),"!","green")
|
|
|
|
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)))
|
|
|
|
# say_log(repr(r))
|
2018-07-26 20:06:17 +00:00
|
|
|
self.say(target,"{}: audited!".format(nick))
|
2018-07-21 11:57:08 +00:00
|
|
|
else:
|
2018-07-21 12:04:52 +00:00
|
|
|
say_log("{} is auditing \"{}\" but is not a sudoer!".format(nick,log(self._bot.bot_nick,text)),"X")
|
2018-07-21 12:17:02 +00:00
|
|
|
self.say(target,"{}: you aren't a sudoer!".format(nick))
|
2018-07-20 19:20:55 +00:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
channels = "#sudoers".split()
|
|
|
|
bot = teambot.TeamBot(channels,"auditor","localhost",chandler=AuditBot)
|
2018-07-20 19:48:06 +00:00
|
|
|
say_log("Starting IRC bot...")
|
2018-07-20 19:20:55 +00:00
|
|
|
bot.start()
|