From dbcb179523b3941f7a6ea27de7903a5be4274e1f Mon Sep 17 00:00:00 2001 From: Dav Date: Mon, 1 Jun 2020 00:58:36 +0000 Subject: [PATCH] Allow to hide moderator from warnings sent to the users + warn channel fix (#3781) * add toggle to allow switching off sending the name of the person who uhhh used? the warning * the Kowlin way of life * reduced config calls to stay in line with #3766 and hopefully didn't break anything (as per Draper suggestion) * more performance magic * found an error + black * forgot warning channel existed * await... seriously... how long have you done async stuff now dav? * unify (most) config calls in ``[p]warn`` * fix all the things --- redbot/cogs/warnings/warnings.py | 55 ++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/redbot/cogs/warnings/warnings.py b/redbot/cogs/warnings/warnings.py index a71615779..68aaeb660 100644 --- a/redbot/cogs/warnings/warnings.py +++ b/redbot/cogs/warnings/warnings.py @@ -29,6 +29,7 @@ class Warnings(commands.Cog): "reasons": {}, "allow_custom_reasons": False, "toggle_dm": True, + "show_mod": False, "warn_channel": None, "toggle_channel": False, } @@ -95,6 +96,24 @@ class Warnings(commands.Cog): else: await ctx.send(_("Warnings will no longer be sent to users DMs.")) + @warningset.command() + @commands.guild_only() + async def showmoderator(self, ctx, true_or_false: bool): + """Decide whether the name of the moderator warning a user should be included in the DM to that user.""" + await self.config.guild(ctx.guild).show_mod.set(true_or_false) + if true_or_false: + await ctx.send( + _( + "I will include the name of the moderator who issued the warning when sending a DM to a user." + ) + ) + else: + await ctx.send( + _( + "I will not include the name of the moderator who issued the warning when sending a DM to a user." + ) + ) + @warningset.command() @commands.guild_only() async def warnchannel(self, ctx: commands.Context, channel: discord.TextChannel = None): @@ -326,10 +345,11 @@ class Warnings(commands.Cog): if user.bot: await ctx.send(_("You cannot warn other bots.")) return - custom_allowed = await self.config.guild(ctx.guild).allow_custom_reasons() - guild_settings = self.config.guild(ctx.guild) + guild_settings = await self.config.guild(ctx.guild).all() + custom_allowed = guild_settings["allow_custom_reasons"] + reason_type = None - async with guild_settings.reasons() as registered_reasons: + async with self.config.guild(ctx.guild).reasons() as registered_reasons: if reason.lower() not in registered_reasons: msg = _("That is not a registered reason!") if custom_allowed: @@ -363,13 +383,15 @@ class Warnings(commands.Cog): await member_settings.total_points.set(current_point_count) await warning_points_add_check(self.config, ctx, user, current_point_count) - dm = await self.config.guild(ctx.guild).toggle_dm() + dm = guild_settings["toggle_dm"] + showmod = guild_settings["show_mod"] dm_failed = False if dm: - em = discord.Embed( - title=_("Warning from {user}").format(user=ctx.author), - description=reason_type["description"], - ) + if showmod: + title = _("Warning from {user}").format(user=ctx.author) + else: + title = _("Warning") + em = discord.Embed(title=title, description=reason_type["description"],) em.add_field(name=_("Points"), value=str(reason_type["points"])) try: await user.send( @@ -389,18 +411,19 @@ class Warnings(commands.Cog): ).format(user=user.mention) ) - toggle_channel = await self.config.guild(guild).toggle_channel() + toggle_channel = guild_settings["toggle_channel"] if toggle_channel: - em = discord.Embed( - title=_("Warning from {user}").format(user=ctx.author), - description=reason_type["description"], - ) + if showmod: + title = _("Warning from {user}").format(user=ctx.author) + else: + title = _("Warning") + em = discord.Embed(title=title, description=reason_type["description"],) em.add_field(name=_("Points"), value=str(reason_type["points"])) - warn_channel = self.bot.get_channel(await self.config.guild(guild).warn_channel()) + warn_channel = self.bot.get_channel(guild_settings["warn_channel"]) if warn_channel: - if channel.permissions_for(guild.me).send_messages: + if warn_channel.permissions_for(guild.me).send_messages: with contextlib.suppress(discord.HTTPException): - await channel.send( + await warn_channel.send( _("{user} has been warned.").format(user=user.mention), embed=em, )