fix: shorten channel name if it's too long for discords limit

This commit is contained in:
Kaaninchen
2026-08-20 13:22:14 +02:00
parent 999fe141b9
commit 054ab7fc42
8 changed files with 25 additions and 16 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ numpy==2.5.1
pandas==3.0.3
propcache==0.5.2
py-cord==2.8.0
py-staticmaps==0.5.0
py-staticmaps[cairo]==0.5.0
pyyaml==6.0.3
pycparser==3.0
pynacl==1.6.2
+13 -7
View File
@@ -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,
+1
View File
@@ -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"
+1
View File
@@ -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"
+4
View File
@@ -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
View File
@@ -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
View File
@@ -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
+2 -1
View File
@@ -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