mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 20:23:12 +00:00
Optimize ban, kick, and slowmode commands for better performance and reliability
This commit is contained in:
parent
892296dc66
commit
a1fc9e37c6
4 changed files with 108 additions and 12 deletions
|
@ -18,6 +18,7 @@ class Ban(commands.Cog):
|
||||||
|
|
||||||
@commands.hybrid_command(name="ban")
|
@commands.hybrid_command(name="ban")
|
||||||
@commands.has_permissions(ban_members=True)
|
@commands.has_permissions(ban_members=True)
|
||||||
|
@commands.bot_has_permissions(ban_members=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def ban(
|
async def ban(
|
||||||
self,
|
self,
|
||||||
|
@ -86,6 +87,7 @@ class Ban(commands.Cog):
|
||||||
|
|
||||||
@commands.hybrid_command(name="unban")
|
@commands.hybrid_command(name="unban")
|
||||||
@commands.has_permissions(ban_members=True)
|
@commands.has_permissions(ban_members=True)
|
||||||
|
@commands.bot_has_permissions(ban_members=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def unban(
|
async def unban(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -47,10 +47,26 @@ class Cases(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.hybrid_command(name="case", aliases=["c", "ca"], description="View a specific case by number")
|
@commands.hybrid_command(name="case", aliases=["c", "ca"])
|
||||||
@commands.has_permissions(manage_messages=True)
|
@commands.has_permissions(manage_messages=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def view_case_by_number(self, ctx: commands.Context[commands.Bot], case_number: int) -> None:
|
async def view_case_by_number(
|
||||||
|
self,
|
||||||
|
ctx: commands.Context[commands.Bot],
|
||||||
|
case_number: int | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
View a specific case by number or all cases if no number is provided.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
case_number: int | None
|
||||||
|
The case number to view. If None, view all cases.
|
||||||
|
"""
|
||||||
|
if case_number is None:
|
||||||
|
await ctx.invoke(self.view_all_cases_in_guild)
|
||||||
|
return
|
||||||
|
|
||||||
guild_id = ctx.guild.id if ctx.guild else 0
|
guild_id = ctx.guild.id if ctx.guild else 0
|
||||||
case = case_service.fetch_case_by_guild_and_number(guild_id, case_number)
|
case = case_service.fetch_case_by_guild_and_number(guild_id, case_number)
|
||||||
|
|
||||||
|
@ -75,10 +91,21 @@ class Cases(commands.Cog):
|
||||||
)
|
)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.hybrid_command(name="cases", description="View all cases in the guild")
|
@commands.hybrid_command(name="cases")
|
||||||
@commands.has_permissions(manage_messages=True)
|
@commands.has_permissions(manage_messages=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def view_all_cases_in_guild(self, ctx: commands.Context[commands.Bot]) -> None:
|
async def view_all_cases_in_guild(
|
||||||
|
self,
|
||||||
|
ctx: commands.Context[commands.Bot],
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
View all cases in the guild.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
ctx: commands.Context[commands.Bot]
|
||||||
|
The context of the command.
|
||||||
|
"""
|
||||||
if not ctx.guild:
|
if not ctx.guild:
|
||||||
raise LumiException(CONST.STRINGS["error_not_in_guild"])
|
raise LumiException(CONST.STRINGS["error_not_in_guild"])
|
||||||
|
|
||||||
|
@ -107,10 +134,22 @@ class Cases(commands.Cog):
|
||||||
|
|
||||||
await menu.start()
|
await menu.start()
|
||||||
|
|
||||||
@commands.hybrid_command(name="modcases", aliases=["mc", "modc"], description="View all cases in the guild")
|
@commands.hybrid_command(name="modcases", aliases=["mc", "modc"])
|
||||||
@commands.has_permissions(manage_messages=True)
|
@commands.has_permissions(manage_messages=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def view_all_cases_by_mod(self, ctx: commands.Context[commands.Bot], moderator: discord.Member) -> None:
|
async def view_all_cases_by_mod(
|
||||||
|
self,
|
||||||
|
ctx: commands.Context[commands.Bot],
|
||||||
|
moderator: discord.Member,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
View all cases by a specific moderator.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
moderator: discord.Member
|
||||||
|
The moderator to view cases for.
|
||||||
|
"""
|
||||||
if not ctx.guild:
|
if not ctx.guild:
|
||||||
raise LumiException(CONST.STRINGS["error_not_in_guild"])
|
raise LumiException(CONST.STRINGS["error_not_in_guild"])
|
||||||
|
|
||||||
|
@ -139,10 +178,26 @@ class Cases(commands.Cog):
|
||||||
|
|
||||||
await menu.start()
|
await menu.start()
|
||||||
|
|
||||||
@commands.hybrid_command(name="editcase", aliases=["ec"], description="Edit the reason for a case")
|
@commands.hybrid_command(name="editcase", aliases=["ec"])
|
||||||
@commands.has_permissions(manage_messages=True)
|
@commands.has_permissions(manage_messages=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def edit_case_reason(self, ctx: commands.Context[commands.Bot], case_number: int, *, new_reason: str):
|
async def edit_case_reason(
|
||||||
|
self,
|
||||||
|
ctx: commands.Context[commands.Bot],
|
||||||
|
case_number: int,
|
||||||
|
*,
|
||||||
|
new_reason: str,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Edit the reason for a specific case.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
case_number: int
|
||||||
|
The case number to edit.
|
||||||
|
new_reason: str
|
||||||
|
The new reason for the case.
|
||||||
|
"""
|
||||||
if not ctx.guild:
|
if not ctx.guild:
|
||||||
raise LumiException(CONST.STRINGS["error_not_in_guild"])
|
raise LumiException(CONST.STRINGS["error_not_in_guild"])
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,27 @@ class Kick(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.hybrid_command(name="kick", description="Kick a user")
|
@commands.hybrid_command(name="kick", aliases=["k"])
|
||||||
@commands.has_permissions(kick_members=True)
|
@commands.has_permissions(kick_members=True)
|
||||||
|
@commands.bot_has_permissions(kick_members=True)
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def kick(self, ctx: commands.Context[commands.Bot], target: discord.Member, *, reason: str | None = None):
|
async def kick(
|
||||||
|
self,
|
||||||
|
ctx: commands.Context[commands.Bot],
|
||||||
|
target: discord.Member,
|
||||||
|
*,
|
||||||
|
reason: str | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Kick a user from the guild.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
target: discord.Member
|
||||||
|
The user to kick.
|
||||||
|
reason: str | None
|
||||||
|
The reason for the kick. Defaults to None.
|
||||||
|
"""
|
||||||
assert ctx.guild
|
assert ctx.guild
|
||||||
assert ctx.author
|
assert ctx.author
|
||||||
assert ctx.bot.user
|
assert ctx.bot.user
|
||||||
|
|
|
@ -56,15 +56,26 @@ class Slowmode(commands.Cog):
|
||||||
@commands.command(
|
@commands.command(
|
||||||
name="slowmode",
|
name="slowmode",
|
||||||
aliases=["sm"],
|
aliases=["sm"],
|
||||||
usage="slowmode <duration> <channel>",
|
|
||||||
)
|
)
|
||||||
@commands.has_permissions(manage_channels=True)
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
@commands.bot_has_permissions(manage_channels=True)
|
||||||
|
@commands.guild_only()
|
||||||
async def slowmode(
|
async def slowmode(
|
||||||
self,
|
self,
|
||||||
ctx: commands.Context[commands.Bot],
|
ctx: commands.Context[commands.Bot],
|
||||||
arg1: str | None = None,
|
arg1: str | None = None,
|
||||||
arg2: str | None = None,
|
arg2: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""
|
||||||
|
Set or view the slowmode for a channel.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
arg1: str | None
|
||||||
|
The first argument. Defaults to None.
|
||||||
|
arg2: str | None
|
||||||
|
The second argument. Defaults to None.
|
||||||
|
"""
|
||||||
channel, duration = None, None
|
channel, duration = None, None
|
||||||
|
|
||||||
for arg in (arg1, arg2):
|
for arg in (arg1, arg2):
|
||||||
|
@ -83,15 +94,26 @@ class Slowmode(commands.Cog):
|
||||||
|
|
||||||
@app_commands.command(
|
@app_commands.command(
|
||||||
name="slowmode",
|
name="slowmode",
|
||||||
description="Set or view the slowmode for a channel",
|
|
||||||
)
|
)
|
||||||
@app_commands.checks.has_permissions(manage_channels=True)
|
@app_commands.checks.has_permissions(manage_channels=True)
|
||||||
|
@app_commands.checks.bot_has_permissions(manage_channels=True)
|
||||||
|
@app_commands.guild_only()
|
||||||
async def slowmode_slash(
|
async def slowmode_slash(
|
||||||
self,
|
self,
|
||||||
interaction: discord.Interaction,
|
interaction: discord.Interaction,
|
||||||
channel: discord.TextChannel,
|
channel: discord.TextChannel,
|
||||||
duration: str | None = None,
|
duration: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
"""
|
||||||
|
Set or view the slowmode for a channel.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
channel: discord.TextChannel
|
||||||
|
The channel to set the slowmode for.
|
||||||
|
duration: str | None
|
||||||
|
The duration of the slowmode. Defaults to None.
|
||||||
|
"""
|
||||||
await self._set_slowmode(interaction, channel, duration)
|
await self._set_slowmode(interaction, channel, duration)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue