Skip to content

Commit

Permalink
fix: custom tod questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik K committed Nov 2, 2023
1 parent e6b54b2 commit 4eb5d78
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/buttons/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const button: Button = {
const dareembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Dare | ID: ${Random}`,
text: `Requested by ${interaction.user.username} | Type: Dare | ID: ${Random}`,
iconURL: interaction.user.avatarURL() || "",
})
.setDescription(truthordare[Random]);
Expand Down
2 changes: 1 addition & 1 deletion src/buttons/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const button: Button = {
});
let random = await getRandomTod(guildDb.language);
const dbquestions = guildDb.customMessages.filter(
(c) => c.type !== "nsfw" && c.type === "randomToD",
(c) => c.type !== "nsfw" && c.type === "truth" || c.type === "dare"
);

let truthordare = [] as string[];
Expand Down
2 changes: 1 addition & 1 deletion src/buttons/truth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const button: Button = {
const truthembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Truth | ID: ${Random}`,
text: `Requested by ${interaction.user.username} | Type: Truth | ID: ${Random}`,
iconURL: interaction.user.avatarURL() || "",
})
.setDescription(truthordare[Random]);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/game/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const command: ChatInputCommand = {
const dareembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Dare | ID: ${Random}`,
text: `Requested by ${interaction.user.username} | Type: Dare | ID: ${Random}`,
iconURL: interaction.user.avatarURL() || "",
})
.setDescription(truthordare[Random]);
Expand Down
95 changes: 95 additions & 0 deletions src/commands/game/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
EmbedBuilder,
SlashCommandBuilder,
ActionRowBuilder,
ButtonBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import shuffle from "../../util/shuffle";
import { captureException } from "@sentry/node";
import { ChatInputCommand } from "../../models";
import { getRandomTod } from "../../util/Functions/jsonImport";

const command: ChatInputCommand = {
requireGuild: true,
data: new SlashCommandBuilder()
.setName("random")
.setDescription("Post a random truth or dare question that you need to answer bitwise cat was here hehe")
.setDMPermission(false)
.setDescriptionLocalizations({
de: "Posted eine zufällig Wahrheits- oder Pflichtfrage, die du beantworten musst shay was here hehe",
"es-ES":
"Publica una pregunta de verdad o reto aleatoria que debes responder",
fr: "Publie une question de vérité ou de défi aléatoire que vous devez répondre",
}),

/**
* @param {CommandInteraction} interaction
* @param {WouldYou} client
* @param {guildModel} guildDb
*/
execute: async (interaction, client, guildDb) => {
let Dare = await getRandomTod(guildDb.language);
const dbquestions = guildDb.customMessages.filter(
(c) => c.type !== "nsfw" && c.type === "dare" || c.type === "truth" ,
);

let truthordare = [] as string[];

if (!dbquestions.length) guildDb.customTypes = "regular";

switch (guildDb.customTypes) {
case "regular":
truthordare = shuffle([...Dare]);
break;
case "mixed":
truthordare = shuffle([...Dare, ...dbquestions.map((c) => c.msg)]);
break;
case "custom":
truthordare = shuffle(dbquestions.map((c) => c.msg));
break;
}

const Random = Math.floor(Math.random() * truthordare.length);

const randomembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random | ID: ${Random}`,
iconURL: interaction.user.avatarURL() || "",
})
.setDescription(truthordare[Random]);

const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
const row2 = new ActionRowBuilder<MessageActionRowComponentBuilder>();
let components = [] as any[];
if (Math.round(Math.random() * 15) < 3) {
row2.addComponents([
new ButtonBuilder()
.setLabel("Invite")
.setStyle(5)
.setEmoji("1009964111045607525")
.setURL(
"https://discord.com/oauth2/authorize?client_id=981649513427111957&permissions=275415247936&scope=bot%20applications.commands",
),
]);
components = [row, row2];
} else {
components = [row];
}
row.addComponents([
new ButtonBuilder().setLabel("Truth").setStyle(3).setCustomId("truth"),
new ButtonBuilder().setLabel("Dare").setStyle(4).setCustomId("dare"),
new ButtonBuilder().setLabel("Random").setStyle(1).setCustomId("random"),
]);

interaction
.reply({ embeds: [randomembed], components: components })
.catch((err) => {
captureException(err);
});
},
};

export default command;

