don't double-post images sent using pluralkit

This commit is contained in:
xenofem 2021-05-09 15:48:56 -04:00
parent 128af6b3c0
commit d8ba5b7b54

View file

@ -20,6 +20,24 @@ async def on_message(message):
and message.attachments
and not any(a.is_spoiler() for a in message.attachments)):
pluralkit = False
if message.webhook_id is not None:
try:
webhook = await client.fetch_webhook(message.webhook_id)
except discord.Forbidden as e:
print('error fetching message webhook: {0}'.format(e), file=sys.stderr)
await message.channel.send("I can't inspect the webhook on this message because I don't have the permissions I need. This is important so I can interact properly with messages sent by PluralKit. Admins, please make sure I have the Manage Webhooks permission in all channels where people want to use me.")
return
except discord.DiscordException as e:
print('error fetching message webhook: {0}'.format(e), file=sys.stderr)
return
if webhook.user is not None and webhook.user.name == "PluralKit":
pluralkit = True
# If this is a message that's being reposted by PluralKit,
# assume we already caught and reposted the original, and
# just delete this one without reposting a spoilered version
if not pluralkit:
attachments = []
try:
for a in message.attachments:
@ -29,7 +47,6 @@ async def on_message(message):
except discord.DiscordException as e:
print('error reading attachments: {0}'.format(e), file=sys.stderr)
return
try:
await message.channel.send("{0} says: {1}".format(message.author.mention, message.content), files=attachments)
except discord.DiscordException as e: