46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
|
import discord
|
||
|
import io
|
||
|
import sys
|
||
|
|
||
|
client = discord.Client()
|
||
|
|
||
|
@client.event
|
||
|
async def on_ready():
|
||
|
print('logged in as {0.user}'.format(client), file=sys.stderr)
|
||
|
|
||
|
@client.event
|
||
|
async def on_message(message):
|
||
|
if message.author == client.user:
|
||
|
return
|
||
|
|
||
|
if ('spoil' in message.content.lower()
|
||
|
and message.author.is_on_mobile()
|
||
|
and message.attachments
|
||
|
and not any(a.is_spoiler() for a in message.attachments)):
|
||
|
|
||
|
attachments = []
|
||
|
try:
|
||
|
for a in message.attachments:
|
||
|
f = await a.to_file()
|
||
|
f.filename = 'SPOILER_' + f.filename
|
||
|
attachments.append(f)
|
||
|
except (discord.HTTPException, discord.Forbidden, discord.NotFound) 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.HTTPException, discord.Forbidden, discord.InvalidArgument) as e:
|
||
|
print('error sending message: {0}'.format(e), file=sys.stderr)
|
||
|
return
|
||
|
|
||
|
try:
|
||
|
await message.delete()
|
||
|
except (discord.HTTPException, discord.Forbidden, discord.NotFound) as e:
|
||
|
print('error deleting message: {0}'.format(e))
|
||
|
return
|
||
|
|
||
|
with open('token') as f:
|
||
|
token = f.read().strip()
|
||
|
client.run(token)
|