2 changes: 1 addition & 1 deletion src/commands/game/truth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const command: ChatInputCommand = {
const truthembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Truth | ID: ${Random}`,
text: `Requested by ${interaction.user.username} | Type: Truth | ID: ${Random}`,
iconURL: interaction.user.avatarURL() || "",
})
.setDescription(truthordare[Random]);
Expand Down
184 changes: 184 additions & 0 deletions src/commands/settings/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const command: ChatInputCommand = {
{ name: "Would You Rather", value: "wouldyourather" },
{ name: "Never Have I Ever", value: "neverhaveiever" },
{ name: "What Would You Do", value: "wwyd" },
{ name: "Truth", value: "truth" },
{ name: "Dare", value: "dare" },
),
)
.addStringOption((option) =>
Expand Down Expand Up @@ -373,6 +375,96 @@ const command: ChatInputCommand = {
);
}

if (
guildDb.customMessages.filter((c) => c.type === "truth")
.length > 0
) {
let data: any;
data = guildDb.customMessages
.filter((c) => c.type === "truth")
.map(
(s, i) =>
`${client.translation.get(
guildDb?.language,
"wyCustom.success.embedAdd.descID",
)}: ${s.id}\n${client.translation.get(
guildDb?.language,
"wyCustom.success.embedAdd.descMsg",
)}: ${s.msg}`,
);
data = Array.from(
{
length: Math.ceil(data.length / 5),
},
(a, r) => data.slice(r * 5, r * 5 + 5),
);

Math.ceil(data.length / 5);
data = data.map((e: any) =>
page.add(
new EmbedBuilder()
.setTitle(
client.translation.get(
guildDb?.language,
"wyCustom.success.paginator.title",
),
)
.setDescription(
`${client.translation.get(
guildDb?.language,
"wyCustom.success.paginator.descCatTRUTH",
)}\n\n${e.slice(0, 5).join("\n\n").toString()}`,
)
.setColor("#0795F6"),
),
);
}

if (
guildDb.customMessages.filter((c) => c.type === "dare")
.length > 0
) {
let data: any;
data = guildDb.customMessages
.filter((c) => c.type === "dare")
.map(
(s, i) =>
`${client.translation.get(
guildDb?.language,
"wyCustom.success.embedAdd.descID",
)}: ${s.id}\n${client.translation.get(
guildDb?.language,
"wyCustom.success.embedAdd.descMsg",
)}: ${s.msg}`,
);
data = Array.from(
{
length: Math.ceil(data.length / 5),
},
(a, r) => data.slice(r * 5, r * 5 + 5),
);

Math.ceil(data.length / 5);
data = data.map((e: any) =>
page.add(
new EmbedBuilder()
.setTitle(
client.translation.get(
guildDb?.language,
"wyCustom.success.paginator.title",
),
)
.setDescription(
`${client.translation.get(
guildDb?.language,
"wyCustom.success.paginator.descCatDARE",
)}\n\n${e.slice(0, 5).join("\n\n").toString()}`,
)
.setColor("#0795F6"),
),
);
}

if (
guildDb.customMessages.filter((c) => c.type === "wwyd").length > 0
) {
Expand Down Expand Up @@ -551,6 +643,12 @@ const command: ChatInputCommand = {
let wouldyourather = guildDb.customMessages.filter(
(c) => c.type === "wouldyourather",
).length;
let truth = guildDb.customMessages.filter(
(c) => c.type === "truth",
).length;
let dare = guildDb.customMessages.filter(
(c) => c.type === "dare",
).length;
let neverhaveiever = guildDb.customMessages.filter(
(c) => c.type === "neverhaveiever",
).length;
Expand Down Expand Up @@ -634,6 +732,62 @@ const command: ChatInputCommand = {
});
}

if (response.data.truth) {
/*
if (
response.data.truth.length + truth > 30 &&
!client.voteLogger.votes.has(interaction.user.id)
) {
interaction.editReply({
options: {
ephemeral: true,
},
content: client.translation.get(
guildDb?.language,
"wyCustom.error.import.att22",
),
});
return;
}
*/
response.data.truth.map((d: any) => {
let newID = makeID(6);
guildDb.customMessages.push({
id: newID,
msg: d,
type: "truth",
});
});
}

if (response.data.dare) {
/*
if (
response.data.dare.length + dare > 30 &&
!client.voteLogger.votes.has(interaction.user.id)
) {
interaction.editReply({
options: {
ephemeral: true,
},
content: client.translation.get(
guildDb?.language,
"wyCustom.error.import.att22",
),
});
return;
}
*/
response.data.dare.map((d: any) => {
let newID = makeID(6);
guildDb.customMessages.push({
id: newID,
msg: d,
type: "dare",
});
});
}

if (response.data.neverhaveiever) {
/*
if (
Expand Down Expand Up @@ -738,6 +892,12 @@ const command: ChatInputCommand = {
let wouldyourather = guildDb.customMessages.filter(
(c) => c.type === "wouldyourather",
);
let truth = guildDb.customMessages.filter(
(c) => c.type === "truth",
);
let dare = guildDb.customMessages.filter(
(c) => c.type === "dare",
);
let neverhaveiever = guildDb.customMessages.filter(
(c) => c.type === "neverhaveiever",
);
Expand All @@ -757,6 +917,30 @@ const command: ChatInputCommand = {
arrayText += `\n]`;
arrays.push(arrayText);
}

if (truth.length > 0) {
let arrayText = `"truth": [`;
truth.map((a, i) => {
i = i++ + 1;
arrayText += `\n"${a.msg}"${
truth.length !== i ? "," : ""
}`;
});
arrayText += `\n]`;
arrays.push(arrayText);
}

if (dare.length > 0) {
let arrayText = `"dare": [`;
dare.map((a, i) => {
i = i++ + 1;
arrayText += `\n"${a.msg}"${
dare.length !== i ? "," : ""
}`;
});
arrayText += `\n]`;
arrays.push(arrayText);
}

if (neverhaveiever.length > 0) {
let arrayText = `"neverhaveiever": [`;
Expand Down
10 changes: 1 addition & 9 deletions src/commands/utility/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ const command: ChatInputCommand = {
"Vote.embed.value",
)} ](https://top.gg/bot/981649513427111957/vote)`,
inline: true,
},
{
name: "Voidbots",
value: `> [ ${client.translation.get(
guildDb?.language,
"Vote.embed.value",
)} ](https://voidbots.net/bot/981649513427111957)`,
inline: true,
},
}
)
.setThumbnail(client.user?.displayAvatarURL() || "")
.setFooter({
Expand Down
2 changes: 2 additions & 0 deletions src/languages/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
"title": "Would You benutzerdefinierte Nachrichten",
"descCatNHIE": "**Kategorie**: Nie habe ich jemals",
"descCatWYR": "**Kategorie**: Würdest du eher",
"descCatTRUTH": "**Kategorie**: Wahrheit",
"descCatDARE": "**Kategorie**: Pflicht",
"descCatWWYD": "**Kategorie**: Was würdest du tun"
}
}
Expand Down
Loading

0 comments on commit 4eb5d78

Please sign in to comment.