don't double-post images sent using pluralkit
This commit is contained in:
parent
128af6b3c0
commit
d8ba5b7b54
|
@ -20,21 +20,38 @@ async def on_message(message):
|
||||||
and message.attachments
|
and message.attachments
|
||||||
and not any(a.is_spoiler() for a in message.attachments)):
|
and not any(a.is_spoiler() for a in message.attachments)):
|
||||||
|
|
||||||
attachments = []
|
pluralkit = False
|
||||||
try:
|
if message.webhook_id is not None:
|
||||||
for a in message.attachments:
|
try:
|
||||||
f = await a.to_file()
|
webhook = await client.fetch_webhook(message.webhook_id)
|
||||||
f.filename = 'SPOILER_' + f.filename
|
except discord.Forbidden as e:
|
||||||
attachments.append(f)
|
print('error fetching message webhook: {0}'.format(e), file=sys.stderr)
|
||||||
except discord.DiscordException as e:
|
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.")
|
||||||
print('error reading attachments: {0}'.format(e), file=sys.stderr)
|
return
|
||||||
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
|
||||||
|
|
||||||
try:
|
# If this is a message that's being reposted by PluralKit,
|
||||||
await message.channel.send("{0} says: {1}".format(message.author.mention, message.content), files=attachments)
|
# assume we already caught and reposted the original, and
|
||||||
except discord.DiscordException as e:
|
# just delete this one without reposting a spoilered version
|
||||||
print('error sending message: {0}'.format(e), file=sys.stderr)
|
if not pluralkit:
|
||||||
return
|
attachments = []
|
||||||
|
try:
|
||||||
|
for a in message.attachments:
|
||||||
|
f = await a.to_file()
|
||||||
|
f.filename = 'SPOILER_' + f.filename
|
||||||
|
attachments.append(f)
|
||||||
|
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:
|
||||||
|
print('error sending message: {0}'.format(e), file=sys.stderr)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|
Loading…
Reference in a new issue