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,7 +56,6 @@ class Events(MixinMeta):
"Failed to ban member for mention spam in server {}.".format(guild.id)
)
else:
try:
await modlog.create_case(
self.bot,
guild,
@ -68,9 +67,6 @@ class Events(MixinMeta):
until=None,
channel=None,
)
except RuntimeError as e:
print(e)
return False
return True
return False

View File

@ -116,7 +116,6 @@ class KickBanMixin(MixinMeta):
return _("An unexpected error occurred.")
if create_modlog_case:
try:
await modlog.create_case(
self.bot,
guild,
@ -128,11 +127,6 @@ class KickBanMixin(MixinMeta):
until=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
@ -230,7 +224,6 @@ class KickBanMixin(MixinMeta):
)
)
else:
try:
await modlog.create_case(
self.bot,
guild,
@ -242,8 +235,6 @@ class KickBanMixin(MixinMeta):
until=None,
channel=None,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("Done. That felt good."))
@commands.command()
@ -415,7 +406,6 @@ class KickBanMixin(MixinMeta):
else:
banned.append(user_id)
try:
await modlog.create_case(
self.bot,
guild,
@ -427,8 +417,6 @@ class KickBanMixin(MixinMeta):
until=None,
channel=None,
)
except RuntimeError as e:
errors["0"] = _("Failed to create modlog case: {reason}").format(reason=e)
await show_results()
@commands.command()
@ -499,7 +487,6 @@ class KickBanMixin(MixinMeta):
except discord.HTTPException:
await ctx.send(_("Something went wrong while banning."))
else:
try:
await modlog.create_case(
self.bot,
guild,
@ -510,8 +497,6 @@ class KickBanMixin(MixinMeta):
reason,
unban_time,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("Done. Enough chaos for now."))
@commands.command()
@ -585,7 +570,6 @@ class KickBanMixin(MixinMeta):
"{}({}) softbanned {}({}), deleting 1 day worth "
"of messages.".format(author.name, author.id, user.name, user.id)
)
try:
await modlog.create_case(
self.bot,
guild,
@ -597,8 +581,6 @@ class KickBanMixin(MixinMeta):
until=None,
channel=None,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("Done. Enough chaos."))
@commands.command()
@ -635,7 +617,6 @@ class KickBanMixin(MixinMeta):
await ctx.send(_("Something went wrong while attempting to kick that member."))
return
else:
try:
await modlog.create_case(
self.bot,
guild,
@ -647,8 +628,6 @@ class KickBanMixin(MixinMeta):
until=None,
channel=case_channel,
)
except RuntimeError as e:
await ctx.send(e)
@commands.command()
@commands.guild_only()
@ -677,7 +656,6 @@ class KickBanMixin(MixinMeta):
await ctx.send(_("Something went wrong while attempting to unban that user."))
return
else:
try:
await modlog.create_case(
self.bot,
guild,
@ -689,8 +667,6 @@ class KickBanMixin(MixinMeta):
until=None,
channel=None,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("Unbanned that user from this server."))
if await self.config.guild(guild).reinvite_on_unban():

View File

@ -103,7 +103,6 @@ class MuteMixin(MixinMeta):
guild = ctx.guild
author = ctx.author
try:
await modlog.create_case(
self.bot,
guild,
@ -115,8 +114,6 @@ class MuteMixin(MixinMeta):
until=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"))
@commands.command()
@ -147,7 +144,6 @@ class MuteMixin(MixinMeta):
await ctx.send(_("That user is already muted and deafened server-wide!"))
return
try:
await modlog.create_case(
self.bot,
guild,
@ -159,8 +155,6 @@ class MuteMixin(MixinMeta):
until=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"))
@commands.group()
@ -190,7 +184,6 @@ class MuteMixin(MixinMeta):
success, issue = await self.mute_user(guild, channel, author, user, audit_reason)
if success:
try:
await modlog.create_case(
self.bot,
guild,
@ -202,8 +195,6 @@ class MuteMixin(MixinMeta):
until=None,
channel=channel,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(
_("Muted {user} in channel {channel.name}").format(user=user, channel=channel)
)
@ -237,7 +228,6 @@ class MuteMixin(MixinMeta):
success, issue = await self.mute_user(guild, channel, author, user, audit_reason)
if success:
try:
await modlog.create_case(
self.bot,
guild,
@ -249,8 +239,6 @@ class MuteMixin(MixinMeta):
until=None,
channel=channel,
)
except RuntimeError as e:
await ctx.send(e)
await channel.send(_("User has been muted in this channel."))
else:
await channel.send(issue)
@ -270,7 +258,6 @@ class MuteMixin(MixinMeta):
success, issue = await self.mute_user(guild, channel, author, user, audit_reason)
mute_success.append((success, issue))
await asyncio.sleep(0.1)
try:
await modlog.create_case(
self.bot,
guild,
@ -282,8 +269,6 @@ class MuteMixin(MixinMeta):
until=None,
channel=None,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User has been muted in this server."))
@commands.group()
@ -316,7 +301,6 @@ class MuteMixin(MixinMeta):
success, message = await self.unmute_user(guild, channel, author, user, audit_reason)
if success:
try:
await modlog.create_case(
self.bot,
guild,
@ -328,8 +312,6 @@ class MuteMixin(MixinMeta):
until=None,
channel=channel,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(
_("Unmuted {user} in channel {channel.name}").format(user=user, channel=channel)
)
@ -363,7 +345,6 @@ class MuteMixin(MixinMeta):
success, message = await self.unmute_user(guild, channel, author, user, audit_reason)
if success:
try:
await modlog.create_case(
self.bot,
guild,
@ -375,8 +356,6 @@ class MuteMixin(MixinMeta):
until=None,
channel=channel,
)
except RuntimeError as e:
await ctx.send(e)
await ctx.send(_("User unmuted in this channel."))
else:
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)
unmute_success.append((success, message))
await asyncio.sleep(0.1)
try:
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."))
async def mute_user(

View File

@ -480,7 +480,6 @@ class Warnings(commands.Cog):
else:
if not dm_failed:
await ctx.tick()
try:
reason_msg = _(
"{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning."
).format(
@ -502,8 +501,6 @@ class Warnings(commands.Cog):
until=None,
channel=None,
)
except RuntimeError:
pass
@commands.command()
@commands.guild_only()
@ -615,7 +612,6 @@ class Warnings(commands.Cog):
current_point_count -= user_warnings[warn_id]["points"]
await member_settings.total_points.set(current_point_count)
user_warnings.pop(warn_id)
try:
await modlog.create_case(
self.bot,
ctx.guild,
@ -627,7 +623,5 @@ class Warnings(commands.Cog):
until=None,
channel=None,
)
except RuntimeError:
pass
await ctx.tick()