err: get pep8 compliant and reduce string repetition

sorry tomger, lol
This commit is contained in:
Ave Ozkal 2018-12-24 11:09:35 +03:00
parent 96bfb9ef28
commit 3b062a2ac3
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B

View file

@ -13,6 +13,11 @@ class Err:
self.dds_re = re.compile(r'0\d{2}\-\d{4}') self.dds_re = re.compile(r'0\d{2}\-\d{4}')
self.wiiu_re = re.compile(r'1\d{2}\-\d{4}') self.wiiu_re = re.compile(r'1\d{2}\-\d{4}')
self.switch_re = re.compile(r'2\d{3}\-\d{4}') self.switch_re = re.compile(r'2\d{3}\-\d{4}')
self.no_err_desc = "It seems like your error code is unknown. "\
"You should report relevant details to "\
"<@141532589725974528> (tomGER) "\
"so it can be added to the bot."
self.rickroll = "https://www.youtube.com/watch?v=x3yXlomPCmU"
@commands.command(aliases=["nxerr", "serr", "nin_err"]) @commands.command(aliases=["nxerr", "serr", "nin_err"])
async def err(self, ctx, err: str): async def err(self, ctx, err: str):
@ -23,17 +28,18 @@ class Err:
if err in dds_errcodes: if err in dds_errcodes:
err_description = dds_errcodes[err] err_description = dds_errcodes[err]
else: else:
err_description = "It seems like your error code is unknown. You should report relevant details to <@141532589725974528> (tomGER) so it can be added to the bot." err_description = self.no_err_desc
# Make a nice Embed out of it # Make a nice Embed out of it
embed = discord.Embed(title=err, embed = discord.Embed(title=err,
url="https://www.youtube.com/watch?v=x3yXlomPCmU", url=self.rickroll,
description=err_description) description=err_description)
embed.set_footer(text="Console: 3DS") embed.set_footer(text="Console: 3DS")
# Send message, crazy # Send message, crazy
await ctx.send(embed=embed) await ctx.send(embed=embed)
elif err.startswith("0x"): # These are not similar to the other errors apparently ... ? # These are not similar to the other errors apparently ... ?
elif err.startswith("0x"):
derr = err[2:] derr = err[2:]
derr = derr.strip() derr = derr.strip()
rc = int(derr, 16) rc = int(derr, 16)
@ -41,13 +47,17 @@ class Err:
mod = (rc >> 10) & 0xFF mod = (rc >> 10) & 0xFF
summ = (rc >> 21) & 0x3F summ = (rc >> 21) & 0x3F
level = (rc >> 27) & 0x1F level = (rc >> 27) & 0x1F
if mod in dds_modules and summ in dds_summaries and desc in dds_descriptions and level in dds_levels: if (mod in dds_modules) and\
(summ in dds_summaries) and\
(desc in dds_descriptions) and\
(level in dds_levels):
# ^ Lets just make extra sure that everything is right :P # ^ Lets just make extra sure that everything is right :P
embed = discord.Embed(title=f"0x{rc:X}") embed = discord.Embed(title=f"0x{rc:X}")
embed.add_field(name="Module", value=dds_modules[mod], inline=False) embed.add_field(name="Module", value=dds_modules[mod])
embed.add_field(name="Description", value=dds_descriptions[desc], inline=False) embed.add_field(name="Description",
embed.add_field(name="Summary", value=dds_summaries[summ], inline=False) value=dds_descriptions[desc])
embed.add_field(name="Level", value=dds_levels[level], inline=False) embed.add_field(name="Summary", value=dds_summaries[summ])
embed.add_field(name="Level", value=dds_levels[level])
embed.set_footer(text="Console: 3DS") embed.set_footer(text="Console: 3DS")
await ctx.send(embed=embed) await ctx.send(embed=embed)
@ -59,11 +69,11 @@ class Err:
if err in wii_u_errors: if err in wii_u_errors:
err_description = wii_u_errors[err] err_description = wii_u_errors[err]
else: else:
err_description = "It seems like your error code is unknown. You should report relevant details to <@141532589725974528> (tomGER) so it can be added to the bot." err_description = self.no_err_desc
# Make a nice Embed out of it # Make a nice Embed out of it
embed = discord.Embed(title=err, embed = discord.Embed(title=err,
url="https://www.youtube.com/watch?v=x3yXlomPCmU", url=self.rickroll,
description=err_description) description=err_description)
embed.set_footer(text="Console: Wii U") embed.set_footer(text="Console: Wii U")
embed.add_field(name="Module", value=module, inline=True) embed.add_field(name="Module", value=module, inline=True)
@ -92,7 +102,8 @@ class Err:
else: else:
err_module = "Unknown" err_module = "Unknown"
# Searching for error codes related to the Switch (Doesn't include Special Cases) # Searching for error codes related to the Switch
# (doesn't include special cases)
if errcode in switch_known_errcodes: if errcode in switch_known_errcodes:
err_description = switch_known_errcodes[errcode] err_description = switch_known_errcodes[errcode]
elif errcode in switch_support_page: elif errcode in switch_support_page:
@ -102,30 +113,37 @@ class Err:
if desc >= errcode_range[0] and desc <= errcode_range[1]: if desc >= errcode_range[0] and desc <= errcode_range[1]:
err_description = errcode_range[2] err_description = errcode_range[2]
else: else:
err_description = "It seems like your error code is unknown. You should report relevant details to <@141532589725974528> so it can be added to the bot." err_description = self.no_err_desc
# Make a nice Embed out of it # Make a nice Embed out of it
embed = discord.Embed(title=f"{str_errcode} / {hex(errcode)}", embed = discord.Embed(title=f"{str_errcode} / {hex(errcode)}",
url="https://www.youtube.com/watch?v=x3yXlomPCmU", url=self.rickroll,
description=err_description) description=err_description)
embed.set_footer(text="Console: Switch") embed.set_footer(text="Console: Switch")
embed.add_field(name="Module", value=f"{err_module} ({module})", inline=True) embed.add_field(name="Module",
value=f"{err_module} ({module})",
inline=True)
embed.add_field(name="Description", value=desc, inline=True) embed.add_field(name="Description", value=desc, inline=True)
# Send message, crazy # Send message, crazy
await ctx.send(embed=embed) await ctx.send(embed=embed)
elif err in switch_game_err: # Special Case Handling because Nintendo feels like its required to break their format lol # Special case handling because Nintendo feels like
# its required to break their format lol
elif err in switch_game_err:
game, desc = switch_game_err[err].split(":") game, desc = switch_game_err[err].split(":")
embed = discord.Embed(title=err, url="https://www.youtube.com/watch?v=x3yXlomPCmU", description=desc) embed = discord.Embed(title=err,
url=self.rickroll,
description=desc)
embed.set_footer(text="Console: Switch") embed.set_footer(text="Console: Switch")
embed.add_field(name="Game", value=game, inline=True) embed.add_field(name="Game", value=game, inline=True)
await ctx.send(embed=embed) await ctx.send(embed=embed)
else: else:
await ctx.send("Unknown Format - This is either no error code or you made some mistake!") await ctx.send("Unknown Format - This is either "
"no error code or you made some mistake!")
@commands.command(aliases=["e2h"]) @commands.command(aliases=["e2h"])
async def err2hex(self, ctx, err: str): async def err2hex(self, ctx, err: str):
@ -137,7 +155,8 @@ class Err:
errcode = (desc << 9) + module errcode = (desc << 9) + module
await ctx.send(hex(errcode)) await ctx.send(hex(errcode))
else: else:
await ctx.send("This doesn't follow the typical Nintendo Switch 2XXX-XXXX format!") await ctx.send("This doesn't follow the typical"
" Nintendo Switch 2XXX-XXXX format!")
@commands.command(aliases=["h2e"]) @commands.command(aliases=["h2e"])
async def hex2err(self, ctx, err: str): async def hex2err(self, ctx, err: str):