mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: validate connections
This commit is contained in:
+17
-5
@@ -11,24 +11,36 @@ async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = Fals
|
||||
if not from_scheduler and _scheduled_task and not _scheduled_task.done():
|
||||
_scheduled_task.cancel()
|
||||
|
||||
attempt = 0
|
||||
max_attempt = 10
|
||||
trip = choose_connection()
|
||||
while trip is None and attempt < max_attempt:
|
||||
attempt += 1
|
||||
logger(f"Attempt {attempt}: Failed to select route, retrying...", "error")
|
||||
trip = choose_connection()
|
||||
|
||||
if trip is None:
|
||||
logger(f"Failed to select route after {max_attempt} attempts", "fatal")
|
||||
return False
|
||||
|
||||
arrival = trip["arrival"]
|
||||
long_name = trip["long_name"]
|
||||
mode = trip["mode"]
|
||||
|
||||
print("-----------------")
|
||||
logger(f"Umstieg: {long_name}, Ankunft: {arrival} Uhr")
|
||||
logger(f"Betreiber: {trip["agency"]}, Typ: {trip["mode"]}")
|
||||
logger(f"Betreiber: {trip["agency"]}, Typ: {mode}")
|
||||
logger(f"Versuche Namen zu ändern, wenn nichts passiert bin ich im cooldown... (warte bis zu 10min!)")
|
||||
|
||||
formatting = channel_formatting(trip["mode"])
|
||||
formatting = channel_formatting(mode)
|
||||
await voice_channel.edit(name=f"{formatting}{long_name}")
|
||||
await voice_channel.set_status(f"Ankunft um {arrival}")
|
||||
|
||||
logger(f"Name geändert!")
|
||||
|
||||
_scheduled_task = asyncio.create_task(_schedule_next_transfer(bot, arrival))
|
||||
_scheduled_task = asyncio.create_task(_schedule_next_transfer(bot, arrival, voice_channel))
|
||||
|
||||
async def _schedule_next_transfer(bot, arrival):
|
||||
async def _schedule_next_transfer(bot, arrival, voice_channel):
|
||||
now = datetime.now()
|
||||
parsed_time = datetime.strptime(arrival, "%H:%M").time()
|
||||
arrival_dt = datetime.combine(date.today(), parsed_time)
|
||||
@@ -44,5 +56,5 @@ async def _schedule_next_transfer(bot, arrival):
|
||||
await asyncio.sleep(wait_seconds)
|
||||
|
||||
logger("Zug angekommen, wähle neue Verbindung")
|
||||
await rename_vc(bot, from_scheduler=True)
|
||||
await rename_vc(bot, voice_channel, from_scheduler=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user