diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/PublicLorittaCommands.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/PublicLorittaCommands.kt index 84e92cc6e9..2b2985b6ef 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/PublicLorittaCommands.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/PublicLorittaCommands.kt @@ -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 @@ -30,7 +29,7 @@ class PublicLorittaCommands(val languageManager: LanguageManager) { // ===[ MODERATION ]=== register(BanCommand(languageManager)) - register(PredefinedReasonsCommand(languageManager)) +// register(PredefinedReasonsCommand(languageManager)) // ===[ FUN ]=== register(TextTransformCommand(languageManager)) diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/vanilla/social/GenderExecutor.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/vanilla/social/GenderExecutor.kt deleted file mode 100644 index e533971830..0000000000 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/vanilla/social/GenderExecutor.kt +++ /dev/null @@ -1,41 +0,0 @@ -package net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.social - -import net.perfectdreams.loritta.cinnamon.emotes.Emotes -import net.perfectdreams.loritta.common.utils.Gender -import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.ApplicationCommandContext -import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.CinnamonSlashCommandExecutor -import net.perfectdreams.loritta.morenitta.LorittaBot -import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.options.LocalizedApplicationCommandOptions -import net.perfectdreams.discordinteraktions.common.commands.options.SlashCommandArguments -import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.social.declarations.GenderCommand -import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled -import net.perfectdreams.loritta.cinnamon.discord.utils.getOrCreateUserProfile - -class GenderExecutor(loritta: LorittaBot) : CinnamonSlashCommandExecutor(loritta) { - inner class Options : LocalizedApplicationCommandOptions(loritta) { - val gender = string("gender", GenderCommand.I18N_PREFIX.Options.Gender) { - choice(GenderCommand.I18N_PREFIX.Female, "female") - choice(GenderCommand.I18N_PREFIX.Male, "male") - choice(GenderCommand.I18N_PREFIX.Unknown, "unknown") - } - } - - override val options = Options() - - override suspend fun execute(context: ApplicationCommandContext, args: SlashCommandArguments) { - val userSettings = context.loritta.pudding.users.getOrCreateUserProfile(context.user) - .getProfileSettings() - - val gender = Gender.valueOf(args[options.gender].uppercase()) - - if (userSettings.gender != gender) - userSettings.setGender(gender) - - context.sendEphemeralMessage { - styled( - context.i18nContext.get(GenderCommand.I18N_PREFIX.SuccessfullyChanged), - Emotes.Tada - ) - } - } -} diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/vanilla/social/declarations/GenderCommand.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/vanilla/social/declarations/GenderCommand.kt deleted file mode 100644 index 671128503e..0000000000 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/interactions/vanilla/social/declarations/GenderCommand.kt +++ /dev/null @@ -1,19 +0,0 @@ -package net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.social.declarations - -import net.perfectdreams.loritta.common.locale.LanguageManager -import net.perfectdreams.loritta.i18n.I18nKeysData -import net.perfectdreams.loritta.morenitta.LorittaBot -import net.perfectdreams.loritta.common.commands.CommandCategory -import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.CinnamonSlashCommandDeclarationWrapper - -import net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla.social.GenderExecutor - -class GenderCommand(languageManager: LanguageManager) : CinnamonSlashCommandDeclarationWrapper(languageManager) { - companion object { - val I18N_PREFIX = I18nKeysData.Commands.Command.Gender - } - - override fun declaration() = slashCommand(I18N_PREFIX.Label, CommandCategory.SOCIAL, I18N_PREFIX.Description) { - executor = { GenderExecutor(it) } - } -} \ No newline at end of file diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt index eea6535317..48316f78e7 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt @@ -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 @@ -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)) diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/moderation/PredefinedReasonsCommand.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/moderation/PredefinedReasonsCommand.kt new file mode 100644 index 0000000000..6340167bbb --- /dev/null +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/moderation/PredefinedReasonsCommand.kt @@ -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 + ) { + 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 + ): Map, 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." + ) + ) + } +} \ No newline at end of file diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/AfkCommand.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/AfkCommand.kt index 352ee00857..68c947cb06 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/AfkCommand.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/AfkCommand.kt @@ -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 @@ -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") ) { @@ -91,7 +92,7 @@ class AfkCommand: SlashCommandDeclarationWrapper { ): Map, Any?>? = emptyMap() } - companion object { + private companion object { private val I18N_PREFIX = I18nKeysData.Commands.Command.Afk } } \ No newline at end of file diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/GenderCommand.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/GenderCommand.kt index e411ac631d..d94ac660d7 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/GenderCommand.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/social/GenderCommand.kt @@ -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() @@ -64,12 +69,15 @@ class GenderCommand: SlashCommandDeclarationWrapper { context: LegacyMessageCommandContext, args: List ): Map, 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" } } \ No newline at end of file