Remove unused try except blocks in modlog.create_case() usage (#4095)

This commit is contained in:
jack1142 2020-08-05 20:40:52 +02:00 committed by GitHub
parent 0cc04706f6
commit 6cef336417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 199 additions and 264 deletions

View File

@ -56,21 +56,17 @@ class Events(MixinMeta):
"Failed to ban member for mention spam in server {}.".format(guild.id) "Failed to ban member for mention spam in server {}.".format(guild.id)
) )
else: else:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, message.created_at,
message.created_at, "ban",
"ban", author,
author, guild.me,
guild.me, _("Mention spam (Autoban)"),
_("Mention spam (Autoban)"), until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
print(e)
return False
return True return True
return False return False

View File

@ -116,23 +116,17 @@ class KickBanMixin(MixinMeta):
return _("An unexpected error occurred.") return _("An unexpected error occurred.")
if create_modlog_case: if create_modlog_case:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "ban",
"ban", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
return _(
"The user was banned but an error occurred when trying to "
"create the modlog entry: {reason}"
).format(reason=e)
return True return True
@ -230,20 +224,17 @@ class KickBanMixin(MixinMeta):
) )
) )
else: else:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "kick",
"kick", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("Done. That felt good.")) await ctx.send(_("Done. That felt good."))
@commands.command() @commands.command()
@ -415,20 +406,17 @@ class KickBanMixin(MixinMeta):
else: else:
banned.append(user_id) banned.append(user_id)
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "hackban",
"hackban", user_id,
user_id, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
errors["0"] = _("Failed to create modlog case: {reason}").format(reason=e)
await show_results() await show_results()
@commands.command() @commands.command()
@ -499,19 +487,16 @@ class KickBanMixin(MixinMeta):
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: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "tempban",
"tempban", user,
user, author,
author, reason,
reason, unban_time,
unban_time, )
)
except RuntimeError as 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()
@ -585,20 +570,17 @@ class KickBanMixin(MixinMeta):
"{}({}) 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: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "softban",
"softban", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("Done. Enough chaos.")) await ctx.send(_("Done. Enough chaos."))
@commands.command() @commands.command()
@ -635,20 +617,17 @@ class KickBanMixin(MixinMeta):
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: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "vkick",
"vkick", member,
member, author,
author, reason,
reason, until=None,
until=None, channel=case_channel,
channel=case_channel, )
)
except RuntimeError as e:
await ctx.send(e)
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@ -677,20 +656,17 @@ class KickBanMixin(MixinMeta):
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: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "unban",
"unban", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as 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():

View File

