diff --git a/.gitignore b/.gitignore index 13d1490..0d4fea2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +token + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/LICENSE b/LICENSE index 204b93d..3c42862 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License Copyright (c) +MIT License Copyright (c) 2020 xenofem Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4b1baf3..b12720a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # data-expunged -Discord bot to help mobile users spoiler uploaded images \ No newline at end of file +Discord bot to help mobile users spoiler uploaded images + +## Setup + + git clone https://git.xeno.science/xenofem/data-expunged + cd data-expunged + python3 -m venv env + source env/bin/activate + pip install discord.py + echo > token + python data_expunged.py diff --git a/data_expunged.py b/data_expunged.py new file mode 100644 index 0000000..dabc0d4 --- /dev/null +++ b/data_expunged.py @@ -0,0 +1,45 @@ +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)