Use typing indicator while updating
This commit is contained in:
parent
cd7c979d10
commit
0a147407c1
42
ahtcg_bot.py
42
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
|
||||
|
Loading…
Reference in New Issue
Block a user