LBI/modules/errors/__init__.py

106 lines
5.1 KiB
Python
Raw Permalink Normal View History

2019-02-25 20:29:13 +01:00
import asyncio
2019-03-02 14:38:37 +01:00
import random
import traceback
import collections
2019-03-02 14:38:37 +01:00
import discord
2019-04-07 21:31:13 +02:00
from modules.base import BaseClass
2019-03-02 14:38:37 +01:00
2019-04-07 21:31:13 +02:00
class MainClass(BaseClass):
name = "errors"
description = "Error handling"
interactive = True
super_users_list = [431043517217898496]
color = 0xdb1348
help = {
"description": "Montre toutes les erreurs du bot dans discord.",
"commands": {
"`{prefix}{command}`": "Renvoie une erreur de test.",
}
}
command_text = "unicorn"
2019-03-02 14:38:37 +01:00
2019-04-07 21:31:13 +02:00
def __init__(self, client):
super().__init__(client)
2019-03-02 14:38:37 +01:00
self.errorsDeque = None
2019-04-07 21:31:13 +02:00
self.development_chan_id = [456142390726623243, 473637619310264330, 474267318332030987]
2019-03-02 14:38:37 +01:00
self.memes = [
2019-04-07 21:31:13 +02:00
"https://cdn.discordapp.com/attachments/430408983283761152/430433931272126465/Bruce_3.png",
"https://cdn.discordapp.com/attachments/430408983283761152/430431622521946123/LUNE.jpg",
"https://cdn.discordapp.com/attachments/326742676672086018/431570139016724480/27th3c.png",
"https://cdn.discordapp.com/attachments/326742676672086018/431570538868244492/27th8d.png",
"https://cdn.discordapp.com/attachments/326742676672086018/431570620942123009/lemdpc3.png",
"https://cdn.discordapp.com/attachments/326742676672086018/431570838026846208/telecharge_15.jpg",
"https://cdn.discordapp.com/attachments/326742676672086018/431571174078808070/telecharge_16.jpg",
"https://cdn.discordapp.com/attachments/326742676672086018/431571655115145217/unknown.png",
"https://cdn.discordapp.com/attachments/326742676672086018/431574206518525963/Bruce_troll_QHwYz39nj7i.png",
"https://cdn.discordapp.com/attachments/326742676672086018/431572693910028289/telecharge_19.jpg"
"https://cdn.discordapp.com/attachments/434475794631360512/447168326582665241/2akl04.jpg",
"https://cdn.discordapp.com/attachments/434475794631360512/447168125067067394/20180519_004620.png",
"https://cdn.discordapp.com/attachments/434475794631360512/446441679868788736/Sans_titre_0.png",
"https://cdn.discordapp.com/attachments/434475794631360512/446441465611026443/unknown.png",
"https://cdn.discordapp.com/attachments/297868535076749323/445789702373638164/image.png",
"https://cdn.discordapp.com/attachments/297868535076749323/297875363160129540/unknown.png",
"https://cdn.discordapp.com/attachments/326742316456869888/447887603664945163/unknown.png",
"https://cdn.discordapp.com/attachments/434475794631360512/460876662414901249/TeslaPLS.png"
2019-02-25 20:29:13 +01:00
]
2019-03-02 22:05:15 +01:00
self.icon = "https://cdn.discordapp.com/attachments/340620490009739265/431569015664803840/photo.png"
2019-03-02 14:38:37 +01:00
2019-02-25 20:29:13 +01:00
async def on_ready(self):
2019-03-02 22:05:15 +01:00
if self.save_exists('errorsDeque'):
self.errorsDeque = self.load_object('errorsDeque')
2019-02-25 20:29:13 +01:00
else:
2019-03-02 14:38:37 +01:00
self.errorsDeque = collections.deque()
2019-02-25 20:29:13 +01:00
for i in range(len(self.errorsDeque)):
try:
2019-03-02 14:38:37 +01:00
messagelst = self.errorsDeque.popleft()
2019-02-25 20:29:13 +01:00
channel = self.client.get_channel(messagelst[0])
delete_message = await channel.get_message(messagelst[1])
await delete_message.delete()
except:
raise
2019-03-02 22:05:15 +01:00
self.save_object(self.errorsDeque, 'errorsDeque')
2019-03-02 14:38:37 +01:00
2019-04-07 21:31:13 +02:00
async def command(self, message, args, kwargs):
raise BaseException("Si cette erreur apparait, alors tout est normal")
2019-02-25 20:29:13 +01:00
async def on_error(self, event, *args, **kwargs):
2019-03-02 14:38:37 +01:00
embed = discord.Embed(title="Aïe :/", description="```PYTHON\n{0}```".format(traceback.format_exc()),
color=self.color).set_image(url=random.choice(self.memes))
2019-03-02 22:05:15 +01:00
message_list = None
2019-02-25 20:29:13 +01:00
try:
2019-03-02 14:38:37 +01:00
message = await args[0].channel.send(
2019-04-07 21:31:13 +02:00
embed=embed.set_footer(text="Ce message va s'autodétruire dans une minute.", icon_url=self.icon))
2019-03-02 22:05:15 +01:00
message_list = [message.channel.id, message.id]
self.errorsDeque.append(message_list)
2019-02-25 20:29:13 +01:00
except:
try:
2019-03-02 14:38:37 +01:00
message = args[1].channel.send(
2019-04-07 21:31:13 +02:00
embed=embed.set_footer(text="Ce message va s'autodétruire dans une minute.", icon_url=self.icon))
2019-03-02 22:05:15 +01:00
message_list = [message.channel.id, message.id]
self.errorsDeque.append(message_list)
2019-02-25 20:29:13 +01:00
except:
pass
2019-04-07 21:31:13 +02:00
for chanid in self.development_chan_id:
2019-02-25 20:29:13 +01:00
try:
2019-03-02 14:38:37 +01:00
await self.client.get_channel(chanid).send(
embed=embed.set_footer(text="Ce message ne s'autodétruira pas.", icon_url=self.icon))
2019-02-25 20:29:13 +01:00
except:
pass
2019-03-02 22:05:15 +01:00
self.save_object(self.errorsDeque, 'errorsDeque')
2019-02-25 20:29:13 +01:00
await asyncio.sleep(60)
try:
2019-03-02 22:05:15 +01:00
channel = self.client.get_channel(message_list[0])
delete_message = await channel.get_message(message_list[1])
2019-02-25 20:29:13 +01:00
await delete_message.delete()
except:
raise
finally:
try:
2019-03-02 22:05:15 +01:00
self.errorsDeque.remove(message_list)
except ValueError:
2019-02-25 20:29:13 +01:00
pass
2019-03-02 22:05:15 +01:00
self.save_object(self.errorsDeque, 'errorsDeque')