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 @bot.event
async def on_command_error(ctx, error): async def on_command_error(ctx, error):
error_text = str(error)
log.error(f"Error with \"{ctx.message.content}\" from " log.error(f"Error with \"{ctx.message.content}\" from "
f"\"{ctx.message.author} ({ctx.message.author.id}) " 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): if isinstance(error, commands.NoPrivateMessage):
return await ctx.send("This command doesn't work on DMs.") 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. " return await ctx.send(f"{ctx.author.mention}: Check failed. "
"You might not have the right permissions " "You might not have the right permissions "
"to run this command.") "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): elif isinstance(error, commands.CommandNotFound):
# Nothing to do when command is not found. # Nothing to do when command is not found.
return return

View file

@ -13,9 +13,13 @@ class AdminCog:
self.previous_eval_code = None self.previous_eval_code = None
def check_if_staff(ctx): 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) return any(r.id in config.staff_role_ids for r in ctx.author.roles)
def check_if_bot_manager(ctx): 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) return any(r.id == config.bot_manager_role_id for r in ctx.author.roles)
@commands.guild_only() @commands.guild_only()

View file

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

View file

@ -8,6 +8,8 @@ class Lockdown:
self.bot = bot self.bot = bot
def check_if_staff(ctx): 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) return any(r.id in config.staff_role_ids for r in ctx.author.roles)
@commands.guild_only() @commands.guild_only()

View file

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

View file

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

View file

@ -104,6 +104,8 @@ class Verification:
self.bot = bot self.bot = bot
def check_if_staff(ctx): 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) return any(r.id in config.staff_role_ids for r in ctx.author.roles)
@commands.check(check_if_staff) @commands.check(check_if_staff)