From 2bd7d74e919200a29a8e7e3227345e6564a4be31 Mon Sep 17 00:00:00 2001 From: iou1name Date: Sun, 23 Sep 2018 00:47:03 -0400 Subject: [PATCH] added notice subscriptions --- warbot.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/warbot.py b/warbot.py index 7aa3c2d..49376d9 100755 --- a/warbot.py +++ b/warbot.py @@ -53,6 +53,7 @@ class WarBot(irc.IRCClient): self.clockThread.start() self.alert_ids = [] + self.subs = {} def stillConnected(self): @@ -63,16 +64,6 @@ class WarBot(irc.IRCClient): return False - def clock(self): - """ - A continous loop which calls the processing functions once per - minute. Should only be ran in a separate thread. - """ - while not stop.is_set(): - self.checkNewAlerts() - stop.wait(60) - - def checkNewAlerts(self, channel=None): """ Checks the world state for new alerts or invasions. @@ -151,6 +142,11 @@ class WarBot(irc.IRCClient): self.msg(channel, message) + for user, subs in self.subs.items(): + for sub in subs: + if sub.lower() in message.lower(): + self.notice(user.partition('!')[0], message) + def privmsg(self, user, channel, message): """ @@ -162,6 +158,32 @@ class WarBot(irc.IRCClient): self.checkNewAlerts(channel) return + if message.startswith(".subscribe "): + sub = message.replace(".subscribe ", "") + if not self.subs.get(user): + self.subs[user] = [] + self.subs[user].append(sub) + + msg = "\x0310Current subscriptions\x03: [\x0308" + msg += "\x03, \x0308".join(self.subs[user]) + msg += "\x03]" + self.notice(user.partition('!')[0], msg) + return + + if message.startswith(".unsubscribe "): + sub = message.replace(".unsubscribe ", "") + if not self.subs.get(user): + return + if not sub in self.subs[user]: + return + self.subs[user].remove(sub) + + msg = "\x0310Current subscriptions\x03: [\x0308" + msg += "\x03, \x0308".join(self.subs[user]) + msg += "\x03]" + self.notice(user.partition('!')[0], msg) + return + def joined(self, channel): """Called when the bot joins a new channel."""