fix(shard): 🐛 Update cache in new mod commands.

This commit is contained in:
2025-04-02 01:07:17 -03:00
parent 4e12539ae7
commit fad0e41198
+25 -6
View File
@@ -29,7 +29,7 @@ class Admin(base.Cog):
@commands.command(aliases=["mod"])
@commands.is_owner()
async def moderator(
self, ctx: commands.Context, user: discord.User, toggle: bool = True
self, ctx: commands.Context, user: discord.User, toggle: bool | None = None
) -> None:
"""Gives the user the Moderator role.
@@ -41,13 +41,17 @@ class Admin(base.Cog):
- Bot Owner
"""
instance, _ = await models.User.update_or_create(
id=user.id, defaults={"is_moderator": toggle}
)
await instance.set_cache(self.bot.redis)
user: models.User = await models.User.get_or_none(id=user.id)
if user is None:
return await ctx.send("❌ User not found.")
user.is_moderator = toggle if toggle is not None else not user.is_moderator
await user.save()
await user.set_cache(self.bot.redis)
await ctx.send(
f"Toggled the moderator role {'on' if toggle else 'off'} for {user.mention}."
f"✅ Toggled the moderator role {'on' if user.is_moderator else 'off'} for {user.mention}."
)
@commands.command(aliases=["b"])
@@ -359,6 +363,11 @@ class Admin(base.Cog):
await warn.delete()
user: models.User = await models.User.get_or_none(id=warn.user_id)
if user:
await user.set_cache(self.bot.redis)
await ctx.send(
f"✅ Deleted warning `#{warn.id}` for user <@{warn.user_id}>.",
allowed_mentions=discord.AllowedMentions(users=False),
@@ -387,6 +396,11 @@ class Admin(base.Cog):
await ban.delete()
user: models.User = await models.User.get_or_none(id=ban.user_id)
if user:
await user.set_cache(self.bot.redis)
if (
not await models.Ban.filter(
expressions.Q(
@@ -426,6 +440,11 @@ class Admin(base.Cog):
await self.bot.unban(user_id, ctx.author.id, False)
user: models.User = await models.User.get_or_none(id=user_id)
if user:
await user.set_cache(self.bot.redis)
await ctx.send(
f"✅ Cleared the record of <@{user_id}>.",
allowed_mentions=discord.AllowedMentions(users=False),