Skip to content

Commit

Permalink
feat: roleplay notifs
Browse files Browse the repository at this point in the history
  • Loading branch information
ishtanzar committed Mar 7, 2024
1 parent 2cc7264 commit 8b3628a
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions wm-discord-bot/src/westmarches/commands/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,38 @@ async def gm_setforward(self, ctx, channel: discord.TextChannel = None):
async def on_question_thread_message(self, message):
if isinstance(message.channel, discord.Thread) and \
message.channel.parent_id == await self.config.forward.questions_channel() and message.content == '✅':
log.info(f"Question is considered answered, closing the thread")
await message.channel.send('Ce sujet est désormais clos, merci.')
log.debug('Fetching original message')
original_message = await self._get_thread_original_message(message.channel)
log.debug('Fetching full original message')
full_message = await message.channel.parent.fetch_message(original_message.id)
log.debug('Adding reaction')
await full_message.add_reaction('✅')
log.debug('Archiving thread')
await message.channel.edit(archived=True)
log.info(f"Question is considered answered, closing the thread")
await message.channel.send('Ce sujet est désormais clos, merci.')
log.debug('Fetching original message')
original_message = await self._get_thread_original_message(message.channel)
log.debug('Fetching full original message')
full_message = await message.channel.parent.fetch_message(original_message.id)
log.debug('Adding reaction')
await full_message.add_reaction('✅')
log.debug('Archiving thread')
await message.channel.edit(archived=True)

@commands.Cog.listener('on_message_without_command')
async def forward_on_message_without_command(self, message):
async def forward_on_message_without_command(self, message: discord.Message):
ctx: commands.Context = await self.bot.get_context(message)
gm_guild = self.bot.get_guild(await self.config.management.gm_guild())

if isinstance(message.channel, discord.Thread):
if isinstance(thread := message.channel, discord.Thread):
channel = thread.parent
category = channel.category

notif_channel = None
if message.channel.parent_id == await self.config.forward.downtime_channel():
if channel.id == await self.config.forward.downtime_channel():
notif_channel = gm_guild.get_channel_or_thread(await self.config.forward.downtime_notif_channel())

if message.channel.parent_id == await self.config.forward.character_sheet_channel():
if channel.id == await self.config.forward.character_sheet_channel():
notif_channel = gm_guild.get_channel_or_thread(await self.config.forward.character_sheet_notif_channel())

if category.id == await self.config.forward.roleplay_category():
notif_channel = gm_guild.get_channel_or_thread(await self.config.forward.roleplay_notif_channel())

if notif_channel:
embeds = [discord.Embed(title=message.channel.name, description=message.content, url=message.channel.jump_url)]
embeds = [discord.Embed(title=thread.name, description=message.content, url=thread.jump_url)]
embeds[0].set_author(name=f"{message.author} | {message.author.id}", icon_url=message.author.avatar.url)
embeds = self._append_attachements(message, embeds)
embeds[-1].timestamp = message.created_at
Expand Down

0 comments on commit 8b3628a

Please sign in to comment.