mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-07-21 19:52:47 +00:00
code restructuring
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
with open("config.json", "r") as file:
|
||||||
|
config = json.load(file)
|
||||||
@@ -1,44 +1,12 @@
|
|||||||
import requests
|
|
||||||
import json
|
|
||||||
import random
|
|
||||||
import discord
|
import discord
|
||||||
|
from config import config
|
||||||
with open("config.json", "r") as file:
|
|
||||||
config = json.load(file)
|
|
||||||
|
|
||||||
bot = discord.Bot(intents=discord.Intents.all())
|
bot = discord.Bot(intents=discord.Intents.all())
|
||||||
|
|
||||||
def random_connection():
|
@bot.event
|
||||||
while True:
|
async def on_ready():
|
||||||
station = random.choice(config["stations"])
|
await bot.change_presence(activity=discord.Game(name = "Casino"))
|
||||||
url = f"https://dbf.finalrewind.org/{station}.json"
|
print(f"{bot.user} ist online")
|
||||||
|
|
||||||
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:
|
try:
|
||||||
bot.run(config['token'])
|
bot.run(config['token'])
|
||||||
|
|||||||
@@ -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]
|
||||||
Reference in New Issue
Block a user