mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
fix: shorten channel name if it's too long for discords limit
This commit is contained in:
+13
-7
@@ -11,7 +11,6 @@ from src.lang.locales import lang
|
||||
station_names = config.connections.stations
|
||||
station_IDs = config.connections.IDs
|
||||
blacklist = config.connections.blacklist
|
||||
long_name_lang = lang.channel.long_name
|
||||
user_agent = config.http.user_agent
|
||||
|
||||
headers = {
|
||||
@@ -238,18 +237,25 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
||||
logger(f"Bot doesn't know what to do with round trips, I'll have to implement this some day", "error")
|
||||
return None # TODO actually handel this
|
||||
|
||||
all_stop_names = [train_from] + [stop["name"] for stop in legs["intermediateStops"]] + [goes_to]
|
||||
if len(all_stop_names) != len(set(all_stop_names)):
|
||||
logger("Route reuses station names! Skipping, to be safe...", "error")
|
||||
return None # TODO this too
|
||||
|
||||
arrival_dt = parse_iso(end_time)
|
||||
departure_dt = parse_iso(start_time)
|
||||
|
||||
train_name = get_train_name(display_name, mode) # used by lang
|
||||
if train_from == from_station:
|
||||
train_name = long_name_lang.train_from()
|
||||
if len(lang.channel.long_name.train_from()) >= 100:
|
||||
channel_name = lang.channel.short_name
|
||||
else:
|
||||
long_name = long_name_lang.train_via()
|
||||
|
||||
if train_from == from_station:
|
||||
channel_name = lang.channel.long_name.train_from()
|
||||
else:
|
||||
channel_name = lang.channel.long_name.train_via()
|
||||
|
||||
trip_details = {
|
||||
"long_name": long_name,
|
||||
"short_name": train_name,
|
||||
"channel_name": channel_name,
|
||||
"station": from_station,
|
||||
"from": train_from,
|
||||
"to": goes_to,
|
||||
|
||||
@@ -2,6 +2,7 @@ channel:
|
||||
long_name:
|
||||
train_from: "{train_name} nach {goes_to} von {train_from}"
|
||||
train_via: "{train_name} nach {goes_to} über {from_station}"
|
||||
short_name: "{train_name} nach {goes_to}"
|
||||
embeds:
|
||||
footer:
|
||||
notice: "Daten bereitgestellt von https://transitous.org • Maps (C) CARTO (C) OpenStreetMap.org contributors"
|
||||
|
||||
@@ -2,6 +2,7 @@ channel:
|
||||
long_name:
|
||||
train_from: "{train_name} to {goes_to} from {train_from}"
|
||||
train_via: "{train_name} to {goes_to} via {from_station}"
|
||||
short_name: "{train_name} to {goes_to}"
|
||||
embeds:
|
||||
footer:
|
||||
notice: "Data provided by https://transitous.org • Maps (C) CARTO (C) OpenStreetMap.org contributors"
|
||||
|
||||
@@ -62,6 +62,10 @@ OPERATORS = {
|
||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/BSicon_LOGO_GVB.svg/960px-BSicon_LOGO_GVB.svg.png",
|
||||
"color": 0x2B62AF,
|
||||
},
|
||||
"Jenaer Nahverkehr GmbH": {
|
||||
"logo": "https://www.stadtwerke-jena.de/dam/jcr:74dc9d81-0447-4864-973b-7e395f1d6948/JNV_Bildmarke_322px.png",
|
||||
"color": 0x0075BD
|
||||
},
|
||||
"Nordbahn Eisenbahngesellschaft": {
|
||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/b/b5/Logo_Nordbahn_NAH.SH_Blau_positiv_final.png",
|
||||
"color": 0x1A2848,
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ def build_info_embed() -> discord.Embed:
|
||||
arrival = format_timestamp_to_dc(trip["arrival"])
|
||||
|
||||
embed = discord.Embed(
|
||||
title = trip["long_name"],
|
||||
title = trip["channel_name"],
|
||||
description=lang_embed.info.description(),
|
||||
color = metadata["color"]
|
||||
)
|
||||
|
||||
+2
-6
@@ -30,11 +30,7 @@ async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = Fals
|
||||
generate_static_map(trip["stops"], trip["mode"], trip["agency"], trip["route_color"])
|
||||
|
||||
arrival = trip["arrival"]
|
||||
|
||||
if len(trip["long_name"]) >= 100:
|
||||
channel_name = trip["short_name"]
|
||||
else:
|
||||
channel_name = trip["long_name"]
|
||||
channel_name = trip["channel_name"]
|
||||
|
||||
mode = trip["mode"]
|
||||
|
||||
@@ -156,7 +152,7 @@ async def _update_next_loop(voice_channel: discord.VoiceChannel):
|
||||
|
||||
wait_seconds = (next_stop["arrival"] - datetime.now(LOCAL_TZ)).total_seconds()
|
||||
if wait_seconds > 0:
|
||||
await (wait_seconds)
|
||||
await asyncio.sleep(wait_seconds)
|
||||
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# generated by datamodel-codegen:
|
||||
# filename: en.yaml
|
||||
# timestamp: 2026-08-18T20:08:48+00:00
|
||||
# timestamp: 2026-08-20T10:40:43+00:00
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -16,6 +16,7 @@ class LongName:
|
||||
@dataclass
|
||||
class Channel:
|
||||
long_name: LongName
|
||||
short_name: str
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user