1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Some bugfixes

This commit is contained in:
Steffo 2019-08-29 16:39:13 +02:00
parent d7617dc5c3
commit 6577aa4ff6
3 changed files with 21 additions and 7 deletions

View file

@ -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}")

View file

@ -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

View file

@ -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()