reloading thread watcher doesn't spawn duplicate threads

This commit is contained in:
iou1name 2018-02-13 16:50:49 -05:00
parent fb2637a14e
commit 6ef18ff0be

View File

@ -13,6 +13,7 @@ def setup(bot):
"""
Establishes the bot's dictionary of watched threads.
"""
if not bot.memory.get("watcher"):
bot.memory["watcher"] = {}
con = bot.db.connect()
@ -30,6 +31,8 @@ def setup(bot):
con.close()
else:
for thread in watching:
if get_thread_url(thread[0]) in bot.memory["watcher"].keys():
continue
t = WatcherThread(bot, thread[0], thread[1], thread[2], thread[3],
thread[4])
t.start()
@ -167,7 +170,7 @@ class WatcherThread(threading.Thread):
if res.status_code == 404:
msg = "[\x0304Watcher\x03] Thread deleted: " \
+ f"\x0307{get_thread_url(self.api_url)}"
self.bot.say(msg, channel)
self.bot.say(msg, self.channel)
self.stop.set()
continue
@ -178,7 +181,7 @@ class WatcherThread(threading.Thread):
if thread["posts"][0].get("closed"):
msg = "[\x0304Watcher\x03] Thread closed: " \
+ f"\x0307{get_thread_url(self.api_url)}"
self.bot.say(msg, channel)
self.bot.say(msg, self.channel)
self.stop.set()
continue
@ -187,5 +190,5 @@ class WatcherThread(threading.Thread):
self.last_post = new_last_post
msg = "[\x0304Watcher\x03] New post from \x0308" \
+ f"{self.name}\x03 in \x0307{get_thread_url(self.api_url)}"
self.bot.say(msg, channel)
self.bot.say(msg, self.channel)