diff --git a/config.py b/config.py new file mode 100644 index 0000000..45d45c1 --- /dev/null +++ b/config.py @@ -0,0 +1,4 @@ +import json + +with open("config.json", "r") as file: + config = json.load(file) \ No newline at end of file diff --git a/main.py b/main.py index 3378702..2b7013f 100644 --- a/main.py +++ b/main.py @@ -1,44 +1,12 @@ -import requests -import json -import random import discord - -with open("config.json", "r") as file: - config = json.load(file) +from config import config 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!") +@bot.event +async def on_ready(): + await bot.change_presence(activity=discord.Game(name = "Casino")) + print(f"{bot.user} ist online") try: bot.run(config['token']) diff --git a/src/commands.py b/src/commands.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils.py b/src/utils.py new file mode 100644 index 0000000..016b79d --- /dev/null +++ b/src/utils.py @@ -0,0 +1,26 @@ +import requests +import random +from config import config + +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 [dep['train'], dep['destination'], station]