added notice subscriptions
This commit is contained in:
parent
6696c15152
commit
2bd7d74e91
42
warbot.py
42
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."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user