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 # Prepare data
data = self._Data(interface=command.interface, message=message) data = self._Data(interface=command.interface, message=message)
# Call the command # Call the command
log.debug(f"Calling command '{command.name}'")
with message.channel.typing(): with message.channel.typing():
try: try:
await command.run(CommandArgs(parameters), data=data) await command.run(CommandArgs(parameters), data=data)
except Exception as e: except Exception as e:
sentry_sdk.capture_exception(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) 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): async def on_ready(cli):
log.debug("Connection successful, client is ready") log.debug("Connection successful, client is ready")
@ -210,9 +212,9 @@ class DiscordBot(GenericBot):
async def run(self): async def run(self):
"""Login to Discord, then run the bot.""" """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) await self.client.login(self._discord_config.token)
log.debug(f"Connecting to Discord") log.info(f"Connecting to Discord")
await self.client.connect() await self.client.connect()
# TODO: how to stop? # TODO: how to stop?
@ -237,7 +239,8 @@ class DiscordBot(GenericBot):
def advance(error=None): def advance(error=None):
if error: 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)) self.loop.create_task(self.advance_music_data(guild))
log.debug(f"Starting playback of {next_source}") log.debug(f"Starting playback of {next_source}")

View file

@ -125,13 +125,20 @@ class TelegramBot(GenericBot):
async def run(self): async def run(self):
while True: while True:
# Get the latest 100 updates # Get the latest 100 updates
log.debug("Calling getUpdates...")
try: try:
last_updates: typing.List[telegram.Update] = await asyncify(self.client.get_updates, last_updates: typing.List[telegram.Update] = await asyncify(self.client.get_updates,
offset=self._offset, offset=self._offset,
timeout=60) timeout=30,
except telegram.error.TelegramError as error: 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) sentry_sdk.capture_exception(error)
await asyncio.sleep(5) await asyncio.sleep(5)
continue
# Handle updates # Handle updates
for update in last_updates: for update in last_updates:
# noinspection PyAsyncCall # 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(tg_bot.run())
loop.create_task(ds_bot.run()) loop.create_task(ds_bot.run())
print("Enabled commands:")
for command in commands:
print(f"{command.name} - {command.description}")
print("Running loop...") print("Running loop...")
loop.run_forever() loop.run_forever()