Fix .help in DMs, make Robocop call you out when your DMs are blocked

Also limit membercount to guilds
This commit is contained in:
Ave Ozkal 2018-12-26 10:48:41 +03:00
parent fbdb441976
commit b35765d296
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
7 changed files with 26 additions and 2 deletions

View file

@ -104,9 +104,11 @@ async def on_error(event_method, *args, **kwargs):
@bot.event
async def on_command_error(ctx, error):
error_text = str(error)
log.error(f"Error with \"{ctx.message.content}\" from "
f"\"{ctx.message.author} ({ctx.message.author.id}) "
f"of type {type(error)}: {error}")
f"of type {type(error)}: {error_text}")
if isinstance(error, commands.NoPrivateMessage):
return await ctx.send("This command doesn't work on DMs.")
@ -129,6 +131,13 @@ async def on_command_error(ctx, error):
return await ctx.send(f"{ctx.author.mention}: Check failed. "
"You might not have the right permissions "
"to run this command.")
elif isinstance(error, commands.CommandInvokeError) and\
("Cannot send messages to this user" in error_text):
return await ctx.send(f"{ctx.author.mention}: I can't DM you.\n"
"You might have me blocked or have DMs "
f"blocked globally or for {ctx.guild.name}.\n"
"Please resolve that, then "
"run the command again.")
elif isinstance(error, commands.CommandNotFound):
# Nothing to do when command is not found.
return

View file

@ -13,9 +13,13 @@ class AdminCog:
self.previous_eval_code = None
def check_if_staff(ctx):
if not ctx.guild:
return False
return any(r.id in config.staff_role_ids for r in ctx.author.roles)
def check_if_bot_manager(ctx):
if not ctx.guild:
return False
return any(r.id == config.bot_manager_role_id for r in ctx.author.roles)
@commands.guild_only()

View file

@ -22,6 +22,7 @@ class Basic:
await ctx.send(f"{targetuser.mention}: A link to the rules "
f"can be found here: {config.rules_url}")
@commands.guild_only()
@commands.command()
async def membercount(self, ctx):
"""Prints the member count of the server."""

View file

@ -8,6 +8,8 @@ class Lockdown:
self.bot = bot
def check_if_staff(ctx):
if not ctx.guild:
return False
return any(r.id in config.staff_role_ids for r in ctx.author.roles)
@commands.guild_only()

View file

@ -14,6 +14,8 @@ class Meme:
self.bot = bot
def check_if_staff_or_ot(ctx):
if not ctx.guild:
return True
is_ot = (ctx.channel.name == "off-topic")
is_staff = any(r.id in config.staff_role_ids for r in ctx.author.roles)
return (is_ot or is_staff)

View file

@ -10,9 +10,13 @@ class ModCog:
self.bot = bot
def check_if_staff(ctx):
if not ctx.guild:
return False
return any(r.id in config.staff_role_ids for r in ctx.author.roles)
def check_if_target_is_staff(self, target):
if not ctx.guild:
return False
return any(r.id in config.staff_role_ids for r in target.roles)
async def add_restriction(self, member, rst):
@ -190,7 +194,7 @@ class ModCog:
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True)
@commands.check(check_if_staff)
@commands.command()
@commands.command(alias=["softban"])
async def hackban(self, ctx, target: int, *, reason: str = ""):
"""Bans a user with their ID, doesn't message them, staff only."""
target_user = await self.bot.get_user_info(target)

View file

@ -104,6 +104,8 @@ class Verification:
self.bot = bot
def check_if_staff(ctx):
if not ctx.guild:
return False
return any(r.id in config.staff_role_ids for r in ctx.author.roles)
@commands.check(check_if_staff)