Fix special case where webhook is deleted by user

This commit is contained in:
Ske 2018-10-27 23:34:50 +02:00
parent a4449ceaae
commit 899183f26d

View File

@ -103,6 +103,8 @@ async def do_proxy_message(conn, original_message: discord.Message, proxy_member
inner_text: str, logger: ChannelLogger): inner_text: str, logger: ChannelLogger):
# Send the message through the webhook # Send the message through the webhook
webhook = await get_or_create_webhook_for_channel(conn, original_message.channel) webhook = await get_or_create_webhook_for_channel(conn, original_message.channel)
try:
sent_message = await webhook.send( sent_message = await webhook.send(
content=inner_text, content=inner_text,
username=proxy_member.name, username=proxy_member.name,
@ -110,6 +112,12 @@ async def do_proxy_message(conn, original_message: discord.Message, proxy_member
file=await make_attachment_file(original_message), file=await make_attachment_file(original_message),
wait=True wait=True
) )
except discord.NotFound:
# The webhook we got from the DB doesn't actually exist
# If we delete it from the DB then call the function again, it'll re-create one for us
await db.delete_webhook(conn, original_message.channel.id)
await do_proxy_message(conn, original_message, proxy_member, inner_text, logger)
return
# Save the proxied message in the database # Save the proxied message in the database
await db.add_message(conn, sent_message.id, original_message.channel.id, proxy_member.id, await db.add_message(conn, sent_message.id, original_message.channel.id, proxy_member.id,