diff --git a/royalnet/bots/discord.py b/royalnet/bots/discord.py index fb9d5c73..47fccfec 100644 --- a/royalnet/bots/discord.py +++ b/royalnet/bots/discord.py @@ -117,14 +117,16 @@ class DiscordBot(GenericBot): # Prepare data data = self._Data(interface=command.interface, message=message) # Call the command + log.debug(f"Calling command '{command.name}'") with message.channel.typing(): try: await command.run(CommandArgs(parameters), data=data) except Exception as e: sentry_sdk.capture_exception(e) - error_message = f"⛔️ {e.__class__.__name__}\n" + error_message = f"{e.__class__.__name__}\n" error_message += '\n'.join(e.args) - await data.reply(error_message) + log.error(f"Error in {command.name}: {error_message}") + await data.reply(f"⛔️ {error_message}") async def on_ready(cli): log.debug("Connection successful, client is ready") @@ -210,9 +212,9 @@ class DiscordBot(GenericBot): async def run(self): """Login to Discord, then run the bot.""" - log.debug(f"Logging in to Discord") + log.info(f"Logging in to Discord") await self.client.login(self._discord_config.token) - log.debug(f"Connecting to Discord") + log.info(f"Connecting to Discord") await self.client.connect() # TODO: how to stop? @@ -237,7 +239,8 @@ class DiscordBot(GenericBot): def advance(error=None): if error: - raise Exception(f"Error while advancing music_data: {error}") + log.error(f"Error while advancing music_data: {error}") + return self.loop.create_task(self.advance_music_data(guild)) log.debug(f"Starting playback of {next_source}") diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 18225e94..88741f70 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -125,13 +125,20 @@ class TelegramBot(GenericBot): async def run(self): while True: # Get the latest 100 updates + log.debug("Calling getUpdates...") try: last_updates: typing.List[telegram.Update] = await asyncify(self.client.get_updates, offset=self._offset, - timeout=60) - except telegram.error.TelegramError as error: + timeout=30, + read_latency=5.0) + except telegram.error.TimedOut as error: + log.debug("getUpdates timed out") + continue + except Exception as error: + log.error(f"Error while getting updates: {error.__class__.__name__} {error.args}") sentry_sdk.capture_exception(error) await asyncio.sleep(5) + continue # Handle updates for update in last_updates: # noinspection PyAsyncCall diff --git a/royalnet/royalgames.py b/royalnet/royalgames.py index 4b3042c6..7fde45d9 100644 --- a/royalnet/royalgames.py +++ b/royalnet/royalgames.py @@ -69,5 +69,9 @@ tg_bot = TelegramBot(telegram_config=TelegramConfig(os.environ["TG_AK"]), loop.create_task(tg_bot.run()) loop.create_task(ds_bot.run()) +print("Enabled commands:") +for command in commands: + print(f"{command.name} - {command.description}") + print("Running loop...") loop.run_forever()