From c1eb9fd3615d335c5f8aed97351a14d18f0f521e Mon Sep 17 00:00:00 2001 From: Kaaninchen <124433727+kaaninchen@users.noreply.github.com> Date: Tue, 14 Jul 2026 23:54:22 +0200 Subject: [PATCH] groundworks consider this more like a simple proof of concept for myself. I coded this while being tired af and not giving a damn about the code quality. Cleanup is gonna be soon --- .gitignore | 3 +++ README.md | 3 +++ config.json.example | 6 ++++++ main.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 config.json.example create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9d0081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv/ +GTFS/ +config.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2c77bc --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Trainstalk + +## Setup diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..68e419c --- /dev/null +++ b/config.json.example @@ -0,0 +1,6 @@ +{ + "token": "", + "stations": [ "Flensburg", "Recklinghausen Hbf", "Augsburg Hbf", "Amsterdam Centraal"], + "vc": "", + "formatting": "🚅┇" +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..3378702 --- /dev/null +++ b/main.py @@ -0,0 +1,46 @@ +import requests +import json +import random +import discord + +with open("config.json", "r") as file: + config = json.load(file) + +bot = discord.Bot(intents=discord.Intents.all()) + +def random_connection(): + while True: + station = random.choice(config["stations"]) + url = f"https://dbf.finalrewind.org/{station}.json" + + try: + response = requests.get(url) + response.raise_for_status() + data = response.json() + except requests.RequestException: + continue + + departures = [ + d for d in data.get("departures", []) + if d.get("scheduledDeparture") and d.get("destination") != station + ] + + if not departures: + continue + + dep = random.choice(departures) + return [f"{config["formatting"]}{dep['train']} nach {dep['destination']}", f"von {station}"] + +@bot.slash_command(description="Rename vc") +async def rename_vc(ctx): + channel = bot.get_channel(int(config["vc"])) + if isinstance(channel, discord.VoiceChannel): + name, status = random_connection() + await channel.edit(name = name) + await channel.set_status(status) + await ctx.respond("Kanal aktualisiert!") + +try: + bot.run(config['token']) +except: + print("An error occured while parsing the token (check the config!)") \ No newline at end of file