mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Mod] Consistency periods & proper logging (#3895)
* Consistency periods & proper logging * woooo jack Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * Update kickban.py Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
parent
802641ce6b
commit
144b7b36d0
@ -78,7 +78,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
"hierarchy."
|
"hierarchy."
|
||||||
)
|
)
|
||||||
elif guild.me.top_role <= user.top_role or user == guild.owner:
|
elif guild.me.top_role <= user.top_role or user == guild.owner:
|
||||||
return _("I cannot do that due to discord hierarchy rules")
|
return _("I cannot do that due to discord hierarchy rules.")
|
||||||
elif not (0 <= days <= 7):
|
elif not (0 <= days <= 7):
|
||||||
return _("Invalid days. Must be between 0 and 7.")
|
return _("Invalid days. Must be between 0 and 7.")
|
||||||
|
|
||||||
@ -101,14 +101,19 @@ class KickBanMixin(MixinMeta):
|
|||||||
try:
|
try:
|
||||||
await guild.ban(user, reason=audit_reason, delete_message_days=days)
|
await guild.ban(user, reason=audit_reason, delete_message_days=days)
|
||||||
log.info(
|
log.info(
|
||||||
"{}({}) banned {}({}), deleting {} days worth of messages".format(
|
"{}({}) 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)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
return _("I'm not allowed to do that.")
|
return _("I'm not allowed to do that.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e # TODO: improper return type? Is this intended to be re-raised?
|
log.exception(
|
||||||
|
"{}({}) attempted to kick {}({}), but an error occurred.".format(
|
||||||
|
author.name, author.id, user.name, user.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return _("An unexpected error occurred.")
|
||||||
|
|
||||||
if create_modlog_case:
|
if create_modlog_case:
|
||||||
try:
|
try:
|
||||||
@ -156,7 +161,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
if e.code == 50013 or e.status == 403:
|
if e.code == 50013 or e.status == 403:
|
||||||
log.info(
|
log.info(
|
||||||
f"Failed to unban ({uid}) user from "
|
f"Failed to unban ({uid}) user from "
|
||||||
f"{guild.name}({guild.id}) guild due to permissions"
|
f"{guild.name}({guild.id}) guild due to permissions."
|
||||||
)
|
)
|
||||||
break # skip the rest of this guild
|
break # skip the rest of this guild
|
||||||
log.info(f"Failed to unban member: error code: {e.code}")
|
log.info(f"Failed to unban member: error code: {e.code}")
|
||||||
@ -195,7 +200,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
elif ctx.guild.me.top_role <= user.top_role or user == ctx.guild.owner:
|
elif ctx.guild.me.top_role <= user.top_role or user == ctx.guild.owner:
|
||||||
await ctx.send(_("I cannot do that due to discord hierarchy rules"))
|
await ctx.send(_("I cannot do that due to discord hierarchy rules."))
|
||||||
return
|
return
|
||||||
audit_reason = get_audit_reason(author, reason)
|
audit_reason = get_audit_reason(author, reason)
|
||||||
toggle = await self.config.guild(guild).dm_on_kickban()
|
toggle = await self.config.guild(guild).dm_on_kickban()
|
||||||
@ -216,7 +221,11 @@ class KickBanMixin(MixinMeta):
|
|||||||
except discord.errors.Forbidden:
|
except discord.errors.Forbidden:
|
||||||
await ctx.send(_("I'm not allowed to do that."))
|
await ctx.send(_("I'm not allowed to do that."))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
log.exception(
|
||||||
|
"{}({}) attempted to kick {}({}), but an error occurred.".format(
|
||||||
|
author.name, author.id, user.name, user.id
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
@ -454,7 +463,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
await ctx.send(_("I can't do that for some reason."))
|
await ctx.send(_("I can't do that for some reason."))
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
await ctx.send(_("Something went wrong while banning"))
|
await ctx.send(_("Something went wrong while banning."))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
@ -469,7 +478,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
await ctx.send(_("Done. Enough chaos for now"))
|
await ctx.send(_("Done. Enough chaos for now."))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -522,17 +531,25 @@ class KickBanMixin(MixinMeta):
|
|||||||
await msg.delete()
|
await msg.delete()
|
||||||
return
|
return
|
||||||
except discord.HTTPException as e:
|
except discord.HTTPException as e:
|
||||||
print(e)
|
log.exception(
|
||||||
|
"{}({}) attempted to softban {}({}), but an error occurred trying to ban them.".format(
|
||||||
|
author.name, author.id, user.name, user.id
|
||||||
|
)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
await guild.unban(user)
|
await guild.unban(user)
|
||||||
except discord.HTTPException as e:
|
except discord.HTTPException as e:
|
||||||
print(e)
|
log.exception(
|
||||||
|
"{}({}) attempted to softban {}({}), but an error occurred trying to unban them.".format(
|
||||||
|
author.name, author.id, user.name, user.id
|
||||||
|
)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
log.info(
|
log.info(
|
||||||
"{}({}) softbanned {}({}), deleting 1 day worth "
|
"{}({}) softbanned {}({}), deleting 1 day worth "
|
||||||
"of messages".format(author.name, author.id, user.name, user.id)
|
"of messages.".format(author.name, author.id, user.name, user.id)
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await modlog.create_case(
|
await modlog.create_case(
|
||||||
@ -581,7 +598,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
await ctx.send(_("I am unable to kick this member from the voice channel."))
|
await ctx.send(_("I am unable to kick this member from the voice channel."))
|
||||||
return
|
return
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
await ctx.send(_("Something went wrong while attempting to kick that member"))
|
await ctx.send(_("Something went wrong while attempting to kick that member."))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
@ -623,7 +640,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
try:
|
try:
|
||||||
await guild.unban(user, reason=audit_reason)
|
await guild.unban(user, reason=audit_reason)
|
||||||
except discord.HTTPException:
|
except discord.HTTPException:
|
||||||
await ctx.send(_("Something went wrong while attempting to unban that user"))
|
await ctx.send(_("Something went wrong while attempting to unban that user."))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
@ -640,7 +657,7 @@ class KickBanMixin(MixinMeta):
|
|||||||
)
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
await ctx.send(_("Unbanned that user from this server"))
|
await ctx.send(_("Unbanned that user from this server."))
|
||||||
|
|
||||||
if await self.config.guild(guild).reinvite_on_unban():
|
if await self.config.guild(guild).reinvite_on_unban():
|
||||||
user = ctx.bot.get_user(user_id)
|
user = ctx.bot.get_user(user_id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user