Skip to content

Commit

Permalink
feat(language): allow language change in dms
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik K committed Apr 7, 2024
1 parent 5a76b01 commit 77d4111
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 125 deletions.
7 changes: 0 additions & 7 deletions .deepsource.toml

This file was deleted.

5 changes: 4 additions & 1 deletion src/buttons/gamesActivities/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/buttons/gamesActivities/higherlower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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] });
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/buttons/gamesActivities/neverhaveiever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/commands/game/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/commands/game/higherlower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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] });
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 14 additions & 10 deletions src/commands/game/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -67,7 +71,7 @@ const command: ChatInputCommand = {
if (data.length === 0) {
interaction.reply({
content: client.translation.get(
guildDb?.language,
language,
"Leaderboard.none",
),
});
Expand All @@ -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",
)}`
}`,
Expand All @@ -93,7 +97,7 @@ const command: ChatInputCommand = {
new EmbedBuilder()
.setTitle(
client.translation.get(
guildDb?.language,
language,
"Leaderboard.global",
),
)
Expand All @@ -113,7 +117,7 @@ const command: ChatInputCommand = {
new EmbedBuilder()
.setTitle(
client.translation.get(
guildDb?.language,
language,
"Leaderboard.global",
),
)
Expand Down Expand Up @@ -144,7 +148,7 @@ const command: ChatInputCommand = {
if (data.length === 0) {
interaction.reply({
content: client.translation.get(
guildDb?.language,
language,
"Leaderboard.none",
),
});
Expand All @@ -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",
)}`
}`,
Expand All @@ -178,7 +182,7 @@ const command: ChatInputCommand = {
new EmbedBuilder()
.setTitle(
client.translation.get(
guildDb?.language,
language,
"Leaderboard.guild",
),
)
Expand Down
6 changes: 5 additions & 1 deletion src/commands/game/neverhaveiever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/commands/game/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/commands/game/truth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/commands/game/whatwouldyoudo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/commands/game/wouldyourather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const commandInteractionEvent: Event = {
"whatwouldyoudo",
"leaderboard",
"privacy",
"language",
];
if (
!interaction.guild &&
Expand Down
Loading

0 comments on commit 77d4111

Please sign in to comment.