diff --git a/.deepsource.toml b/.deepsource.toml deleted file mode 100644 index e5ec308c..00000000 --- a/.deepsource.toml +++ /dev/null @@ -1,7 +0,0 @@ -version = 1 - -[[analyzers]] -name = "javascript" - - [analyzers.meta] - environment = ["nodejs"] \ No newline at end of file diff --git a/src/buttons/gamesActivities/dare.ts b/src/buttons/gamesActivities/dare.ts index 44c5c89b..687d7e74 100644 --- a/src/buttons/gamesActivities/dare.ts +++ b/src/buttons/gamesActivities/dare.ts @@ -12,6 +12,7 @@ import shuffle from "../../util/shuffle"; import { Button } from "../../interfaces"; import { getDare } from "../../util/Functions/jsonImport"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const button: Button = { name: "dare", @@ -45,8 +46,10 @@ const button: Button = { } } + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let Dare = await getDare( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/buttons/gamesActivities/higherlower.ts b/src/buttons/gamesActivities/higherlower.ts index 4fa94be0..4c8b02f3 100644 --- a/src/buttons/gamesActivities/higherlower.ts +++ b/src/buttons/gamesActivities/higherlower.ts @@ -15,6 +15,7 @@ import { getHigherLower } from "../../util/Functions/jsonImport"; import { HigherLowerEmbed } from "../../util/Defaults/Embeds/Games/HigherLowerEmbed"; import { HigherlowerModel } from "../../util/Models/higherlowerModel"; import HOR from "../../util/Classes/generateHOR"; +import { IUserModel, UserModel } from "../../util/Models/userModel"; const button: Button = { name: "higherlower", @@ -49,6 +50,8 @@ const button: Button = { } await interaction.deferReply(); + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + const initembed = new HigherLowerEmbed(interaction, client, guildDb); await interaction.editReply({ embeds: [initembed] }); @@ -93,7 +96,7 @@ const button: Button = { .setDescription( `${client.translation.get( - guildDb?.language, + guildDb?.language != null ? guildDb.language : userDb.language, "HigherLower.description", { keyword: game.items.current.keyword, diff --git a/src/buttons/gamesActivities/neverhaveiever.ts b/src/buttons/gamesActivities/neverhaveiever.ts index e969a953..a3c1df3c 100644 --- a/src/buttons/gamesActivities/neverhaveiever.ts +++ b/src/buttons/gamesActivities/neverhaveiever.ts @@ -11,6 +11,7 @@ import shuffle from "../../util/shuffle"; import { Button } from "../../interfaces"; import { getNeverHaveIEver } from "../../util/Functions/jsonImport"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const button: Button = { name: "neverhaveiever", @@ -44,8 +45,10 @@ const button: Button = { } } + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let { Funny, Basic, Young, Food, RuleBreak } = await getNeverHaveIEver( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/game/dare.ts b/src/commands/game/dare.ts index 747d18bd..6da1853e 100644 --- a/src/commands/game/dare.ts +++ b/src/commands/game/dare.ts @@ -10,6 +10,7 @@ import shuffle from "../../util/shuffle"; import { captureException } from "@sentry/node"; import { ChatInputCommand } from "../../interfaces"; import { getDare } from "../../util/Functions/jsonImport"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -29,8 +30,11 @@ const command: ChatInputCommand = { * @param {guildModel} guildDb */ execute: async (interaction, client, guildDb) => { + + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let Dare = await getDare( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/game/higherlower.ts b/src/commands/game/higherlower.ts index 5723948d..a6c76c40 100644 --- a/src/commands/game/higherlower.ts +++ b/src/commands/game/higherlower.ts @@ -13,6 +13,7 @@ import { ChatInputCommand } from "../../interfaces"; import { HigherlowerModel } from "../../util/Models/higherlowerModel"; import { getHigherLower } from "../../util/Functions/jsonImport"; import { HigherLowerEmbed } from "../../util/Defaults/Embeds/Games/HigherLowerEmbed"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -35,6 +36,8 @@ const command: ChatInputCommand = { execute: async (interaction, client, guildDb) => { await interaction.deferReply(); + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + const initembed = new HigherLowerEmbed(interaction, client, guildDb); await interaction.editReply({ embeds: [initembed] }); @@ -79,7 +82,7 @@ const command: ChatInputCommand = { .setDescription( `${client.translation.get( - guildDb?.language, + guildDb?.language != null ? guildDb.language : userDb.language, "HigherLower.description", { keyword: game.items.current.keyword, diff --git a/src/commands/game/leaderboard.ts b/src/commands/game/leaderboard.ts index 3e7edd4c..26d066f1 100644 --- a/src/commands/game/leaderboard.ts +++ b/src/commands/game/leaderboard.ts @@ -1,7 +1,7 @@ import { EmbedBuilder, SlashCommandBuilder } from "discord.js"; import { ChatInputCommand } from "../../interfaces"; import Paginator from "../../util/pagination"; -import { UserModel } from "../../util/Models/userModel"; +import { IUserModel, UserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -38,6 +38,10 @@ const command: ChatInputCommand = { * @param {guildModel} guildDb */ execute: async (interaction, client, guildDb) => { + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + + let language = guildDb?.language != null ? guildDb.language : userDb.language; + switch (interaction.options.getString("game")) { case "higherlower": const page = new Paginator({ @@ -67,7 +71,7 @@ const command: ChatInputCommand = { if (data.length === 0) { interaction.reply({ content: client.translation.get( - guildDb?.language, + language, "Leaderboard.none", ), }); @@ -79,11 +83,11 @@ const command: ChatInputCommand = { `${i++}. ${ s.user === "Anonymous" ? `${s.user} • **${s.score}** ${client.translation.get( - guildDb?.language, + language, "Leaderboard.points", )}` : `<@${s.user}> • **${s.score}** ${client.translation.get( - guildDb?.language, + language, "Leaderboard.points", )}` }`, @@ -93,7 +97,7 @@ const command: ChatInputCommand = { new EmbedBuilder() .setTitle( client.translation.get( - guildDb?.language, + language, "Leaderboard.global", ), ) @@ -113,7 +117,7 @@ const command: ChatInputCommand = { new EmbedBuilder() .setTitle( client.translation.get( - guildDb?.language, + language, "Leaderboard.global", ), ) @@ -144,7 +148,7 @@ const command: ChatInputCommand = { if (data.length === 0) { interaction.reply({ content: client.translation.get( - guildDb?.language, + language, "Leaderboard.none", ), }); @@ -156,11 +160,11 @@ const command: ChatInputCommand = { `${i++}. ${ s.user === "Anonymous" ? `${s.user} • **${s.score}** ${client.translation.get( - guildDb?.language, + language, "Leaderboard.points", )}` : `<@${s.user}> • **${s.score}** ${client.translation.get( - guildDb?.language, + language, "Leaderboard.points", )}` }`, @@ -178,7 +182,7 @@ const command: ChatInputCommand = { new EmbedBuilder() .setTitle( client.translation.get( - guildDb?.language, + language, "Leaderboard.guild", ), ) diff --git a/src/commands/game/neverhaveiever.ts b/src/commands/game/neverhaveiever.ts index 2cc3893f..5c03c9ad 100644 --- a/src/commands/game/neverhaveiever.ts +++ b/src/commands/game/neverhaveiever.ts @@ -10,6 +10,7 @@ import { captureException } from "@sentry/node"; import shuffle from "../../util/shuffle"; import { ChatInputCommand } from "../../interfaces"; import { getNeverHaveIEver } from "../../util/Functions/jsonImport"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -30,8 +31,11 @@ const command: ChatInputCommand = { */ execute: async (interaction, client, guildDb) => { + + let userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let { Funny, Basic, Young, Food, RuleBreak } = await getNeverHaveIEver( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/game/random.ts b/src/commands/game/random.ts index 7fe7eace..df70ef68 100644 --- a/src/commands/game/random.ts +++ b/src/commands/game/random.ts @@ -10,6 +10,7 @@ import shuffle from "../../util/shuffle"; import { captureException } from "@sentry/node"; import { ChatInputCommand } from "../../interfaces"; import { getRandomTod } from "../../util/Functions/jsonImport"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -30,8 +31,11 @@ const command: ChatInputCommand = { * @param {guildModel} guildDb */ execute: async (interaction, client, guildDb) => { + + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let Randomtod = await getRandomTod( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/game/truth.ts b/src/commands/game/truth.ts index 3d9eb084..678861c8 100644 --- a/src/commands/game/truth.ts +++ b/src/commands/game/truth.ts @@ -10,6 +10,7 @@ import shuffle from "../../util/shuffle"; import { captureException } from "@sentry/node"; import { ChatInputCommand } from "../../interfaces"; import { getTruth } from "../../util/Functions/jsonImport"; +import { UserModel, IUserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -29,8 +30,11 @@ const command: ChatInputCommand = { * @param {guildModel} guildDb */ execute: async (interaction, client, guildDb) => { + + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let Truth = await getTruth( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/game/whatwouldyoudo.ts b/src/commands/game/whatwouldyoudo.ts index ff172763..4fd389f7 100644 --- a/src/commands/game/whatwouldyoudo.ts +++ b/src/commands/game/whatwouldyoudo.ts @@ -10,6 +10,7 @@ import shuffle from "../../util/shuffle"; import { captureException } from "@sentry/node"; import { ChatInputCommand } from "../../interfaces"; import { getWwyd } from "../../util/Functions/jsonImport"; +import { IUserModel, UserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -28,8 +29,11 @@ const command: ChatInputCommand = { * @param {guildModel} guildDb */ execute: async (interaction, client, guildDb) => { + + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let WWYD = await getWwyd( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/game/wouldyourather.ts b/src/commands/game/wouldyourather.ts index b0ac7eaa..c9cda565 100644 --- a/src/commands/game/wouldyourather.ts +++ b/src/commands/game/wouldyourather.ts @@ -9,6 +9,7 @@ import { captureException } from "@sentry/node"; import { ChatInputCommand } from "../../interfaces"; import { getWouldYouRather } from "../../util/Functions/jsonImport"; import { DefaultGameEmbed } from "../../util/Defaults/Embeds/Games/DefaultGameEmbed"; +import { IUserModel, UserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, @@ -29,8 +30,11 @@ const command: ChatInputCommand = { */ execute: async (interaction, client, guildDb) => { + + const userDb = await UserModel.findOne({ userID: interaction.user?.id }) as IUserModel; + let General = await getWouldYouRather( - guildDb?.language != null ? guildDb.language : "en_EN", + guildDb?.language != null ? guildDb.language : userDb.language, ); let dbquestions; diff --git a/src/commands/index.ts b/src/commands/index.ts index d656cf4b..a74cf501 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -72,6 +72,7 @@ const commandInteractionEvent: Event = { "whatwouldyoudo", "leaderboard", "privacy", + "language", ]; if ( !interaction.guild && diff --git a/src/commands/settings/language.ts b/src/commands/settings/language.ts index a21f7641..7d244541 100644 --- a/src/commands/settings/language.ts +++ b/src/commands/settings/language.ts @@ -6,29 +6,39 @@ import { } from "discord.js"; import { captureException } from "@sentry/node"; import { ChatInputCommand } from "../../interfaces"; +import { UserModel } from "../../util/Models/userModel"; const command: ChatInputCommand = { requireGuild: true, data: new SlashCommandBuilder() .setName("language") .setDescription("Changes the language for your server") - .setDMPermission(false) .setDescriptionLocalizations({ de: "Ändere die Sprache für den aktuellen Server", "es-ES": "Cambiar el idioma del bot en el servidor", fr: "Changer la langue du serveur actuel", }) + .addStringOption((option) => + option + .setName("type") + .setDescription("What you want to change the language for.") + .setRequired(true) + .addChoices( + { name: "User", value: "user" }, + { name: "Server", value: "server" }, + ), + ) .addStringOption((option) => option .setName("language") .setDescription("The language you want to use.") .setRequired(true) .addChoices( - { name: "🇩🇪 Deutsch", value: "german" }, - { name: "🇺🇸 English", value: "english" }, - { name: "🇪🇸 Español", value: "spanish" }, - { name: "🇫🇷 Français", value: "french" }, - // { name: "🇮🇹 Italiano", value: "italian" }, + { name: "🇩🇪 Deutsch", value: "de_DE" }, + { name: "🇺🇸 English", value: "en_EN" }, + { name: "🇪🇸 Español", value: "es_ES" }, + { name: "🇫🇷 Français", value: "fr_FR" }, + // { name: "🇮🇹 Italiano", value: "fr_FR" }, ), ), @@ -39,116 +49,100 @@ const command: ChatInputCommand = { */ execute: async (interaction, client, guildDb) => { let languageembed; - if ( - (interaction.member?.permissions as Readonly).has( - PermissionFlagsBits.ManageGuild, - ) - ) { - switch (interaction.options.getString("language")) { - case "english": { - await client.database.updateGuild( - interaction.guildId || "", - { - ...guildDb, - language: "en_EN", - }, - true, - ); - languageembed = new EmbedBuilder() - .setTitle("Language changed!") - .setDescription("English has been selected as the new language!") - .setFooter({ - text: "Would You", - iconURL: client?.user?.displayAvatarURL() || undefined, - }); - break; - } - case "german": { - await client.database.updateGuild( - interaction.guildId || "", - { - ...guildDb, - language: "de_DE", - }, - true, - ); + const languageMap = { + de_DE: { title: "Sprache geändert!", description: "Deutsch wurde als neue Sprache ausgewählt!" }, + en_EN: { title: "Language changed!", description: "English has been selected as the new language!" }, + es_ES: { title: "¡Idioma cambiado!", description: "¡Has seleccionado el español como nuevo idioma!"}, + fr_FR: { title: "Langue changée!", description: "Français a été sélectionné comme nouvelle langue!"}, + } as Record - languageembed = new EmbedBuilder() - .setTitle("Sprache bearbeitet!") - .setDescription("Deutsch wurde als neue Sprache ausgewählt!") - .setFooter({ - text: "Would You", - iconURL: client?.user?.displayAvatarURL() || undefined, - }); - break; + languageembed = new EmbedBuilder() + .setTitle(languageMap[interaction.options.getString("language") || "en_EN"].title) + .setDescription(languageMap[interaction.options.getString("language") || "en_EN"].description) + .setFooter({ + text: "Would You", + iconURL: client?.user?.displayAvatarURL() || undefined, + }); + + switch (interaction.options.getString("type")) { + case "user": { + if (interaction.guild) { + console.log(!interaction.guild); + interaction.reply({ + content: + "You can only change the language for your user in direct messages!", + ephemeral: true, + }); + return; } - case "spanish": { - await client.database.updateGuild( - interaction.guildId || "", - { - ...guildDb, - language: "es_ES", - }, - true, - ); + await UserModel.findOneAndUpdate( + { userID: interaction.user.id }, + { language: interaction.options.getString("language") || "en_EN" }, + { upsert: true }, + ); - languageembed = new EmbedBuilder() - .setTitle("¡Idioma cambiado!") - .setDescription("¡Has seleccionado el español como nuevo idioma!") - .setFooter({ - text: "Would You", - iconURL: client?.user?.displayAvatarURL() || undefined, + interaction + .reply({ + embeds: [languageembed as EmbedBuilder], + ephemeral: true, + }) + .catch((err) => { + captureException(err); }); break; + } + case "server": { + if (!interaction.guild) { + console.log(interaction.guild); + interaction.reply({ + content: + "You can only change the language for the server in a server!", + ephemeral: true, + }); + return; } - case "french": { + if ( + ( + interaction.member?.permissions as Readonly + ).has(PermissionFlagsBits.ManageGuild) + ) { await client.database.updateGuild( - interaction.guildId || "", + interaction.guildId as string, { ...guildDb, - language: "fr_FR", + language: interaction.options.getString("language") || "en_EN", }, true, ); - languageembed = new EmbedBuilder() - .setTitle("Langue changée!") - .setDescription("Français a été sélectionné comme nouvelle langue!") - .setFooter({ - text: "Would You", - iconURL: client?.user?.displayAvatarURL() || undefined, + interaction + .reply({ + embeds: [languageembed as EmbedBuilder], + ephemeral: true, + }) + .catch((err) => { + captureException(err); }); break; + } else { + const errorembed = new EmbedBuilder() + .setColor("#F00505") + .setTitle("Error!") + .setDescription( + client.translation.get(guildDb?.language, "Language.embed.error"), + ); + interaction + .reply({ + embeds: [errorembed], + ephemeral: true, + }) + .catch((err) => { + captureException(err); + }); + return; } } - - interaction - .reply({ - embeds: [languageembed as EmbedBuilder], - ephemeral: true, - }) - .catch((err) => { - captureException(err); - }); - return; - } else { - const errorembed = new EmbedBuilder() - .setColor("#F00505") - .setTitle("Error!") - .setDescription( - client.translation.get(guildDb?.language, "Language.embed.error"), - ); - - interaction - .reply({ - embeds: [errorembed], - ephemeral: true, - }) - .catch((err) => { - captureException(err); - }); - return; } }, }; diff --git a/src/util/Functions/supportAppCommands.ts b/src/util/Functions/supportAppCommands.ts index 3d8c27e4..8132e74c 100644 --- a/src/util/Functions/supportAppCommands.ts +++ b/src/util/Functions/supportAppCommands.ts @@ -16,6 +16,7 @@ const userCommands = [ "whatwouldyoudo", "leaderboard", "privacy", + "language" ]; export default function supportAppCommands( diff --git a/src/util/Models/userModel.ts b/src/util/Models/userModel.ts index ddaa663b..3086118f 100644 --- a/src/util/Models/userModel.ts +++ b/src/util/Models/userModel.ts @@ -3,6 +3,7 @@ import { Schema, model } from "mongoose"; export interface IUserModel { userID: { type: string; required: true }; votePrivacy: boolean; + language: string; wouldyourather: { yes: number; no: number; @@ -58,6 +59,7 @@ const userModelSchema = new Schema( { userID: { type: String, unique: true }, votePrivacy: { type: Boolean, default: false }, + language : { type: String, default: "en_EN" }, wouldyourather: { yes: { type: Number, default: 0 }, no: { type: Number, default: 0 },