diff --git a/main.py b/main.py index c1c1f6f..d18445b 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,7 @@ async def on_ready(): global _bot_initialized if not _bot_initialized: - logger(f"{bot.user} ist online") + logger(f"{bot.user} is online") _bot_initialized = True server_id = config.discord.server server_vc_id = config.discord.vc @@ -32,7 +32,7 @@ async def on_ready(): try: bot.run(config.discord.token) except: - logger("Feher peim parsen des tokens", "fatal") + logger("An error occured while parsing the token", "fatal") ''' TODO diff --git a/src/dc/handlers.py b/src/dc/handlers.py index 40c69fd..93eddeb 100644 --- a/src/dc/handlers.py +++ b/src/dc/handlers.py @@ -29,17 +29,17 @@ async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = Fals mode = trip["mode"] print("-----------------") - logger(f"Umstieg: {long_name}; Ankunft: {arrival} Uhr") - logger(f"Betreiber: {trip["agency"]}, Typ: {mode}") - logger(f"Versuche Namen zu ändern, wenn nichts passiert bin ich im cooldown... (warte bis zu 10min!)") + logger(f"Transfer: {long_name}; Arrival: {arrival}") + logger(f"Agency: {trip["agency"]}, mode: {mode}") + logger(f"Trying to change channel name. Discord put the bot into a cooldown if nothing happens... (automatically resolves after up to 10min)") 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!") + logger(f"Updated channel name!") - await announcer("umstieg", voice_channel) + await announcer("transfer", voice_channel) _scheduled_task = asyncio.create_task(_schedule_next_transfer(bot, trip["arrival_dt"], voice_channel, trip["to"])) @@ -51,32 +51,28 @@ async def announcer(announcement: str, voice_channel: discord.VoiceChannel, dest if announcements_enabled: if len(voice_channel.members) > 0: match announcement: - case "ende": + case "end_of_connection": if voice_announcement_enabled: announcement_status = await voice_announcer(destination, voice_channel) if announcement_status: return embed = build_announcement_embed( f'Sehr geehrte Fahrgäste,\nIn wenigen Minuten erreichen wir {destination}. Dieser Zug endet dort.\n\nWir wünschen Ihnen eine angenehme Weiterreise.\n\nVielen Dank für ihr Vertrauen und auf Wiedersehen.') - case "umstieg": + case "transfer": embed = build_info_embed() case _: - logger(f"Unbekanntes Announcements: {announcement}") + logger(f"Unknown announcement: {announcement}") embed = None if embed: await voice_channel.send(embed=embed) - else: - logger(f"Announcement {announcement} wird geskipped, keiner da") - return - async def voice_announcer(destination: str, voice_channel: discord.VoiceChannel) -> bool: sound_path = get_sound_path(destination=destination) if sound_path is None: return False - logger(f"VC wird betreten, spiele {sound_path}") + logger(f"Joining vc, playing {sound_path}") vc = await voice_channel.connect(timeout=15, reconnect=True) audio_source = discord.FFmpegPCMAudio(sound_path) @@ -87,7 +83,7 @@ async def voice_announcer(destination: str, voice_channel: discord.VoiceChannel) if error: logger(f"Player error: {error}", "error") loop.create_task(vc.disconnect()) - logger("VC wird verlassen") + logger("Leaving vc") vc.play(audio_source, after=after_playing) return True @@ -100,15 +96,15 @@ async def _schedule_next_transfer(bot: discord.Bot, arrival_dt: datetime, voice_ if wait_seconds > 0: remaining = str(timedelta(seconds=wait_seconds)) - logger(f"Nächster Umstieg in {remaining.split('.')[0]} ({arrival_dt.strftime('%H:%M')} Uhr)") + logger(f"Nexxt transfer in {remaining.split('.')[0]} ({arrival_dt.strftime('%H:%M')} Uhr)") if wait_seconds > announcement_countdown: wait_until_end_announcement = wait_seconds - announcement_countdown await asyncio.sleep(wait_until_end_announcement) - await announcer("ende", voice_channel, destination) + await announcer("end_of_connection", voice_channel, destination) await asyncio.sleep(announcement_countdown) else: await asyncio.sleep(wait_seconds) - logger("Zug angekommen, wähle neue Verbindung") + logger("Train arrived, searching for a new connection....") await rename_vc(bot, voice_channel, from_scheduler=True) \ No newline at end of file diff --git a/src/dc/helpers.py b/src/dc/helpers.py index 3efc8e8..e8b3568 100644 --- a/src/dc/helpers.py +++ b/src/dc/helpers.py @@ -6,12 +6,12 @@ def validate_channel(bot: discord.bot, server_id: int, channel_id: int): guild = bot.get_guild(server_id) if guild is None: - logger(f"Es konnte kein Server mit der ID {server_id} gefunden werden", "fatal") + logger(f"Couldn't find server with ID '{server_id}', is the bot invited?", "fatal") return False channel = guild.get_channel(channel_id) if not isinstance(channel, discord.VoiceChannel): - logger(f"Es konnte kein VC mit der id {channel_id} gefunden werden", "fatal") + logger(f"Couldn't find vc with '{channel_id}'", "fatal") return False return channel diff --git a/src/utils.py b/src/utils.py index 000cbe0..26d96b0 100644 --- a/src/utils.py +++ b/src/utils.py @@ -33,12 +33,12 @@ def validate_connection(start_time: str, end_time: str, departure_time_iso: str) end_dt = datetime.fromisoformat(end_time.replace("Z", "+00:00")) if end_dt < now: - logger(f"Verbindung liegt bereits in der Vergangenheit: {start_dt}", "error") + logger(f"Connection is from the past: {start_dt}", "error") return False max_wait_time = config.connections.max_wait_time if start_dt > now + timedelta(hours=max_wait_time): - logger(f"Verbindung liegt zu weit in der Zukunft: {start_dt}", "error") + logger(f"Connection is way too far in the future: {start_dt} (max_wait_time: {max_wait_time}h)", "error") return False departure_time_iso_dt = datetime.fromisoformat(departure_time_iso.replace("Z", "+00:00")) @@ -48,14 +48,14 @@ def validate_connection(start_time: str, end_time: str, departure_time_iso: str) min_duration = config.connections.min_duration min_duration_seconds = min_duration * 60 if trip_duration < min_duration_seconds: - logger(f"Verbindung ist mit {trip_duration_minutes} zu kurz (mindestens {min_duration} Minuten gewollt)", "error") + logger(f"Connection is with {trip_duration_minutes} minutes too short (configured to {min_duration} minutes or more)", "error") return False max_duration = config.connections.max_duration if max_duration: max_duration_seconds = max_duration * 60 if max_duration_seconds < trip_duration: - logger(f"Verbindung ist mit {trip_duration_minutes} zu lang (höchstens {max_duration} Minuten gewollt)", "error") + logger(f"Connection is with {trip_duration_minutes} too long (configured to {max_duration} minutes at most)", "error") return False return True @@ -98,8 +98,6 @@ def _reload_operators_if_changed(): if current_mtime != _operator_mtime: importlib.reload(operators) _operator_mtime = current_mtime - logger("operators.py wurde automatisch neu geladen (Änderungen erkannt)") - def get_operator_metadata(agency: str, route_color: str, mode: str) -> dict: _reload_operators_if_changed() @@ -142,7 +140,7 @@ def get_sound_path(destination) -> str | None: sound_path = f"src/data/announcements/{sound_file}" if Path(sound_path).is_file() is False: - logger(f"Konnte Datei {sound_path} nicht finden", "error") + logger(f"Couldn't find {sound_path}", "error") return None return sound_path