From 812808a3bf208e592b746171af005971562a1c13 Mon Sep 17 00:00:00 2001 From: BluemediaGER Date: Sat, 28 Oct 2023 01:44:20 +0200 Subject: [PATCH 1/4] Auto generate invite url --- bot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index e1a4806..67bb660 100644 --- a/bot.py +++ b/bot.py @@ -7,9 +7,10 @@ from sqlalchemy.orm import Session from models import Guild, Channel, Base import discord -from discord import app_commands, Game +from discord import app_commands, Game, Permissions from discord.app_commands import Choice from discord.ext import tasks +from discord.utils import oauth_url logger = logging.getLogger() logger.setLevel(logging.INFO) @@ -45,6 +46,8 @@ class BotClient(discord.Client): async def setup_hook(self): await self.tree.sync() self.background_task.start() + invite_url = oauth_url(client_id=self.application_id, permissions=Permissions(permissions=76800)) + logger.info(f"Bot started. Invite it using the following link: {invite_url}") @tasks.loop(minutes=15) async def background_task(self): From 075b7b3333aba9bd5705a46e5032ef2e533d1dfc Mon Sep 17 00:00:00 2001 From: BluemediaGER Date: Sat, 28 Oct 2023 01:45:04 +0200 Subject: [PATCH 2/4] Add Docker compose file and documentation --- README.md | 28 ++++++++++++++++++++++++++++ docker-compose.yaml | 13 +++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 docker-compose.yaml diff --git a/README.md b/README.md index a9c5ad5..8d59759 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ # discord-cleanup-bot A simple discord bot to clean up messages in a channel after a configured ammount of time. + +## Limitations / special features +- Only messages not older than 14 days can be deleted +- Threads are not processed by the bot +- Pinned messages are excluded from deletion + +## Setup using Docker +Using Docker is the easiest way to use this bot: +1. Copy the `docker-compose.yaml` to your server +2. Create a bot account [using this guide](https://discordpy.readthedocs.io/en/stable/discord.html#creating-a-bot-account) (ignore the "Inviting Your Bot" section - the bot will show you the correct invite link later) +3. Paste your bot token behind `BOT_TOKEN=` in the `docker-compose.yaml` +4. Start the container using `docker compose up -d` +5. Run `docker compose logs` and copy the invite link to your browser + +## Manual setup +If you don't want to use Docker, you can set up the bot manually: +1. Clone the Git repo +2. Create and activate a new venv +3. Install the requirements using `requirements.txt` +4. Create a bot account [using this guide](https://discordpy.readthedocs.io/en/stable/discord.html#creating-a-bot-account) (ignore the "Inviting Your Bot" section - the bot will show you the correct invite link later) +5. Set your bot token in the environment variable `BOT_TOKEN` +6. Start the `bot.py` script +7. Copy the invite link to your browser + +## Commands +All commands provide help messages and support auto-completion. +- `/purge (days)` Delete all messages of the last x days now an only once. +- `/retention [get|set|disable] (retention_period)` Manage continous cleanup. The background job runs every 15 minutes. \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..9eb5452 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,13 @@ +version: '3.4' + +services: + discord-cleanup-bot: + image: git.bluemedia.dev/bluemedia/discord-cleanup-bot + volumes: + - bot-data:/data + environment: + - BOT_TOKEN= + restart: unless-stopped + +volumes: + bot-data: \ No newline at end of file From c418132a95cdc9ec9a305c24deb42eadc0bf00d9 Mon Sep 17 00:00:00 2001 From: BluemediaGER Date: Sat, 28 Oct 2023 01:50:36 +0200 Subject: [PATCH 3/4] Add documentation for DB_PATH variable --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d59759..8a7dea0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you don't want to use Docker, you can set up the bot manually: 2. Create and activate a new venv 3. Install the requirements using `requirements.txt` 4. Create a bot account [using this guide](https://discordpy.readthedocs.io/en/stable/discord.html#creating-a-bot-account) (ignore the "Inviting Your Bot" section - the bot will show you the correct invite link later) -5. Set your bot token in the environment variable `BOT_TOKEN` +5. Set your bot token in the environment variable `BOT_TOKEN` and specify a file path for the SQLite database using `DB_PATH` 6. Start the `bot.py` script 7. Copy the invite link to your browser From b93befd90e1e9f3adda0bac8178816e0b9b078e8 Mon Sep 17 00:00:00 2001 From: BluemediaGER Date: Sat, 28 Oct 2023 02:04:55 +0200 Subject: [PATCH 4/4] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a7dea0..861595d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # discord-cleanup-bot -A simple discord bot to clean up messages in a channel after a configured ammount of time. +A simple discord bot to clean up messages in a channel after a configured amount of time. ## Limitations / special features - Only messages not older than 14 days can be deleted