commit 1d025d0f396b8e5679c5022bd996016197d7696a Author: xenofem Date: Fri Sep 11 16:46:44 2020 -0400 working initial version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d4fea2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +token + +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c42862 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +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 +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5019697 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# journal3 + +Archival discord bot + +## Usage + +Tag the bot in any channel, and it'll reply with a downloadable text file containing the channel's message history. This will only include text, not images or other uploaded files. + +## Setup + + git clone https://git.xeno.science/xenofem/journal3 + cd journal3 + python3 -m venv env + source env/bin/activate + pip install discord.py + echo > token + python journal3.py diff --git a/journal3.py b/journal3.py new file mode 100644 index 0000000..0d1701c --- /dev/null +++ b/journal3.py @@ -0,0 +1,31 @@ +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 not isinstance(message.channel, discord.TextChannel): + return + if not (client.user in message.mentions or [client.user] in [role.members for role in message.role_mentions]): + return + + await message.channel.send('generating channel archive...') + + with io.StringIO() as buf: + async for m in message.channel.history(limit=None, oldest_first=True): + buf.write('@{0.author.name}#{0.author.discriminator} {0.created_at}\n{0.clean_content}\n\n'.format(m)) + buf.seek(0) + f = discord.File(buf, '{}_{}.txt'.format(message.channel.guild.name, message.channel.name)) + await message.channel.send('complete:', files=[f]) + +with open('token') as f: + token = f.read().strip() +client.run(token)