aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar SebastiaanZ <[email protected]>2019-05-06 22:26:30 +0200
committerGravatar SebastiaanZ <[email protected]>2019-05-06 22:26:30 +0200
commit596a007138a669478b280ebd4dd7c2b85e842dd6 (patch)
tree06e179dcc185ff2befdfe4909791c1f41fabf2eb
parentFixing the lint error -_- (diff)
Preventing multiple reddit background tasks from starting by checking if one already exists
-rw-r--r--bot/cogs/reddit.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py
index 2e3d32b2d..b5bd26e3d 100644
--- a/bot/cogs/reddit.py
+++ b/bot/cogs/reddit.py
@@ -31,6 +31,9 @@ class Reddit:
self.prev_lengths = {}
self.last_ids = {}
+ self.new_posts_task = None
+ self.top_weekly_posts_task = None
+
async def fetch_posts(self, route: str, *, amount: int = 25, params=None):
"""
A helper method to fetch a certain amount of Reddit posts at a given route.
@@ -280,8 +283,10 @@ class Reddit:
self.reddit_channel = self.bot.get_channel(Channels.reddit)
if self.reddit_channel is not None:
- self.bot.loop.create_task(self.poll_new_posts())
- self.bot.loop.create_task(self.poll_top_weekly_posts())
+ if self.new_posts_task is None:
+ self.new_posts_task = self.bot.loop.create_task(self.poll_new_posts())
+ if self.top_weekly_posts_task is None:
+ self.top_weekly_posts_task = self.bot.loop.create_task(self.poll_top_weekly_posts())
else:
log.warning("Couldn't locate a channel for subreddit relaying.")