Make few adjustments to [p]mywarnings and its docs (#6673)

This commit is contained in:
Jakub Kuczys
2026-03-04 21:57:52 +01:00
committed by GitHub
parent afe4e636b7
commit 1bfe2a78fa
2 changed files with 44 additions and 42 deletions

View File

@@ -347,7 +347,7 @@ warningset mywarnings sendtodms
.. code-block:: none .. code-block:: none
[p]warningset mywarnings_sendtodms <true_or_false> [p]warningset mywarnings sendtodms <true_or_false>
**Description** **Description**

View File

@@ -648,52 +648,54 @@ class Warnings(commands.Cog):
msg = "" msg = ""
guild_settings = await self.config.guild(ctx.guild).all() guild_settings = await self.config.guild(ctx.guild).all()
member_settings = self.config.member(user) member_settings = self.config.member(user)
async with member_settings.warnings() as user_warnings: user_warnings = await member_settings.warnings()
if not user_warnings.keys(): # no warnings for the user if not user_warnings: # no warnings for the user
if guild_settings["mywarnings_in_dms"]: if guild_settings["mywarnings_in_dms"]:
await ctx.tick() try:
await user.send(_("You have no warnings!")) await user.send(_("You have no warnings!"))
except discord.Forbidden:
await ctx.send(_("I could not send you a DM. Do you have DMs disabled?"))
else: else:
await ctx.send(_("You have no warnings!")) await ctx.tick()
else: else:
for key in user_warnings.keys(): await ctx.send(_("You have no warnings!"))
mod_id = user_warnings[key]["mod"] return
if mod_id == 0xDE1:
mod = _("Deleted Moderator")
elif not guild_settings["show_mod"]:
mod = None
else:
bot = ctx.bot
mod = bot.get_user(mod_id) or _("Unknown Moderator ({})").format(mod_id)
msg += _("{num_points} point warning {reason_name}").format(
num_points=user_warnings[key]["points"],
reason_name=key,
)
if mod is not None:
msg += _(" issued by {user}").format(user=mod)
msg += _(" for {description} \n").format(
description=user_warnings[key]["description"]
)
if guild_settings["mywarnings_in_dms"]: for key in user_warnings:
if user.dm_channel is None: mod_id = user_warnings[key]["mod"]
await user.create_dm() if mod_id == 0xDE1:
try: mod = _("Deleted Moderator")
await ctx.bot.send_interactive( elif not guild_settings["show_mod"]:
channel=user.dm_channel, mod = None
messages=pagify(msg, shorten_by=58), else:
user=user, bot = ctx.bot
box_lang=_("Warnings for {user}").format(user=user), mod = bot.get_user(mod_id) or _("Unknown Moderator ({})").format(mod_id)
) msg += _("{num_points} point warning {reason_name}").format(
await ctx.tick() num_points=user_warnings[key]["points"],
except discord.Forbidden: reason_name=key,
await ctx.send(_("I could not send you a DM. Do you have DMs disabled?")) )
if mod is not None:
msg += _(" issued by {user}").format(user=mod)
msg += _(" for {description}\n").format(description=user_warnings[key]["description"])
else: if guild_settings["mywarnings_in_dms"]:
await ctx.send_interactive( try:
pagify(msg, shorten_by=58), await ctx.bot.send_interactive(
box_lang=_("Warnings for {user}").format(user=user), channel=user,
) messages=pagify(msg, shorten_by=58),
user=user,
box_lang=_("Warnings for {user}").format(user=user),
)
except discord.Forbidden:
await ctx.send(_("I could not send you a DM. Do you have DMs disabled?"))
else:
await ctx.tick()
else:
await ctx.send_interactive(
pagify(msg, shorten_by=58),
box_lang=_("Warnings for {user}").format(user=user),
)
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()