reloading thread watcher doesn't spawn duplicate threads
This commit is contained in:
parent
fb2637a14e
commit
6ef18ff0be
|
@ -13,6 +13,7 @@ def setup(bot):
|
||||||
"""
|
"""
|
||||||
Establishes the bot's dictionary of watched threads.
|
Establishes the bot's dictionary of watched threads.
|
||||||
"""
|
"""
|
||||||
|
if not bot.memory.get("watcher"):
|
||||||
bot.memory["watcher"] = {}
|
bot.memory["watcher"] = {}
|
||||||
|
|
||||||
con = bot.db.connect()
|
con = bot.db.connect()
|
||||||
|
@ -30,6 +31,8 @@ def setup(bot):
|
||||||
con.close()
|
con.close()
|
||||||
else:
|
else:
|
||||||
for thread in watching:
|
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],
|
t = WatcherThread(bot, thread[0], thread[1], thread[2], thread[3],
|
||||||
thread[4])
|
thread[4])
|
||||||
t.start()
|
t.start()
|
||||||
|
@ -167,7 +170,7 @@ class WatcherThread(threading.Thread):
|
||||||
if res.status_code == 404:
|
if res.status_code == 404:
|
||||||
msg = "[\x0304Watcher\x03] Thread deleted: " \
|
msg = "[\x0304Watcher\x03] Thread deleted: " \
|
||||||
+ f"\x0307{get_thread_url(self.api_url)}"
|
+ f"\x0307{get_thread_url(self.api_url)}"
|
||||||
self.bot.say(msg, channel)
|
self.bot.say(msg, self.channel)
|
||||||
self.stop.set()
|
self.stop.set()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -178,7 +181,7 @@ class WatcherThread(threading.Thread):
|
||||||
if thread["posts"][0].get("closed"):
|
if thread["posts"][0].get("closed"):
|
||||||
msg = "[\x0304Watcher\x03] Thread closed: " \
|
msg = "[\x0304Watcher\x03] Thread closed: " \
|
||||||
+ f"\x0307{get_thread_url(self.api_url)}"
|
+ f"\x0307{get_thread_url(self.api_url)}"
|
||||||
self.bot.say(msg, channel)
|
self.bot.say(msg, self.channel)
|
||||||
self.stop.set()
|
self.stop.set()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -187,5 +190,5 @@ class WatcherThread(threading.Thread):
|
||||||
self.last_post = new_last_post
|
self.last_post = new_last_post
|
||||||
msg = "[\x0304Watcher\x03] New post from \x0308" \
|
msg = "[\x0304Watcher\x03] New post from \x0308" \
|
||||||
+ f"{self.name}\x03 in \x0307{get_thread_url(self.api_url)}"
|
+ f"{self.name}\x03 in \x0307{get_thread_url(self.api_url)}"
|
||||||
self.bot.say(msg, channel)
|
self.bot.say(msg, self.channel)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user