@ -103,20 +103,17 @@ class MuteMixin(MixinMeta):
guild = ctx.guild guild = ctx.guild
author = ctx.author author = ctx.author
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "voiceunban",
"voiceunban", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User is now allowed to speak and listen in voice channels")) await ctx.send(_("User is now allowed to speak and listen in voice channels"))
@commands.command() @commands.command()
@ -147,20 +144,17 @@ class MuteMixin(MixinMeta):
await ctx.send(_("That user is already muted and deafened server-wide!")) await ctx.send(_("That user is already muted and deafened server-wide!"))
return return
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "voiceban",
"voiceban", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User has been banned from speaking or listening in voice channels")) await ctx.send(_("User has been banned from speaking or listening in voice channels"))
@commands.group() @commands.group()
@ -190,20 +184,17 @@ class MuteMixin(MixinMeta):
success, issue = await self.mute_user(guild, channel, author, user, audit_reason) success, issue = await self.mute_user(guild, channel, author, user, audit_reason)
if success: if success:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "vmute",
"vmute", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=channel,
channel=channel, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send( await ctx.send(
_("Muted {user} in channel {channel.name}").format(user=user, channel=channel) _("Muted {user} in channel {channel.name}").format(user=user, channel=channel)
) )
@ -237,20 +228,17 @@ class MuteMixin(MixinMeta):
success, issue = await self.mute_user(guild, channel, author, user, audit_reason) success, issue = await self.mute_user(guild, channel, author, user, audit_reason)
if success: if success:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "cmute",
"cmute", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=channel,
channel=channel, )
)
except RuntimeError as e:
await ctx.send(e)
await channel.send(_("User has been muted in this channel.")) await channel.send(_("User has been muted in this channel."))
else: else:
await channel.send(issue) await channel.send(issue)
@ -270,20 +258,17 @@ class MuteMixin(MixinMeta):
success, issue = await self.mute_user(guild, channel, author, user, audit_reason) success, issue = await self.mute_user(guild, channel, author, user, audit_reason)
mute_success.append((success, issue)) mute_success.append((success, issue))
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "smute",
"smute", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User has been muted in this server.")) await ctx.send(_("User has been muted in this server."))
@commands.group() @commands.group()
@ -316,20 +301,17 @@ class MuteMixin(MixinMeta):
success, message = await self.unmute_user(guild, channel, author, user, audit_reason) success, message = await self.unmute_user(guild, channel, author, user, audit_reason)
if success: if success:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "vunmute",
"vunmute", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=channel,
channel=channel, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send( await ctx.send(
_("Unmuted {user} in channel {channel.name}").format(user=user, channel=channel) _("Unmuted {user} in channel {channel.name}").format(user=user, channel=channel)
) )
@ -363,20 +345,17 @@ class MuteMixin(MixinMeta):
success, message = await self.unmute_user(guild, channel, author, user, audit_reason) success, message = await self.unmute_user(guild, channel, author, user, audit_reason)
if success: if success:
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, guild,
guild, ctx.message.created_at,
ctx.message.created_at, "cunmute",
"cunmute", user,
user, author,
author, reason,
reason, until=None,
until=None, channel=channel,
channel=channel, )
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User unmuted in this channel.")) await ctx.send(_("User unmuted in this channel."))
else: else:
await ctx.send(_("Unmute failed. Reason: {}").format(message)) await ctx.send(_("Unmute failed. Reason: {}").format(message))
@ -398,19 +377,9 @@ class MuteMixin(MixinMeta):
success, message = await self.unmute_user(guild, channel, author, user, audit_reason) success, message = await self.unmute_user(guild, channel, author, user, audit_reason)
unmute_success.append((success, message)) unmute_success.append((success, message))
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
try: await modlog.create_case(
await modlog.create_case( self.bot, guild, ctx.message.created_at, "sunmute", user, author, reason, until=None,
self.bot, )
guild,
ctx.message.created_at,
"sunmute",
user,
author,
reason,
until=None,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User has been unmuted in this server.")) await ctx.send(_("User has been unmuted in this server."))
async def mute_user( async def mute_user(

View File

@ -480,30 +480,27 @@ class Warnings(commands.Cog):
else: else:
if not dm_failed: if not dm_failed:
await ctx.tick() await ctx.tick()
try: reason_msg = _(
reason_msg = _( "{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning."
"{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning." ).format(
).format( reason=_("{description}\nPoints: {points}").format(
reason=_("{description}\nPoints: {points}").format( description=reason_type["description"], points=reason_type["points"]
description=reason_type["description"], points=reason_type["points"] ),
), prefix=ctx.clean_prefix,
prefix=ctx.clean_prefix, user=user.id,
user=user.id, message=ctx.message.id,
message=ctx.message.id, )
) await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, ctx.guild,
ctx.guild, ctx.message.created_at,
ctx.message.created_at, "warning",
"warning", user,
user, ctx.message.author,
ctx.message.author, reason_msg,
reason_msg, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError:
pass
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@ -615,19 +612,16 @@ class Warnings(commands.Cog):
current_point_count -= user_warnings[warn_id]["points"] current_point_count -= user_warnings[warn_id]["points"]
await member_settings.total_points.set(current_point_count) await member_settings.total_points.set(current_point_count)
user_warnings.pop(warn_id) user_warnings.pop(warn_id)
try: await modlog.create_case(
await modlog.create_case( self.bot,
self.bot, ctx.guild,
ctx.guild, ctx.message.created_at,
ctx.message.created_at, "unwarned",
"unwarned", member,
member, ctx.message.author,
ctx.message.author, reason,
reason, until=None,
until=None, channel=None,
channel=None, )
)
except RuntimeError:
pass
await ctx.tick() await ctx.tick()