From 0a147407c18a4b4f74e681a6281b1caa56dd5d0c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 9 May 2021 09:58:31 -0400 Subject: [PATCH] Use typing indicator while updating --- ahtcg_bot.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/ahtcg_bot.py b/ahtcg_bot.py index 566a851..2a75566 100755 --- a/ahtcg_bot.py +++ b/ahtcg_bot.py @@ -78,30 +78,32 @@ class ArkhamDBUpdater(commands.Bot): await message.delete() async def update_channel_latest_decks(self, channel: discord.TextChannel) -> None: - deck_ids = await self.gather_deck_ids(channel) - latest_decks = await self.arkhamdb_client.get_latest_decks(deck_ids) + print(f'Running update in channel {channel.guild} - {channel.name}') + async with channel.typing(): + deck_ids = await self.gather_deck_ids(channel) + latest_decks = await self.arkhamdb_client.get_latest_decks(deck_ids) - await self.clear_old_messages(channel) + await self.clear_old_messages(channel) - try: - last_message = await channel.fetch_message(channel.last_message_id) - except discord.NotFound: - last_message = None + try: + last_message = await channel.fetch_message(channel.last_message_id) + except discord.NotFound: + last_message = None - message_text = '\n'.join( - f"{prefix}[{deck['name']}]({self.arkhamdb_client.origin}/deck/view/{deck['id']}) [{deck['id']}]" - for prefix, deck in latest_decks.values()) - message_embed = discord.Embed( - title=f'Updated as of {datetime.now()}', - description=message_text) + message_text = '\n'.join( + f"{prefix}[{deck['name']}]({self.arkhamdb_client.origin}/deck/view/{deck['id']}) [{deck['id']}]" + for prefix, deck in latest_decks.values()) + message_embed = discord.Embed( + title=f'Updated as of {datetime.now()}', + description=message_text) - if last_message is not None \ - and last_message.author.id == self.user.id \ - and len(last_message.embeds) == 1: - if message_text != last_message.embeds[0].description: - await last_message.edit(embed=message_embed) - else: - await channel.send(embed=message_embed) + if last_message is not None \ + and last_message.author.id == self.user.id \ + and len(last_message.embeds) == 1: + if message_text != last_message.embeds[0].description: + await last_message.edit(embed=message_embed) + else: + await channel.send(embed=message_embed) async def maybe_update_channel_for_message(self, message: discord.Message) -> None: # don't to react to the bot's changes, and only update registered channels