mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-07-21 19:52:47 +00:00
Code cleanup
This commit is contained in:
@@ -2,7 +2,7 @@ import discord
|
|||||||
import random
|
import random
|
||||||
from discord.ext import tasks
|
from discord.ext import tasks
|
||||||
from config import config
|
from config import config
|
||||||
from src.state import rename_vc
|
from handlers import rename_vc
|
||||||
from src.commands import setup_commands
|
from src.commands import setup_commands
|
||||||
from src.embeds import build_error_embed
|
from src.embeds import build_error_embed
|
||||||
from src.data.status import discord_status
|
from src.data.status import discord_status
|
||||||
|
|||||||
@@ -26,5 +26,10 @@ OPERATORS = {
|
|||||||
"logo": db_logo,
|
"logo": db_logo,
|
||||||
"color": 0xEC0016,
|
"color": 0xEC0016,
|
||||||
"slogan": db_slogans
|
"slogan": db_slogans
|
||||||
|
},
|
||||||
|
"NBE": {
|
||||||
|
"name": "Nordbahn",
|
||||||
|
"logo": "https://upload.wikimedia.org/wikipedia/commons/b/b5/Logo_Nordbahn_NAH.SH_Blau_positiv_final.png",
|
||||||
|
"color": 0x1A2848
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-18
@@ -1,7 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
import discord
|
import discord
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import src.state as state
|
import handlers as handlers
|
||||||
from src.utils import operator_infos, format_via_list
|
from src.utils import operator_infos, format_via_list
|
||||||
|
|
||||||
def format_timestamp(timestr):
|
def format_timestamp(timestr):
|
||||||
@@ -15,32 +15,28 @@ def format_timestamp(timestr):
|
|||||||
return discord.utils.format_dt(final_datetime, style="t")
|
return discord.utils.format_dt(final_datetime, style="t")
|
||||||
|
|
||||||
def build_info_embed() -> discord.Embed | None:
|
def build_info_embed() -> discord.Embed | None:
|
||||||
if state.name is None:
|
if handlers.current is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
operator = operator_infos(state.train)
|
conn = handlers.current
|
||||||
|
operator = operator_infos(conn["train"])
|
||||||
|
name = f"{conn['train']} nach {conn['destination']}"
|
||||||
|
embed = discord.Embed(
|
||||||
|
title=name,
|
||||||
|
description=f"Abfahrt von {conn['station']} um {format_timestamp(conn['departure'])}",
|
||||||
|
color=operator["color"]
|
||||||
|
)
|
||||||
|
|
||||||
if len(state.via) == 0:
|
if len(conn['via']) > 0:
|
||||||
embed = discord.Embed(
|
embed.add_field(name="Über", value=format_via_list(conn['via']), inline=False)
|
||||||
title=state.name,
|
|
||||||
description=f"Abfahrt von {state.station} um {format_timestamp(state.departure)}",
|
|
||||||
color=operator["color"]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
embed = discord.Embed(
|
|
||||||
title=state.name,
|
|
||||||
description=f"Abfahrt **{format_timestamp(state.departure)}** von **{state.station}**",
|
|
||||||
color=operator["color"]
|
|
||||||
)
|
|
||||||
embed.add_field(name="Über", value=format_via_list(state.via), inline=False)
|
|
||||||
|
|
||||||
embed.set_author(name=operator["name"])
|
embed.set_author(name=operator["name"])
|
||||||
embed.set_thumbnail(url=operator["logo"])
|
embed.set_thumbnail(url=operator["logo"])
|
||||||
|
|
||||||
route_lines = []
|
route_lines = []
|
||||||
for stop in state.route:
|
for stop in conn['route']:
|
||||||
stop_name = stop["name"]
|
stop_name = stop["name"]
|
||||||
if stop_name == state.station:
|
if stop_name == conn['station']:
|
||||||
route_lines.append(f"• **{stop_name}**")
|
route_lines.append(f"• **{stop_name}**")
|
||||||
else:
|
else:
|
||||||
route_lines.append(f"• {stop_name}")
|
route_lines.append(f"• {stop_name}")
|
||||||
|
|||||||
@@ -2,15 +2,10 @@ import discord
|
|||||||
from config import config
|
from config import config
|
||||||
from src.utils import random_connection
|
from src.utils import random_connection
|
||||||
|
|
||||||
name = None
|
current = None
|
||||||
train = None
|
|
||||||
route = None
|
|
||||||
departure = None
|
|
||||||
via = None
|
|
||||||
station = None
|
|
||||||
|
|
||||||
async def rename_vc(bot: discord.Bot) -> bool:
|
async def rename_vc(bot: discord.Bot) -> bool:
|
||||||
global name, train, route, departure, via, station
|
global current, name
|
||||||
|
|
||||||
guild = bot.get_guild(int(config["server"]))
|
guild = bot.get_guild(int(config["server"]))
|
||||||
if guild is None:
|
if guild is None:
|
||||||
@@ -22,10 +17,10 @@ async def rename_vc(bot: discord.Bot) -> bool:
|
|||||||
print(f"Unable to find voice-Channel {config['vc']} on the server")
|
print(f"Unable to find voice-Channel {config['vc']} on the server")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
train, destination, route, departure, via, station = random_connection()
|
current = random_connection()
|
||||||
name = f"{train} nach {destination}"
|
name = f"{current['train']} nach {current['destination']}"
|
||||||
|
|
||||||
print(f"Info: {name} from {station}\n via: {via}")
|
print(f"Info: {name} from {current['station']} \n via: {current['via']}")
|
||||||
|
|
||||||
await channel.edit(name=f"{config['formatting']}{name}")
|
await channel.edit(name=f"{config['formatting']}{name}")
|
||||||
return True
|
return True
|
||||||
+9
-2
@@ -24,12 +24,19 @@ def random_connection():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
dep = random.choice(departures)
|
dep = random.choice(departures)
|
||||||
return [dep['train'], dep['destination'], dep['route'], dep['scheduledDeparture'], dep['via'], station]
|
return {
|
||||||
|
"train": dep['train'],
|
||||||
|
"destination": dep['destination'],
|
||||||
|
"route": dep['route'],
|
||||||
|
"departure": dep['scheduledDeparture'],
|
||||||
|
"via": dep['via'],
|
||||||
|
"station": station
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def operator_infos(train):
|
def operator_infos(train):
|
||||||
if not train:
|
if not train:
|
||||||
return OPERATORS["Fallback"]
|
return OPERATORS["fallback"]
|
||||||
|
|
||||||
train_type = train.split()[0]
|
train_type = train.split()[0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user