playing: Add playing

Also this commit includes DRAM optimization (aka I sneakily cleaned
tomGER's code a bit)~
This commit is contained in:
Ave Ozkal 2018-12-23 20:36:40 +03:00
parent b67ddda4f1
commit 5d54ac7aec
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
4 changed files with 34 additions and 18 deletions

View file

@ -31,7 +31,7 @@ Based on https://gitlab.com/ao/dpybotbase
- [ ] Moderation: timelock (channel lockdown with time) - [ ] Moderation: timelock (channel lockdown with time)
- [ ] Moderation: mute-unmute - [ ] Moderation: mute-unmute
- [ ] Moderation: mutetime - [ ] Moderation: mutetime
- [ ] Moderation: playing - [x] Moderation: playing
- [ ] Moderation: botnickname - [ ] Moderation: botnickname
- [ ] Moderation: nickname - [ ] Moderation: nickname
- [ ] Moderation: clear/purge - [ ] Moderation: clear/purge

View file

@ -47,7 +47,7 @@ initial_extensions = ['cogs.common',
'cogs.meme'] 'cogs.meme']
bot = commands.Bot(command_prefix=get_prefix, bot = commands.Bot(command_prefix=get_prefix,
description=config.bot_description, pm_help=None) description=config.bot_description, pm_help=True)
bot.log = log bot.log = log
bot.config = config bot.config = config

View file

@ -4,6 +4,7 @@ import discord
from discord.ext import commands from discord.ext import commands
from data.errcodes import * from data.errcodes import *
class Err: class Err:
"Everything related to Nintendo 3DS, Wii U and Switch error codes" "Everything related to Nintendo 3DS, Wii U and Switch error codes"
@ -12,26 +13,27 @@ 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}')
print("Err has been loaded!")
@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):
"""Searches for Nintendo 3DS, Switch and Wii U error codes! """Searches for Nintendo 3DS, Switch and Wii U error codes!
Usage: .serr/.nxerr/.nin_err/.err <Error Code>""" Usage: .serr/.nxerr/.nin_err/.err <Error Code>"""
if self.dds_re.match(err): # 3DS - dds -> Drei DS -> Three DS if self.dds_re.match(err): # 3DS - dds -> Drei DS -> Three DS
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> so it can be added to the bot." 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."
# Make a nice Embed out of it # Make a nice Embed out of it
embed = discord.Embed(title=err, url="https://www.youtube.com/watch?v=x3yXlomPCmU", description=err_description) embed = discord.Embed(title=err,
url="https://www.youtube.com/watch?v=x3yXlomPCmU",
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 apperently ... ? elif err.startswith("0x"): # These are not similar to the other errors apperently ... ?
derr = err[2:] derr = err[2:]
derr = derr.strip() derr = derr.strip()
rc = int(derr, 16) rc = int(derr, 16)
@ -51,8 +53,8 @@ class Err:
await ctx.send(embed=embed) await ctx.send(embed=embed)
return return
elif self.wiiu_re.match(err): # Wii U elif self.wiiu_re.match(err): # Wii U
module = err[2:3] # Is that even true, idk just guessing module = err[2:3] # Is that even true, idk just guessing
desc = err[5:8] desc = err[5:8]
if err in wii_u_errors: if err in wii_u_errors:
err_description = wii_u_errors[err] err_description = wii_u_errors[err]
@ -66,10 +68,10 @@ class Err:
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)
if self.switch_re.match(err) or err.startswith("0x"): # Switch
if self.switch_re.match(err) or err.startswith("0x"): # Switch
if err.startswith("0x"): if err.startswith("0x"):
err = err[2:] err = err[2:]
errcode = int(err, 16) errcode = int(err, 16)
@ -79,7 +81,7 @@ class Err:
module = int(err[0:4]) - 2000 module = int(err[0:4]) - 2000
desc = int(err[5:9]) desc = int(err[5:9])
errcode = (desc << 9) + module errcode = (desc << 9) + module
str_errcode = '{:04}-{:04}'.format(module + 2000, desc) str_errcode = '{:04}-{:04}'.format(module + 2000, desc)
# Searching for Modules in list # Searching for Modules in list
@ -109,8 +111,8 @@ class Err:
# 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 elif err in switch_game_err: # Special Case Handling because Nintendo feels like its required to break their format lol
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="https://www.youtube.com/watch?v=x3yXlomPCmU", description=desc)
embed.set_footer(text="Console: Switch") embed.set_footer(text="Console: Switch")
@ -132,7 +134,7 @@ class Err:
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):
"""Converts Nintendo Switch errors to hex """Converts Nintendo Switch errors to hex
@ -143,9 +145,9 @@ class Err:
module = err & 0x1FF module = err & 0x1FF
desc = (err >> 9) & 0x3FFF desc = (err >> 9) & 0x3FFF
errcode = '{:04}-{:04}'.format(module + 2000, desc) errcode = '{:04}-{:04}'.format(module + 2000, desc)
await ctx.send(errcode) await ctx.send(errcode)
else: else:
await ctx.send("This doesn't look like typical hex!") await ctx.send("This doesn't look like typical hex!")
def setup(bot): def setup(bot):

View file

@ -92,6 +92,7 @@ class ModCog:
await modlog_channel.send(chan_message) await modlog_channel.send(chan_message)
await ctx.send(f"{safe_name} is now b&. 👍") await ctx.send(f"{safe_name} is now b&. 👍")
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True) @commands.bot_has_permissions(ban_members=True)
@commands.check(check_if_staff) @commands.check(check_if_staff)
@commands.command() @commands.command()
@ -118,6 +119,7 @@ class ModCog:
modlog_channel = self.bot.get_channel(config.modlog_channel) modlog_channel = self.bot.get_channel(config.modlog_channel)
await modlog_channel.send(chan_message) await modlog_channel.send(chan_message)
@commands.guild_only()
@commands.check(check_if_staff) @commands.check(check_if_staff)
@commands.command() @commands.command()
async def userinfo(self, ctx, *, user: discord.Member): async def userinfo(self, ctx, *, user: discord.Member):
@ -136,6 +138,18 @@ class ModCog:
f"color = {user.colour}\n" f"color = {user.colour}\n"
f"top_role = {role}\n") f"top_role = {role}\n")
@commands.guild_only()
@commands.check(check_if_staff)
@commands.command(aliases=["setplaying", "setgame"])
async def playing(self, ctx, *, game: str = ""):
"""Sets the currently played game name, staff only.
Just send .playing to wipe the playing state."""
if game:
await self.bot.change_presence(activity=discord.Game(name=game))
else:
await self.bot.change_presence(activity=None)
def setup(bot): def setup(bot):
bot.add_cog(ModCog(bot)) bot.add_cog(ModCog(bot))