mirror of
https://github.com/UiO-Gaming/mustafa.git
synced 2026-11-05 13:56:48 +01:00
only count streaks in the bot's own server
Messages in other servers the bot is in and in DMs no longer count towards streaks, and catching up on missed messages at startup only reads that server. Streaks started elsewhere made /streak se look up a channel in another server, which crashed with InvalidData. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
154d4de881
commit
562c30f45e
1 file changed
+7
-6
+7
-6
@@ -101,7 +101,7 @@ class Streak(commands.Cog):
|
||||
message (discord.Message): The message
|
||||
"""
|
||||
|
||||
if message.author.bot:
|
||||
if message.author.bot or message.guild is None or message.guild.id != self.bot.guild_id:
|
||||
return
|
||||
|
||||
self.record_message(message)
|
||||
@@ -143,9 +143,12 @@ class Streak(commands.Cog):
|
||||
|
||||
await self.bot.wait_until_ready()
|
||||
|
||||
if not (guild := self.bot.get_guild(self.bot.guild_id)):
|
||||
self.bot.logger.warning("Could not find the bot's server, so missed messages won't count towards streaks")
|
||||
return
|
||||
|
||||
since = discord.utils.utcnow().astimezone(self.bot.timezone).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
counted = 0
|
||||
for guild in self.bot.guilds:
|
||||
channels = [c for c in guild.channels if isinstance(c, discord.abc.Messageable)] + list(guild.threads)
|
||||
for channel in channels:
|
||||
if not channel.permissions_for(guild.me).read_message_history:
|
||||
@@ -157,11 +160,9 @@ class Streak(commands.Cog):
|
||||
self.record_message(message)
|
||||
counted += 1
|
||||
except discord.HTTPException as e:
|
||||
self.bot.logger.warning(
|
||||
f"Could not read the history of {channel} while catching up on streaks: {e}"
|
||||
)
|
||||
self.bot.logger.warning(f"Could not read the history of {channel} while catching up on streaks: {e}")
|
||||
|
||||
self.bot.logger.info(f"Counted {counted} messages since {since} towards streaks")
|
||||
self.bot.logger.info(f"Counted {counted} messages in {guild} since {since} towards streaks")
|
||||
|
||||
async def insert_cache(self):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user