[Mod] Fixed some case toggles not working properly

Check is now done at function level
This commit is contained in:
Twentysix 2017-03-10 05:51:37 +01:00
parent 5ba312c45a
commit 361d45e724

View File

@ -268,13 +268,11 @@ class Mod:
await self.bot.kick(user) await self.bot.kick(user)
logger.info("{}({}) kicked {}({})".format( logger.info("{}({}) kicked {}({})".format(
author.name, author.id, user.name, user.id)) author.name, author.id, user.name, user.id))
if self.settings[server.id].get('kick_cases', await self.new_case(server,
default_settings['kick_cases']): action="KICK",
await self.new_case(server, mod=author,
action="KICK", user=user,
mod=author, reason=reason)
user=user,
reason=reason)
await self.bot.say("Done. That felt good.") await self.bot.say("Done. That felt good.")
except discord.errors.Forbidden: except discord.errors.Forbidden:
await self.bot.say("I'm not allowed to do that.") await self.bot.say("I'm not allowed to do that.")
@ -317,13 +315,11 @@ class Mod:
await self.bot.ban(user, days) await self.bot.ban(user, days)
logger.info("{}({}) banned {}({}), deleting {} days worth of messages".format( logger.info("{}({}) banned {}({}), deleting {} days worth of messages".format(
author.name, author.id, user.name, user.id, str(days))) author.name, author.id, user.name, user.id, str(days)))
if self.settings[server.id].get('ban_cases', await self.new_case(server,
default_settings['ban_cases']): action="BAN",
await self.new_case(server, mod=author,
action="BAN", user=user,
mod=author, reason=reason)
user=user,
reason=reason)
await self.bot.say("Done. It was about time.") await self.bot.say("Done. It was about time.")
except discord.errors.Forbidden: except discord.errors.Forbidden:
await self.bot.say("I'm not allowed to do that.") await self.bot.say("I'm not allowed to do that.")
@ -365,13 +361,11 @@ class Mod:
logger.info("{}({}) softbanned {}({}), deleting 1 day worth " logger.info("{}({}) softbanned {}({}), deleting 1 day worth "
"of messages".format(author.name, author.id, user.name, "of messages".format(author.name, author.id, user.name,
user.id)) user.id))
if self.settings[server.id].get('softban_cases', await self.new_case(server,
default_settings['softban_cases']): action="SOFTBAN",
await self.new_case(server, mod=author,
action="SOFTBAN", user=user,
mod=author, reason=reason)
user=user,
reason=reason)
await self.bot.unban(server, user) await self.bot.unban(server, user)
await self.bot.say("Done. Enough chaos.") await self.bot.say("Done. Enough chaos.")
except discord.errors.Forbidden: except discord.errors.Forbidden:
@ -432,14 +426,12 @@ class Mod:
"lower than myself in the role hierarchy.") "lower than myself in the role hierarchy.")
else: else:
dataIO.save_json("data/mod/perms_cache.json", self._perms_cache) dataIO.save_json("data/mod/perms_cache.json", self._perms_cache)
if self.settings[server.id].get('cmute_cases', await self.new_case(server,
default_settings['cmute_cases']): action="CMUTE",
await self.new_case(server, channel=channel,
action="CMUTE", mod=author,
channel=channel, user=user,
mod=author, reason=reason)
user=user,
reason=reason)
await self.bot.say("User has been muted in this channel.") await self.bot.say("User has been muted in this channel.")
@checks.mod_or_permissions(administrator=True) @checks.mod_or_permissions(administrator=True)
@ -472,13 +464,11 @@ class Mod:
return return
self._perms_cache[user.id] = register self._perms_cache[user.id] = register
dataIO.save_json("data/mod/perms_cache.json", self._perms_cache) dataIO.save_json("data/mod/perms_cache.json", self._perms_cache)
if self.settings[server.id].get('smute_cases', await self.new_case(server,
default_settings['smute_cases']): action="SMUTE",
await self.new_case(server, mod=author,
action="SMUTE", user=user,
mod=author, reason=reason)
user=user,
reason=reason)
await self.bot.say("User has been muted in this server.") await self.bot.say("User has been muted in this server.")
@commands.group(pass_context=True, no_pm=True, invoke_without_command=True) @commands.group(pass_context=True, no_pm=True, invoke_without_command=True)
@ -1296,6 +1286,10 @@ class Mod:
return False return False
async def new_case(self, server, *, action, mod=None, user, reason=None, until=None, channel=None): async def new_case(self, server, *, action, mod=None, user, reason=None, until=None, channel=None):
action_type = action.lower() + "_cases"
if not self.settings[server.id].get(action_type, default_settings[action_type]):
return
mod_channel = server.get_channel(self.settings[server.id]["mod-log"]) mod_channel = server.get_channel(self.settings[server.id]["mod-log"])
if mod_channel is None: if mod_channel is None:
return return