aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-03-07 20:20:43 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-03-07 20:20:43 +0000
commite7d2973f33bfd6088bbad8f53a10c4f8cab72fd9 (patch)
tree15bdc4fc0fbddf124b093a3c4aebf369472de644
parenta18dd07732c9c1867318e660ce19644283aca2ae (diff)
downloadaps-cogs-e7d2973f33bfd6088bbad8f53a10c4f8cab72fd9.tar
aps-cogs-e7d2973f33bfd6088bbad8f53a10c4f8cab72fd9.tar.gz
aps-cogs-e7d2973f33bfd6088bbad8f53a10c4f8cab72fd9.zip
markov: handle threads properly
-rw-r--r--markov/markov.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/markov/markov.py b/markov/markov.py
index b2fb591..3acf2dd 100644
--- a/markov/markov.py
+++ b/markov/markov.py
@@ -45,12 +45,18 @@ class Markov(commands.Cog):
async def on_message_without_command(self, message):
if message.guild is None:
return
+
if not await self.config.guild(message.guild).use_messages():
return
- if not await self.config.channel(message.channel).use_messages():
+
+ if not await self.config.channel(
+ self.get_base_channel(message.channel)
+ ).use_messages():
return
+
if not await self.config.member(message.author).use_messages():
return
+
if message.author.id == self.bot.user.id:
return
@@ -146,6 +152,11 @@ class Markov(commands.Cog):
raise ValueError(f"x must be non-negative (got {x})")
return x.to_bytes(math.ceil(x.bit_length() / 8), byteorder="big", signed=False)
+ def get_base_channel(self, channel_or_thread):
+ if isinstance(channel_or_thread, discord.Thread):
+ return channel_or_thread.parent
+ return channel_or_thread
+
@commands.group()
async def markov(self, _ctx):
"""
@@ -182,7 +193,7 @@ class Markov(commands.Cog):
Enable/disable processing in this channel (must be enabled for the guild
using toggle_guild as well).
"""
- channel_conf = self.config.channel(ctx.channel)
+ channel_conf = self.config.channel(self.get_base_channel(ctx.channel))
new_state = not (await channel_conf.use_messages())
await channel_conf.use_messages.set(new_state)
await ctx.reply(