1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54: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

@ -2,9 +2,7 @@ import datetime
import discord import discord
import discord.opus import discord.opus
import functools import functools
import sys import sys
import db import db
import errors import errors
import youtube_dl import youtube_dl
@ -84,7 +82,8 @@ class Video:
"key": 'FFmpegExtractAudio', "key": 'FFmpegExtractAudio',
"preferredcodec": 'opus' "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"])) info = await loop.run_in_executor(None, functools.partial(ytdl.extract_info, self.info["webpage_url"]))
except Exception as e: except Exception as e:
client.send_message(self.channel, f"⚠ Errore durante il download del video:\n" 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) user = await loop.run_in_executor(None, session.query(db.Discord).filter_by(discord_id=user.id).join(db.Royal).first)
return user return user
def on_error(event, *args, **kwargs):
print(f"ERRORE CRITICO NELL'EVENTO `{event}`\n" async def on_error(event, *args, **kwargs):
f"Il bot si è chiuso per prevenire altri errori.\n" type, exception, traceback = sys.exc_info()
f"Dettagli dell'errore:\n" try:
f"{sys.exc_info()}") 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) 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 @client.event
async def on_message(message: discord.Message): async def on_message(message: discord.Message):
global voice_queue global voice_queue
@ -275,7 +290,7 @@ async def on_message(message: discord.Message):
break break
await client.send_message(message.channel, to_send) await client.send_message(message.channel, to_send)
elif __debug__ and message.content.startswith("!exception"): elif __debug__ and message.content.startswith("!exception"):
raise Exception("sei un mostro") raise Exception("!exception was called")
async def update_users_pipe(users_connection): async def update_users_pipe(users_connection):