Untitled

mail@pastecode.io avatar
unknown
kotlin
a month ago
2.9 kB
2
Indexable
Never
class PunishCommand(
    val name: String,
    permission: Permission,
    val action: (User, List<OptionMapping>) -> Unit,
    vararg additionalOptions: OptionData,
    val reason: Boolean = false
) : SlashCommand(name, "$name Someone", true) {
    override val options = listOf(
        OptionData(OptionType.USER, "member", "The Member You Want To Punish", true),
        *additionalOptions
    ).apply { if (reason) plus(OptionData(OptionType.STRING, "reason", "The Reason The Member Is Punished", true)) }
    override val requiredPermissions = setOf(permission)
    override fun onCommand(event: SlashCommandInteractionEvent) {
        val mention = event.getOption("member")!!.asUser
        val eb = EmbedBuilder().apply {
            setAuthor(event.member!!.effectiveName, null, event.member!!.effectiveAvatarUrl)
        }
        if ((event.guild!!.getMember(mention)?.roles?.firstOrNull()?.position ?: -1) < event.member!!.roles[0].position) {
            eb.setTitle("$name: ${mention.effectiveName}")
            if (reason)
                eb.setDescription(event.getOption("reason")!!.asString)
            eb.setColor(Color.decode("#4ab567"))
            event.replyEmbeds(eb.build()).queue {
                action(mention, event.options)
            }
        } else {
            eb.setTitle("Command Failed")
            eb.setDescription("You Can't $name Someone Higher Than You")
            eb.setColor(Color.decode("#cf0e0e"))
            event.replyEmbeds(eb.build()).setEphemeral(true).queue()
        }
    }
}

//Main.kt
commandManager.addCommands(
    PunishCommand("Ban", Permission.BAN_MEMBERS, { member, _ -> guild.ban(member,0, TimeUnit.DAYS).queue() }),
    PunishCommand("Kick", Permission.KICK_MEMBERS, { member, _ -> guild.kick(member).queue() }),
    PunishCommand(
        "Mute",
        Permission.MODERATE_MEMBERS,
        { member, optionsData ->
            guild.timeoutFor(member,
                parseSeconds(optionsData.first { it.name == "time" }.asString),
                TimeUnit.SECONDS
            ).queue()
        },
        OptionData(
        OptionType.STRING,
        "time",
        "For How Much Time Is The Member Muted Syntax:11d 2h 3m 4s (11 days 2 hours 3 minutes and 4 seconds)",
        true
        )
    ),
    PunishCommand("Unban", Permission.BAN_MEMBERS, { member, _ -> guild.unban(member).queue() }, reason = false),
    PunishCommand("Unmute", Permission.MODERATE_MEMBERS, { member, _ -> guild.removeTimeout(member).queue() }, reason = false),
    PunishCommand(
        "Warn",
        Permission.MODERATE_MEMBERS,
        { member, optionsData ->
            WarnData.addWarn(
                member.id,
                optionsData.first { it.name == "time" }.asString,
                member.asMention
            )
    })
)
Leave a Comment