mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
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
This commit is contained in:
parent
6984dca394
commit
dbcb179523
@ -29,6 +29,7 @@ class Warnings(commands.Cog):
|
|||||||
"reasons": {},
|
"reasons": {},
|
||||||
"allow_custom_reasons": False,
|
"allow_custom_reasons": False,
|
||||||
"toggle_dm": True,
|
"toggle_dm": True,
|
||||||
|
"show_mod": False,
|
||||||
"warn_channel": None,
|
"warn_channel": None,
|
||||||
"toggle_channel": False,
|
"toggle_channel": False,
|
||||||
}
|
}
|
||||||
@ -95,6 +96,24 @@ class Warnings(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
await ctx.send(_("Warnings will no longer be sent to users DMs."))
|
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()
|
@warningset.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def warnchannel(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
async def warnchannel(self, ctx: commands.Context, channel: discord.TextChannel = None):
|
||||||
@ -326,10 +345,11 @@ class Warnings(commands.Cog):
|
|||||||
if user.bot:
|
if user.bot:
|
||||||
await ctx.send(_("You cannot warn other bots."))
|
await ctx.send(_("You cannot warn other bots."))
|
||||||
return
|
return
|
||||||
custom_allowed = await self.config.guild(ctx.guild).allow_custom_reasons()
|
guild_settings = await self.config.guild(ctx.guild).all()
|
||||||
guild_settings = self.config.guild(ctx.guild)
|
custom_allowed = guild_settings["allow_custom_reasons"]
|
||||||
|
|
||||||
reason_type = None
|
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:
|
if reason.lower() not in registered_reasons:
|
||||||
msg = _("That is not a registered reason!")
|
msg = _("That is not a registered reason!")
|
||||||
if custom_allowed:
|
if custom_allowed:
|
||||||
@ -363,13 +383,15 @@ class Warnings(commands.Cog):
|
|||||||
await member_settings.total_points.set(current_point_count)
|
await member_settings.total_points.set(current_point_count)
|
||||||
|
|
||||||
await warning_points_add_check(self.config, ctx, user, 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
|
dm_failed = False
|
||||||
if dm:
|
if dm:
|
||||||
em = discord.Embed(
|
if showmod:
|
||||||
title=_("Warning from {user}").format(user=ctx.author),
|
title = _("Warning from {user}").format(user=ctx.author)
|
||||||
description=reason_type["description"],
|
else:
|
||||||
)
|
title = _("Warning")
|
||||||
|
em = discord.Embed(title=title, description=reason_type["description"],)
|
||||||
em.add_field(name=_("Points"), value=str(reason_type["points"]))
|
em.add_field(name=_("Points"), value=str(reason_type["points"]))
|
||||||
try:
|
try:
|
||||||
await user.send(
|
await user.send(
|
||||||
@ -389,18 +411,19 @@ class Warnings(commands.Cog):
|
|||||||
).format(user=user.mention)
|
).format(user=user.mention)
|
||||||
)
|
)
|
||||||
|
|
||||||
toggle_channel = await self.config.guild(guild).toggle_channel()
|
toggle_channel = guild_settings["toggle_channel"]
|
||||||
if toggle_channel:
|
if toggle_channel:
|
||||||
em = discord.Embed(
|
if showmod:
|
||||||
title=_("Warning from {user}").format(user=ctx.author),
|
title = _("Warning from {user}").format(user=ctx.author)
|
||||||
description=reason_type["description"],
|
else:
|
||||||
)
|
title = _("Warning")
|
||||||
|
em = discord.Embed(title=title, description=reason_type["description"],)
|
||||||
em.add_field(name=_("Points"), value=str(reason_type["points"]))
|
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 warn_channel:
|
||||||
if channel.permissions_for(guild.me).send_messages:
|
if warn_channel.permissions_for(guild.me).send_messages:
|
||||||
with contextlib.suppress(discord.HTTPException):
|
with contextlib.suppress(discord.HTTPException):
|
||||||
await channel.send(
|
await warn_channel.send(
|
||||||
_("{user} has been warned.").format(user=user.mention), embed=em,
|
_("{user} has been warned.").format(user=user.mention), embed=em,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user