1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 22:23:13 +00:00

Add kick command

This commit is contained in:
wlinator 2023-08-08 06:53:06 -04:00
parent fc4392afa9
commit 3a40651a73
3 changed files with 68 additions and 0 deletions

View file

@ -1,4 +1,10 @@
{
"error_hierarchy": "❌ | **{0}** you can't perform this action because the target user is equal or higher than you in the role hierarchy.",
"error_missing_permissions": "❌ | **{0}** you are missing permissions to run this command.",
"error_mod_invoke_error": "❌ | **{0}** I couldn't perform this action, most likely because I don't have the required permissions.",
"error_bot_missing_permissions": "❌ | **{0}** I can't perform this command because I don't have the required permissions.",
"mod_kick": "\uD83D\uDC77 | **{0}** you successfully kicked **{1}**.",
"mod_kick_dm": "\uD83D\uDC77 | **{0}** you have been kicked from **{1}**.",
"ping": "\uD83C\uDFD3 | **{0}** I'm online.",
"restarting": "Restarting Racu...",
"restart_error": "Error executing the script: {0}",

View file

@ -225,6 +225,14 @@ async def on_application_command_error(ctx, error) -> None:
racu_logs.info(f"commands.CommandOnCooldown | {ctx.author.name}")
elif isinstance(error, commands.MissingPermissions):
await ctx.respond(strings["error_missing_permissions"].format(ctx.author.name), ephemeral=True)
racu_logs.info(f"commands.MissingPermissions: {ctx.command.qualified_name} | {ctx.author.name}")
elif isinstance(error, commands.BotMissingPermissions):
await ctx.respond(strings["error_bot_missing_permissions"].format(ctx.author.name), ephemeral=True)
racu_logs.info(f"commands.BotMissingPermissions: {ctx.command.qualified_name} | {ctx.author.name}")
else:
racu_logs.error(f"on_application_command_error (check debug log): {error}", exc_info=False)
racu_logs.debug(f"on_application_command_error (w/ stacktrace): {error}", exc_info=True)

54
modules/simple_mod.py Normal file
View file

@ -0,0 +1,54 @@
import logging
import discord
from discord.ext import commands
from main import strings
racu_logs = logging.getLogger('Racu.Core')
def hierarchy_check(user, target):
if target.top_role >= user.top_role:
return False
else:
return True
class SimpleModCog(commands.Cog):
def __init__(self, sbbot):
self.bot = sbbot
"""
This cog contains simple moderation commands
Fallback? Use Discord's built-ins.
"""
@commands.slash_command(
name="kick",
description="Kick a member.",
guild_only=True
)
@commands.has_permissions(kick_members=True)
@commands.bot_has_permissions(kick_members=True)
async def kick_command(self, ctx, *, target: discord.Member):
if not hierarchy_check(ctx.author, target):
return await ctx.respond(content=strings["error_hierarchy"].format(ctx.author.name), ephemeral=True)
try:
await ctx.guild.kick(user=target, reason=f"moderator: {ctx.author.name}")
await ctx.respond(strings["mod_kick"].format(ctx.author.name, target.name))
try:
await target.send(strings["mod_kick_dm"].format(target.name, ctx.guild.name))
except Exception as err:
racu_logs.info(f"error during kick command (DM): {err}")
except Exception as err:
await ctx.respond(strings["error_mod_invoke_error"].format(ctx.author.name), ephemeral=True)
racu_logs.info(f"error during kick command: {err}")
def setup(sbbot):
sbbot.add_cog(SimpleModCog(sbbot))