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

exception handling

This commit is contained in:
Steffo 2017-11-10 08:53:48 +01:00
parent df5f0d89bb
commit 7b1674b511
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: C27544372FBB445D
2 changed files with 25 additions and 10 deletions

View file

@ -9,4 +9,4 @@ telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_use
if __name__ == "__main__":
discord.start()
telegram.start()
telegram.start()

View file

@ -2,9 +2,7 @@ import datetime
import discord
import discord.opus
import functools
import sys
import db
import errors
import youtube_dl
@ -84,7 +82,8 @@ class Video:
"key": 'FFmpegExtractAudio',
"preferredcodec": 'opus'
}],
"outtmpl": "music.%(ext)s"}) as ytdl:
"outtmpl": "music.%(ext)s",
"quiet": True}) as ytdl:
info = await loop.run_in_executor(None, functools.partial(ytdl.extract_info, self.info["webpage_url"]))
except Exception as e:
client.send_message(self.channel, f"⚠ Errore durante il download del video:\n"
@ -98,14 +97,30 @@ async def find_user(user: discord.User):
user = await loop.run_in_executor(None, session.query(db.Discord).filter_by(discord_id=user.id).join(db.Royal).first)
return user
def on_error(event, *args, **kwargs):
print(f"ERRORE CRITICO NELL'EVENTO `{event}`\n"
f"Il bot si è chiuso per prevenire altri errori.\n"
f"Dettagli dell'errore:\n"
f"{sys.exc_info()}")
async def on_error(event, *args, **kwargs):
type, exception, traceback = sys.exc_info()
try:
await client.send_message(client.get_channel("368447084518572034"), f"☢️ ERRORE CRITICO NELL'EVENTO `{event}`\n"
f"Il bot si è chiuso per prevenire altri errori.\n\n"
f"Dettagli dell'errore:\n"
f"```python\n"
f"{repr(exception)}\n"
f"```")
await client.change_presence(status=discord.Status.invisible)
await client.close()
except Exception as e:
print("ERRORE CRITICO PIU' CRITICO:\n" + repr(e) + "\n" + repr(sys.exc_info()))
loop.stop()
sys.exit(1)
@client.event
async def on_ready():
await client.send_message(client.get_channel("368447084518572034"), f" Bot avviato e pronto a ricevere comandi!")
await client.change_presence(game=None, status=discord.Status.online)
@client.event
async def on_message(message: discord.Message):
global voice_queue
@ -275,7 +290,7 @@ async def on_message(message: discord.Message):
break
await client.send_message(message.channel, to_send)
elif __debug__ and message.content.startswith("!exception"):
raise Exception("sei un mostro")
raise Exception("!exception was called")
async def update_users_pipe(users_connection):