Skip to content

Commit

Permalink
refactor: migrate predefined reasons slash command back to JDA
Browse files Browse the repository at this point in the history
  • Loading branch information
SrGaabriel committed Sep 21, 2024
1 parent 6e62bb0 commit dc3ff47
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.`fun`.dec
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.moderation.declarations.BanCommand
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.moderation.declarations.PredefinedReasonsCommand
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.social.declarations.AchievementsCommand
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.social.declarations.GenderCommand
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.utils.declarations.*
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.videos.declarations.FansExplainingCommand
import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.videos.declarations.GigaChadCommand
Expand All @@ -30,7 +29,7 @@ class PublicLorittaCommands(val languageManager: LanguageManager) {

// ===[ MODERATION ]===
register(BanCommand(languageManager))
register(PredefinedReasonsCommand(languageManager))
// register(PredefinedReasonsCommand(languageManager))

// ===[ FUN ]===
register(TextTransformCommand(languageManager))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import net.perfectdreams.loritta.morenitta.interactions.vanilla.minecraft.Minecr
import net.perfectdreams.loritta.morenitta.interactions.vanilla.misc.LanguageCommand
import net.perfectdreams.loritta.morenitta.interactions.vanilla.moderation.BanInfoCommand
import net.perfectdreams.loritta.morenitta.interactions.vanilla.moderation.DashboardCommand
import net.perfectdreams.loritta.morenitta.interactions.vanilla.moderation.PredefinedReasonsCommand
import net.perfectdreams.loritta.morenitta.interactions.vanilla.roleplay.RoleplayCommand
import net.perfectdreams.loritta.morenitta.interactions.vanilla.social.AfkCommand
import net.perfectdreams.loritta.morenitta.interactions.vanilla.social.GenderCommand
Expand Down Expand Up @@ -274,6 +275,7 @@ class UnleashedCommandManager(val loritta: LorittaBot, val languageManager: Lang
// ===[ MODERATION ]===
register(BanInfoCommand(loritta))
register(DashboardCommand(loritta))
register(PredefinedReasonsCommand())

// ===[ FUN ]===
register(EventCommand(loritta))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package net.perfectdreams.loritta.morenitta.interactions.vanilla.moderation

import net.dv8tion.jda.api.Permission
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions
import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled
import net.perfectdreams.loritta.cinnamon.emotes.Emotes
import net.perfectdreams.loritta.cinnamon.pudding.tables.servers.moduleconfigs.ModerationPredefinedPunishmentMessages
import net.perfectdreams.loritta.common.commands.CommandCategory
import net.perfectdreams.loritta.i18n.I18nKeysData
import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.interactions.UnleashedContext
import net.perfectdreams.loritta.morenitta.interactions.commands.LegacyMessageCommandContext
import net.perfectdreams.loritta.morenitta.interactions.commands.LorittaLegacyMessageCommandExecutor
import net.perfectdreams.loritta.morenitta.interactions.commands.LorittaSlashCommandExecutor
import net.perfectdreams.loritta.morenitta.interactions.commands.SlashCommandArguments
import net.perfectdreams.loritta.morenitta.interactions.commands.SlashCommandDeclarationBuilder
import net.perfectdreams.loritta.morenitta.interactions.commands.SlashCommandDeclarationWrapper
import net.perfectdreams.loritta.morenitta.interactions.commands.options.OptionReference
import net.perfectdreams.loritta.morenitta.interactions.commands.slashCommand
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import java.util.UUID

class PredefinedReasonsCommand: SlashCommandDeclarationWrapper {
override fun command(): SlashCommandDeclarationBuilder =
slashCommand(
name = I18N_PREFIX.Label,
description = I18N_PREFIX.Label,
category = CommandCategory.MODERATION,
uniqueId = UUID.fromString("e126bb95-1bbd-4117-bd42-db467276ece4")
) {
isGuildOnly = true
defaultMemberPermissions = DefaultMemberPermissions.enabledFor(Permission.BAN_MEMBERS)
executor = PredefinedReasonsExecutor()
}

class PredefinedReasonsExecutor: LorittaSlashCommandExecutor(), LorittaLegacyMessageCommandExecutor {
override suspend fun execute(
context: UnleashedContext,
args: SlashCommandArguments
) {
context.deferChannelMessage(ephemeral = true)

// TODO: Allow further customization of predefined reasons
val predefinedReasons = DefaultPredefinedPunishmentMessages

registerPredefinedReasons(
context.loritta,
context.guild.idLong,
predefinedReasons
)

context.reply(ephemeral = true) {
styled(
"Motivos de punições pré-definidos foram criados com sucesso! Você agora pode usar eles no ${context.loritta.commandMentions.ban} na opção de `predefined_reason`!",
Emotes.LoriHi
)
styled(
"No futuro, quando o MrPowerGamerBR parar de ser preguiçoso, motivos de punições pré-definidos poderão ser customizados pelo meu painel!",
Emotes.LoriLick
)
}
}

private suspend fun registerPredefinedReasons(
loritta: LorittaBot,
guildId: Long,
reasons: Collection<PredefinedPunishmentMessage>
) {
loritta.pudding.transaction {
ModerationPredefinedPunishmentMessages.deleteWhere {
guild eq guildId
}

for (reason in reasons) {
ModerationPredefinedPunishmentMessages.insert {
it[guild] = guildId
it[short] = reason.shortened
it[message] = reason.message
}
}
}
}

override suspend fun convertToInteractionsArguments(
context: LegacyMessageCommandContext,
args: List<String>
): Map<OptionReference<*>, Any?>? = emptyMap()
}

companion object {
val I18N_PREFIX = I18nKeysData.Commands.Command.Predefinedreasons

data class PredefinedPunishmentMessage(
val shortened: String,
val message: String
)

val DefaultPredefinedPunishmentMessages = listOf(
PredefinedPunishmentMessage(
shortened = "divdm",
message = "Enviar conteúdo (não solicitado!) via mensagem direta, fazer spam (ou seja, mandar conteúdo indesejado para outras pessoas) é contra as regras do servidor da Loritta e dos termos de uso do Discord e, caso continuar, você poderá ser suspenso do Discord e irá perder a sua conta!"
),
PredefinedPunishmentMessage(
shortened = "div",
message = "Não é permitido divulgar conteúdos em canais de texto sem que a equipe permita."
),
PredefinedPunishmentMessage(
shortened = "spam",
message = "Floodar/spammar (Enviar várias mensagens repetidas, enviar uma mensagem com caracteres aletórios, adicionar reações aleatórias, etc) nos canais de texto."
),
PredefinedPunishmentMessage(
shortened = "nsfw",
message = "É proibido compartilhar conteúdo NSFW (coisas obscenas como pornografia, gore e coisas relacionadas), conteúdo sugestivo, jumpscares, conteúdo de ódio, racismo, assédio, links com conteúdo ilegal e links falsos. Será punido até se passar via mensagem direta, até mesmo se a outra pessoa pedir."
),
PredefinedPunishmentMessage(
shortened = "toxic",
message = "Ser tóxico (irritar e desrespeitar) com outros membros do servidor. Aprenda a respeitar e conviver com outras pessoas!"
),
PredefinedPunishmentMessage(
shortened = "under13",
message = "É proibido ter uma conta de Discord caso você tenha menos de 13 anos!"
),
PredefinedPunishmentMessage(
shortened = "bob",
message = "Imagine fazer spam dizendo que não é para fazer spam."
),
PredefinedPunishmentMessage(
shortened = "selfbot",
message = "Não é permitido o uso de selfbot no nosso servidor, caso continue, a conta poderá ser suspensa da plataforma e inutilizada."
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.perfectdreams.loritta.morenitta.interactions.vanilla.social
import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled
import net.perfectdreams.loritta.cinnamon.emotes.Emotes
import net.perfectdreams.loritta.common.commands.CommandCategory
import net.perfectdreams.loritta.common.utils.TodoFixThisData
import net.perfectdreams.loritta.common.utils.text.TextUtils.shortenAndStripCodeBackticks
import net.perfectdreams.loritta.common.utils.text.TextUtils.stripNewLines
import net.perfectdreams.loritta.i18n.I18nKeysData
Expand All @@ -23,7 +24,7 @@ class AfkCommand: SlashCommandDeclarationWrapper {
override fun command(): SlashCommandDeclarationBuilder =
slashCommand(
name = I18N_PREFIX.Label,
description = I18N_PREFIX.Label,
description = TodoFixThisData,
category = CommandCategory.SOCIAL,
uniqueId = UUID.fromString("bcf80930-44b9-4a60-814e-0a9549e939ed")
) {
Expand Down Expand Up @@ -91,7 +92,7 @@ class AfkCommand: SlashCommandDeclarationWrapper {
): Map<OptionReference<*>, Any?>? = emptyMap()
}

companion object {
private companion object {
private val I18N_PREFIX = I18nKeysData.Commands.Command.Afk
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class GenderCommand: SlashCommandDeclarationWrapper {
context: UnleashedContext,
args: SlashCommandArguments
) {
if (context is LegacyMessageCommandContext) {
context.reply(ephemeral = true, "This command can only be used as a slash command!")
return
}

val userSettings = context.loritta.pudding.users.getOrCreateUserProfile(UserId(context.user.idLong))
.getProfileSettings()

Expand All @@ -64,12 +69,15 @@ class GenderCommand: SlashCommandDeclarationWrapper {
context: LegacyMessageCommandContext,
args: List<String>
): Map<OptionReference<*>, Any?>? {
val choice = args.singleOrNull() ?: return null
context.reply(ephemeral = true, "This command can only be used as as slash command!")
val choice = args.singleOrNull() ?: GENDER_NOT_SPECIFIED
return mapOf(options.gender to choice)
}
}

companion object {
private companion object {
val I18N_PREFIX = I18nKeysData.Commands.Command.Gender

const val GENDER_NOT_SPECIFIED = "none"
}
}

0 comments on commit dc3ff47

Please sign in to comment.