Skip to content

Commit

Permalink
fix background tasks thinking they need to do everything
Browse files Browse the repository at this point in the history
  • Loading branch information
AEnterprise committed Jun 4, 2020
1 parent d46e42a commit 7a0d012
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions GearBot/Bot/GearBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ class GearBot(AutoShardedBot):
dash_guild_users = set()
dash_guild_watchers = dict()
cluster = 0
shard_count = 1
shard_ids = []

def __init__(self, *args, loop=None, **kwargs):
super().__init__(*args, loop=loop, **kwargs)
self.metrics = PromMonitors(self)
self.cluster = kwargs.get("cluster", 0)
self.total_shards = kwargs.get("shard_count", 1)
self.shard_ids = kwargs.get("shard_ids", [0])

def dispatch(self, event_name, *args, **kwargs):
if "socket" not in event_name not in ["message_edit"]:
Expand Down
2 changes: 1 addition & 1 deletion GearBot/Cogs/Moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ async def timed_actions(self):
for name, action in types.items():

for infraction in await Infraction.filter(type = name, active = True, end__lt=limit):
if infraction.id not in self.handling:
if infraction.id not in self.handling and ((infraction.guild_id >> 22) % self.bot.total_shards) in self.bot.shard_ids:
self.handling.add(infraction.id)
self.bot.loop.create_task(
self.run_after(infraction.end - now, action(infraction)))
Expand Down
7 changes: 5 additions & 2 deletions GearBot/Cogs/Reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async def remind_me(self, ctx, duration: Duration, *, reminder: ReminderText):
duration_identifier=duration.unit)

async def delivery_service(self):
# only let cluster 0 do this one
if self.bot.cluster is not 0:
return
GearbotLogging.info("📬 Starting reminder delivery background task 📬")
while self.running:
now = time.time()
Expand All @@ -102,8 +105,8 @@ async def run_after(self, delay, action):
await action

async def deliver(self, r):
channel = self.bot.get_channel(r.channel_id)
dm = self.bot.get_user(r.user_id)
channel = await self.bot.fetch_channel(r.channel_id)
dm = await self.bot.fetch_user(r.user_id)
first = dm if r.dm else channel
alternative = channel if r.dm else dm

Expand Down

0 comments on commit 7a0d012

Please sign in to comment.