2019-04-28 18:59:08 +02:00
|
|
|
import asyncio
|
|
|
|
import random
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
import collections
|
|
|
|
import discord
|
|
|
|
|
2019-06-05 02:23:11 +02:00
|
|
|
from modules.base import BaseClassPython
|
2019-04-28 18:59:08 +02:00
|
|
|
|
|
|
|
|
2019-06-05 02:23:11 +02:00
|
|
|
class MainClass(BaseClassPython):
|
2019-04-28 18:59:08 +02:00
|
|
|
name = "errors"
|
|
|
|
description = "Error handling"
|
|
|
|
interactive = True
|
2019-08-10 09:30:46 +02:00
|
|
|
authorized_users = [431043517217898496]
|
|
|
|
authorized_roles = []
|
2019-04-28 18:59:08 +02:00
|
|
|
color = 0xdb1348
|
|
|
|
help = {
|
|
|
|
"description": "Montre toutes les erreurs du bot dans discord.",
|
|
|
|
"commands": {
|
|
|
|
"`{prefix}{command}`": "Renvoie une erreur de test.",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_text = "unicorn"
|
|
|
|
|
|
|
|
def __init__(self, client):
|
|
|
|
super().__init__(client)
|
|
|
|
self.errorsDeque = None
|
|
|
|
self.development_chan_id = []
|
|
|
|
self.memes = [
|
|
|
|
"",
|
|
|
|
]
|
|
|
|
self.icon = ""
|
|
|
|
|
|
|
|
async def on_ready(self):
|
2019-06-10 17:46:33 +02:00
|
|
|
if self.objects.save_exists('errorsDeque'):
|
|
|
|
self.errorsDeque = self.objects.load_object('errorsDeque')
|
2019-04-28 18:59:08 +02:00
|
|
|
else:
|
|
|
|
self.errorsDeque = collections.deque()
|
|
|
|
for i in range(len(self.errorsDeque)):
|
|
|
|
try:
|
|
|
|
messagelst = self.errorsDeque.popleft()
|
|
|
|
channel = self.client.get_channel(messagelst[0])
|
|
|
|
delete_message = await channel.fetch_message(messagelst[1])
|
|
|
|
await delete_message.delete()
|
|
|
|
except:
|
|
|
|
raise
|
2019-08-08 22:43:46 +02:00
|
|
|
self.objects.save_object('errorsDeque', self.errorsDeque)
|
2019-04-28 18:59:08 +02:00
|
|
|
|
|
|
|
async def command(self, message, args, kwargs):
|
2019-08-08 22:43:46 +02:00
|
|
|
raise Exception("KERNEL PANIC!!!")
|
2019-04-28 18:59:08 +02:00
|
|
|
|
|
|
|
async def on_error(self, event, *args, **kwargs):
|
|
|
|
embed = discord.Embed(title="Aïe :/", description="```PYTHON\n{0}```".format(traceback.format_exc()),
|
|
|
|
color=self.color).set_image(url=random.choice(self.memes))
|
|
|
|
message_list = None
|
|
|
|
try:
|
|
|
|
message = await args[0].channel.send(
|
|
|
|
embed=embed.set_footer(text="Ce message va s'autodétruire dans une minute.", icon_url=self.icon))
|
|
|
|
message_list = [message.channel.id, message.id]
|
|
|
|
self.errorsDeque.append(message_list)
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
message = args[1].channel.send(
|
|
|
|
embed=embed.set_footer(text="Ce message va s'autodétruire dans une minute.", icon_url=self.icon))
|
|
|
|
message_list = [message.channel.id, message.id]
|
|
|
|
self.errorsDeque.append(message_list)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
for chanid in self.development_chan_id:
|
|
|
|
try:
|
|
|
|
await self.client.get_channel(chanid).send(
|
|
|
|
embed=embed.set_footer(text="Ce message ne s'autodétruira pas.", icon_url=self.icon))
|
|
|
|
except:
|
|
|
|
pass
|
2019-08-08 22:43:46 +02:00
|
|
|
self.objects.save_object('errorsDeque', self.errorsDeque)
|
2019-04-28 18:59:08 +02:00
|
|
|
await asyncio.sleep(60)
|
|
|
|
try:
|
|
|
|
channel = self.client.get_channel(message_list[0])
|
|
|
|
delete_message = await channel.fetch_message(message_list[1])
|
|
|
|
await delete_message.delete()
|
|
|
|
except:
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
self.errorsDeque.remove(message_list)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2019-08-08 22:43:46 +02:00
|
|
|
self.objects.save_object('errorsDeque', self.errorsDeque)
|