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()
|
await message.delete()
|
||||||
|
|
||||||
async def update_channel_latest_decks(self, channel: discord.TextChannel) -> None:
|
async def update_channel_latest_decks(self, channel: discord.TextChannel) -> None:
|
||||||
deck_ids = await self.gather_deck_ids(channel)
|
print(f'Running update in channel {channel.guild} - {channel.name}')
|
||||||
latest_decks = await self.arkhamdb_client.get_latest_decks(deck_ids)
|
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:
|
try:
|
||||||
last_message = await channel.fetch_message(channel.last_message_id)
|
last_message = await channel.fetch_message(channel.last_message_id)
|
||||||
except discord.NotFound:
|
except discord.NotFound:
|
||||||
last_message = None
|
last_message = None
|
||||||
|
|
||||||
message_text = '\n'.join(
|
message_text = '\n'.join(
|
||||||
f"{prefix}[{deck['name']}]({self.arkhamdb_client.origin}/deck/view/{deck['id']}) [{deck['id']}]"
|
f"{prefix}[{deck['name']}]({self.arkhamdb_client.origin}/deck/view/{deck['id']}) [{deck['id']}]"
|
||||||
for prefix, deck in latest_decks.values())
|
for prefix, deck in latest_decks.values())
|
||||||
message_embed = discord.Embed(
|
message_embed = discord.Embed(
|
||||||
title=f'Updated as of {datetime.now()}',
|
title=f'Updated as of {datetime.now()}',
|
||||||
description=message_text)
|
description=message_text)
|
||||||
|
|
||||||
if last_message is not None \
|
if last_message is not None \
|
||||||
and last_message.author.id == self.user.id \
|
and last_message.author.id == self.user.id \
|
||||||
and len(last_message.embeds) == 1:
|
and len(last_message.embeds) == 1:
|
||||||
if message_text != last_message.embeds[0].description:
|
if message_text != last_message.embeds[0].description:
|
||||||
await last_message.edit(embed=message_embed)
|
await last_message.edit(embed=message_embed)
|
||||||
else:
|
else:
|
||||||
await channel.send(embed=message_embed)
|
await channel.send(embed=message_embed)
|
||||||
|
|
||||||
async def maybe_update_channel_for_message(self, message: discord.Message) -> None:
|
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
|
# don't to react to the bot's changes, and only update registered channels
|
||||||
|
Loading…
Reference in New Issue
Block a user