Skip to content

Commit

Permalink
finish truth or dare
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik K committed Oct 31, 2023
1 parent fad9890 commit ec8d990
Show file tree
Hide file tree
Showing 14 changed files with 5,909 additions and 131 deletions.
88 changes: 88 additions & 0 deletions src/buttons/dare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
PermissionFlagsBits,
MessageActionRowComponentBuilder,
} from "discord.js";
import { captureException } from "@sentry/node";
import shuffle from "../util/shuffle";
import { Button } from "../models";
import { getDare } from "../util/Functions/jsonImport";

const button: Button = {
name: "dare",
execute: async (interaction: any, client, guildDb) => {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessages)
)
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
let Dare = await getDare(guildDb.language);
const dbquestions = guildDb.customMessages.filter(
(c) => c.type !== "nsfw" && c.type === "dare",
);

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 dareembed = new EmbedBuilder()
.setColor("#248046")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Dare | 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: [dareembed], components: components })
.catch((err: Error) => {
captureException(err);
});
},
};

export default button;
88 changes: 88 additions & 0 deletions src/buttons/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
PermissionFlagsBits,
MessageActionRowComponentBuilder,
} from "discord.js";
import { captureException } from "@sentry/node";
import shuffle from "../util/shuffle";
import { Button } from "../models";
import { getRandomTod } from "../util/Functions/jsonImport";

const button: Button = {
name: "random",
execute: async (interaction: any, client, guildDb) => {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessages)
)
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
let random = await getRandomTod(guildDb.language);
const dbquestions = guildDb.customMessages.filter(
(c) => c.type !== "nsfw" && c.type === "randomToD",
);

let truthordare = [] as string[];

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

switch (guildDb.customTypes) {
case "regular":
truthordare = shuffle([...random]);
break;
case "mixed":
truthordare = shuffle([...random, ...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 randomebed = 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: [randomebed], components: components })
.catch((err: Error) => {
captureException(err);
});
},
};

export default button;
88 changes: 88 additions & 0 deletions src/buttons/truth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
PermissionFlagsBits,
MessageActionRowComponentBuilder,
} from "discord.js";
import { captureException } from "@sentry/node";
import shuffle from "../util/shuffle";
import { Button } from "../models";
import { getTruth } from "../util/Functions/jsonImport";

const button: Button = {
name: "truth",
execute: async (interaction: any, client, guildDb) => {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessages)
)
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
let Truth = await getTruth(guildDb.language);
const dbquestions = guildDb.customMessages.filter(
(c) => c.type !== "nsfw" && c.type === "truth",
);

let truthordare = [] as string[];

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

switch (guildDb.customTypes) {
case "regular":
truthordare = shuffle([...Truth]);
break;
case "mixed":
truthordare = shuffle([...Truth, ...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 truthembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Truth | 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: [truthembed], components: components })
.catch((err: Error) => {
captureException(err);
});
},
};

export default button;
94 changes: 94 additions & 0 deletions src/commands/game/dare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
EmbedBuilder,
SlashCommandBuilder,
ActionRowBuilder,
ButtonBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import shuffle from "../../util/shuffle";
import { captureException } from "@sentry/node";
import { ChatInputCommand } from "../../models";
import { getDare } from "../../util/Functions/jsonImport";

const command: ChatInputCommand = {
requireGuild: true,
data: new SlashCommandBuilder()
.setName("dare")
.setDescription("Posts a random dare question that you need to answer")
.setDMPermission(false)
.setDescriptionLocalizations({
de: "Postet eine zufällige Pflichtfrage, die du beantworten musst",
"es-ES":
"Publica una pregunta de atrevimiento aleatoria que debes responder",
fr: "Publie une question 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 getDare(guildDb.language);
const dbquestions = guildDb.customMessages.filter(
(c) => c.type !== "nsfw" && c.type === "dare",
);

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 dareembed = new EmbedBuilder()
.setColor("#0598F6")
.setFooter({
text: `Requested by ${interaction.user.username} | Type: Random Dare | 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: [dareembed], components: components })
.catch((err) => {
captureException(err);
});
},
};

export default command;
Loading

0 comments on commit ec8d990

Please sign in to comment.