This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
error_code.py
208 lines (150 loc) · 6.35 KB
/
error_code.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import discord
import untangle
from discord.ext import commands
class errorCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command(aliases = ["er", "err", "error", "code"])
async def errcode(self, nes, value: str = None):
if value == "<:insane:841971835645853706>":
await nes.send("Me too, but please enter a valid error code.")
return
if checkValue(value) == False:
await nes.send("Enter a valid error code!")
return
resources = [
("error_codes/bugcheck.xml", "Bugcheck"),
("error_codes/hresult.xml", "HRESULT"),
("error_codes/mmresult.xml", "Multimedia API"),
("error_codes/ntstatus.xml", "NTSTATUS"),
("error_codes/winerror.xml", "Win32"),
("error_codes/wm.xml", "Window Message")
]
value = adjustValue(value)
value = value.upper()
codes = []
for resource in resources:
res = find_and_get(value, resource[0])
if len(res) != 0:
codes.append(f"{resource[1]}: {res}")
if len(codes) == 0:
await nes.send("Error code not found in any dictionary. Double check the code and try again.")
else:
await nes.send("Found following results for the code:\n{}".format('\n'.join(codes)))
@commands.command(aliases = ["bugcheck", "bc"])
async def buc(self, nes, value: str = None):
if(checkValue(value) == False):
await nes.send("Enter a valid error code!")
return
obj = untangle.parse("error_codes/bugcheck.xml")
bugdict = {}
for BugCheck in obj.BugCheckList.BugCheck:
bugdict[BugCheck['value']] = BugCheck['text']
value = adjustValue(value)
value = value.upper()
if value in bugdict:
await nes.send("The meaning of this error code is - `{}`" .format(bugdict[value]))
else:
await nes.send("Error code not found! Please check the code and try again.")
@commands.command(aliases = ["hresult", "hr"])
async def hre(self, nes, value: str = None):
if(checkValue(value) == False):
await nes.send("Enter a valid error code!")
return
obj = untangle.parse("error_codes/hresult.xml")
hrdict = {}
for Hresult in obj.HresultList.Hresult:
hrdict[Hresult['value']] = Hresult['text']
value = adjustValue(value)
value = value.upper()
if value in hrdict:
await nes.send("The meaning of this error code is - `{}`" .format(hrdict[value]))
else:
await nes.send("Error code not found! Please check the code and try again.")
@commands.command(aliases = ["mmresult", "mm"])
async def mmr(self, nes, value: str = None):
if(checkValue(value) == False):
await nes.send("Enter a valid error code!")
return
obj = untangle.parse("error_codes/mmresult.xml")
mmdict = {}
for Mmresult in obj.MmresultList.Mmresult:
mmdict[Mmresult['value']] = Mmresult['text']
value = adjustValue(value)
value = value.upper()
if value in mmdict:
await nes.send("The meaning of this error code is - `{}`" .format(mmdict[value]))
else:
await nes.send("Error code not found! Please check the code and try again.")
@commands.command(aliases = ["ntresult", "nt"])
async def ntr(self, nes, value: str = None):
if(checkValue(value) == False):
await nes.send("Enter a valid error code!")
return
obj = untangle.parse("error_codes/ntstatus.xml")
ntdict = {}
for Ntstatus in obj.NtstatusList.Ntstatus:
ntdict[Ntstatus['value']] = Ntstatus['text']
value = adjustValue(value)
value = value.upper()
if value in ntdict:
await nes.send("The meaning of this error code is - `{}`" .format(ntdict[value]))
else:
await nes.send("Error code not found! Please check the code and try again.")
@commands.command(aliases = ["winerror", "win32"])
async def wie(self, nes, value: str = None):
if(checkValue(value) == False):
await nes.send("Enter a valid error code!")
return
obj = untangle.parse("error_codes/winerror.xml")
windict = {}
for Winerror in obj.WinerrorList.Winerror:
strValue = 8 - len(Winerror['value'])
errorCode = "0" * strValue + Winerror['value']
windict[errorCode] = Winerror['text']
value = adjustValue(value)
value = value.upper()
if value in windict:
await nes.send("The meaning of this error code is - `{}`" .format(windict[value]))
else:
await nes.send("Error code not found! Please check the code and try again.")
@commands.command(aliases = ["windowmessage", "wm"])
async def wme(self, nes, value: str = None):
if(checkValue(value) == False):
await nes.send("Enter a valid error code!")
return
obj = untangle.parse("error_codes/wm.xml")
wmdict = {}
for Wm in obj.WindowMessageList.WindowMessage:
strValue = 8 - len(Wm['value'])
errorCode = "0" * strValue + Wm['value']
wmdict[errorCode] = Wm['text']
value = adjustValue(value)
value = value.upper()
if value in wmdict:
await nes.send("The meaning of this error code is - `{}`" .format(wmdict[value]))
else:
await nes.send("Error code not found! Please check the code and try again.")
def adjustValue(value):
if any(c in value for c in "x"):
value = value[2:]
if len(value) < 8:
strValue = 8 - len(value)
value = "0" * strValue + value
return value
def checkValue(value):
invalid_chars = set("!@#$%^&*()-_=+/*-[];',.\|<>?}{`~₹€")
if not value:
return False
elif any((c in invalid_chars) for c in value):
return False
return True
def find_and_get(value, file):
obj = untangle.parse(file)
for code in obj.get_elements()[0].get_elements():
fix_value = "0" * (8 - len(code["value"])) + code["value"]
if fix_value == value:
return code['text']
return ""
def setup(client):
client.add_cog(errorCog(client))