mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: split /info embed if more than 1024 characters
This commit is contained in:
@@ -92,7 +92,6 @@ def get_random_connection(stop_id: str) -> str | None:
|
|||||||
if not trip_ids:
|
if not trip_ids:
|
||||||
logger("Couldn't find any connection", "error")
|
logger("Couldn't find any connection", "error")
|
||||||
return None
|
return None
|
||||||
print(trip_ids)
|
|
||||||
trip_id = random.choice(trip_ids)
|
trip_id = random.choice(trip_ids)
|
||||||
|
|
||||||
from_station = None
|
from_station = None
|
||||||
|
|||||||
+15
-9
@@ -1,12 +1,12 @@
|
|||||||
import discord
|
import discord
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from src.utils import convert_iso_string, get_operator_metadata
|
from src.utils import get_operator_metadata
|
||||||
from src.dc.helpers import format_timestamp_to_dc
|
from src.dc.helpers import format_timestamp_to_dc
|
||||||
|
|
||||||
def build_embed_footer(mode: str, slogans):
|
def build_embed_footer(mode: str, slogans):
|
||||||
footer_notice = f"Data provided by https://transitous.org • mode: {mode}"
|
footer_notice = f"Data provided by https://transitous.org • mode: {mode}"
|
||||||
icon = "https://avatars.githubusercontent.com/u/24960008?s=60&v=4"
|
icon = "https://raw.githubusercontent.com/kaaninchen/Gleiswechsel/refs/heads/main/src/data/assets/transitous-logo.png"
|
||||||
|
|
||||||
if slogans is not None:
|
if slogans is not None:
|
||||||
footer_text = f"{random.choice(slogans)} • {footer_notice}"
|
footer_text = f"{random.choice(slogans)} • {footer_notice}"
|
||||||
@@ -40,14 +40,20 @@ def build_info_embed() -> discord.Embed:
|
|||||||
via = ", ".join(random_stops[:-1]) + " und " + random_stops[-1]
|
via = ", ".join(random_stops[:-1]) + " und " + random_stops[-1]
|
||||||
embed.add_field(name="Über", value=via, inline=False)
|
embed.add_field(name="Über", value=via, inline=False)
|
||||||
|
|
||||||
|
field_lines, field_length, part = [], 0, 1
|
||||||
|
|
||||||
route_lines = []
|
for name, stop_arrival in stops.items():
|
||||||
for stop_name, stop_arrival in stops.items():
|
line = f"**• {name} ({stop_arrival} Uhr)**" if name == trip["station"] else f"• {name} ({stop_arrival} Uhr)"
|
||||||
if stop_name == trip["station"]:
|
|
||||||
route_lines.append(f"**• {stop_name} ({stop_arrival} Uhr)**")
|
if field_length + len(line) + 1 > 1024:
|
||||||
else:
|
embed.add_field(name="Route" if part == 1 else "Route (Fortsetzung)", value="\n".join(field_lines), inline=True)
|
||||||
route_lines.append(f"• {stop_name} ({stop_arrival} Uhr)")
|
field_lines, field_length, part = [], 0, part + 1
|
||||||
embed.add_field(name="Route", value="\n".join(route_lines))
|
|
||||||
|
field_lines.append(line)
|
||||||
|
field_length += len(line) + 1
|
||||||
|
|
||||||
|
if field_lines:
|
||||||
|
embed.add_field(name="Route" if part == 1 else "Route (Fortsetzung)", value="\n".join(field_lines), inline=True)
|
||||||
|
|
||||||
footer = build_embed_footer(trip["mode"], metadata["slogans"])
|
footer = build_embed_footer(trip["mode"], metadata["slogans"])
|
||||||
embed.set_footer(text=footer["text"], icon_url=footer["icon"])
|
embed.set_footer(text=footer["text"], icon_url=footer["icon"])
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@ def get_operator_metadata(agency: str, route_color: str) -> dict:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
color = operators.OPERATORS["fallback"]["color"]
|
color = operators.OPERATORS["fallback"]["color"]
|
||||||
else:
|
else:
|
||||||
logger(f"Managed to get color from API, edit src/data/operators.py if you don't like it")
|
logger(f"Managed to get color from API, add agency to src/data/operators.py if you don't like it")
|
||||||
else:
|
else:
|
||||||
color = operators.OPERATORS["fallback"]["color"]
|
color = operators.OPERATORS["fallback"]["color"]
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user