-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorhandler.py
194 lines (159 loc) · 5.45 KB
/
errorhandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import discord
from discord import Embed, Colour
from db import db
from discord.ext import commands, tasks
import time
t = True
def error_en(ctx, used=None, description=None, aliases=None, type=None):
embed = Embed(
description="> **Used:** `{}{}`\n**> Description:** `{}` \n> **Aliases:** `{}`\n> **Type:** `{}`".format(
db.get_prefix(ctx=ctx),
used,
description,
aliases,
type
), color=Colour.red())
return embed
def error_ar(ctx, used=None, description=None, aliases=None, type=None):
embed = Embed(
description="> **الأستعمال:** `{}{}`\n> **الوصف:** `{}` \n> **الأختصارات:** `{}`\n> "
"**النوع:** `{}`".format(
db.get_prefix(ctx=ctx),
used,
description,
aliases,
type
), color=Colour.red())
return embed
def error_permissions_en():
embed = Embed(
description="> 🙄 You don't have permissions",
color=Colour.red())
return embed
def error_permissions_ar():
embed = Embed(
description="> 🙄 ليس لديك أذونات كافيه",
color=Colour.red())
return embed
def bot_missing_permissions_en():
embed = Embed(
description='> ❌ I do not have permissions',
color=Colour.red()
)
return embed
def bot_missing_permissions_ar():
embed = Embed(
description='> ❌ ليس لدي أذونات كافيه',
color=Colour.red()
)
return embed
def channel_not_found_en():
embed = Embed(
description="> ❌ I could not find this channel",
color=Colour.red()
)
return embed
def channel_not_found_ar():
embed = Embed(
description="> ❌ لم أجد هذه الروم",
color=Colour.red()
)
return embed
def member_not_found_en():
embed = Embed(
description="> ❌ I could not find this member",
color=Colour.red()
)
return embed
def member_not_found_ar():
embed = Embed(
description="> ❌ لم أجد هذا العضو",
color=Colour.red()
)
return embed
def cooldown_er(error):
m, s = divmod(error.retry_after, 60)
embed = discord.Embed(
description="> ❌ Command Cooldown, please wait `{}` and try again".format("%02d seconds" % s),
color=0xf7072b
)
return embed
def cooldown_ar(error):
m, s = divmod(error.retry_after, 60)
embed = discord.Embed(
description="> يرجى الانتظار `{}` و المحاوله مرا اخرا".format("%02d ثانيه" % s),
color=0xf7072b
)
return embed
def winner_not_find_en():
embed = discord.Embed(
description="> ❌ I can't find a winner",
color=discord.Colour.red())
return embed
def winner_not_find_ar():
embed = discord.Embed(
description="> ❌ لا يمكنني العثور على فائز",
color=discord.Colour.red())
return embed
class ErrorHandler(commands.Cog):
def __init__(self, client):
self.client = client
self.cooldown = []
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
# print(db.get_cooldown())
if ctx.author.id in db.get_cooldown():
return
elif isinstance(error, commands.CommandOnCooldown):
m, s = divmod(error.retry_after, 60)
await ctx.send(embed=discord.Embed(
description=f"This command is currently **on cooldown** for ,Please **try again in** `{'%02d seconds' % (s,)}`.",
color=discord.Colour.red()
), delete_after=2)
db.cr.execute("INSERT OR IGNORE INTO cooldown(user_id) VALUES(?)", (ctx.author.id,))
db.commit()
return
elif isinstance(ctx.channel, discord.channel.DMChannel):
return
elif isinstance(error, commands.errors.MemberNotFound):
embed = member_not_found_en()
if db.get_lang(ctx) == "ar":
embed = member_not_found_ar()
await ctx.send(embed=embed)
return
elif isinstance(error, commands.MissingRequiredArgument):
aliases = []
if ctx.command.aliases == []:
aliases = None
else:
aliases = ", ".join(ctx.command.aliases)
embed = discord.Embed(
description=f"**command:** {ctx.command.name}\n\
**help:** {ctx.command.help}\n\
**used:** {db.get_prefix(ctx)}{ctx.command.usage}\n\
**aliases:** {aliases}\n",
color=Colour.red()
).set_author(name=ctx.command.cog_name)
await ctx.send(embed=embed)
return
elif isinstance(error, commands.errors.BadArgument):
aliases = []
if ctx.command.aliases == []:
aliases = None
else:
aliases = ", ".join(ctx.command.aliases)
embed = discord.Embed(
description=f"**command:** {ctx.command.name}\n\
**help:** {ctx.command.help}\n\
**used:** {db.get_prefix(ctx)}{ctx.command.usage}\n\
**aliases:** {aliases}\n",
color=Colour.red()
).set_author(name=ctx.command.cog_name)
await ctx.send(embed=embed)
return
elif isinstance(error, commands.errors.MissingPermissions):
await ctx.send(error)
else:
pass
def setup(client):
client.add_cog(ErrorHandler(client))