Skip to content

Commit

Permalink
Add type per channel (#670)
Browse files Browse the repository at this point in the history
* feat(channelCooldown): add cooldown settings

* add: questionType

* add: perChannelTypes

* chore(style): format files

* fix: welcome type seperated

---------

Co-authored-by: ForGetFulSkyBro <[email protected]>
Co-authored-by: mezotv <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 27, 2024
1 parent 469f521 commit 43909e2
Show file tree
Hide file tree
Showing 24 changed files with 593 additions and 284 deletions.
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const button: Button = {
});

const DARE = await getQuestionsByType(
interaction.channelId,
"dare",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/neverhaveiever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const button: Button = {
});

const NHIE = await getQuestionsByType(
interaction.channelId,
"neverhaveiever",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const button: Button = {
});

const RANDOM = await getRandomTod(
interaction.channelId,
guildDb,
guildDb?.language != null
? guildDb.language
Expand Down
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const button: Button = {
});

const TOPIC = await getQuestionsByType(
interaction.channelId,
"topic",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/truth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const button: Button = {
});

const TRUTH = await getQuestionsByType(
interaction.channelId,
"truth",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/wouldyourather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const button: Button = {
});

const WYR = await getQuestionsByType(
interaction.channelId,
"wouldyourather",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/buttons/gamesActivities/wwyd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const button: Button = {
});

const WWYD = await getQuestionsByType(
interaction.channelId,
"whatwouldyoudo",
guildDb,
guildDb?.language != null
Expand Down
44 changes: 44 additions & 0 deletions src/buttons/questionTypes/customTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
ActionRowBuilder,
type MessageActionRowComponentBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
} from "discord.js";
import type { Button } from "../../interfaces";

const button: Button = {
name: "customTypes",
cooldown: false,
execute: async (interaction, client, guildDb) => {
const inter =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId("selectMenuCustomTypes")
.setPlaceholder("Click on the type you want to set globally.")
.setMinValues(1)
.setMaxValues(1)
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel("Regular")
.setValue("regular"),
new StringSelectMenuOptionBuilder()
.setLabel("Mixed")
.setValue("mixed"),
new StringSelectMenuOptionBuilder()
.setLabel("Custom")
.setValue("custom"),
),
);

interaction.update({
embeds: [],
content: "Click on the type you want to set globally.",
components: [inter],
options: {
ephemeral: true,
},
});
},
};

export default button;
34 changes: 34 additions & 0 deletions src/buttons/questionTypes/setPerChannel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
ActionRowBuilder,
ChannelSelectMenuBuilder,
ChannelType,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
type MessageActionRowComponentBuilder,
} from "discord.js";
import type { Button } from "../../interfaces";

const button: Button = {
name: "setPerChannel",
cooldown: false,
execute: async (interaction, client, guildDb) => {
const inter =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new ChannelSelectMenuBuilder()
.setCustomId("selectMenuPerChannel")
.setPlaceholder("Select a channel")
.addChannelTypes(ChannelType.GuildText),
);

interaction.update({
embeds: [],
content: "Select a channel you want to add a question type to.",
components: [inter],
options: {
ephemeral: true,
},
});
},
};

export default button;
67 changes: 67 additions & 0 deletions src/buttons/selectionMenus/selectMenuCustomTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
EmbedBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
type MessageActionRowComponentBuilder,
} from "discord.js";
import type { Button } from "../../interfaces";

const button: Button = {
name: "selectMenuCustomTypes",
cooldown: false,
execute: async (interaction, client, guildDb) => {
const value = (interaction as any).values[0];

await client.database.updateGuild(interaction.guild?.id || "", {
...guildDb,
customTypes: value,
});

const emb = new EmbedBuilder()
.setTitle("Would You - Question Types")
.setDescription(
`**Global Question Type**: ${value}\n**Per-Channel Settings**: \n${
guildDb.channelTypes
.map((ch) => `<#${ch.channelId}>: ${ch.questionType}`)
.join("\n") || "No specific channel settings"
}`,
)
.setColor("#0598F6")
.setFooter({
text: "Would You",
iconURL: client.user?.displayAvatarURL() || undefined,
});

// Button to set the global question type
const buttonGlobal =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("customTypes")
.setLabel("Set Global Question Type")
.setStyle(ButtonStyle.Primary),
);

// Button to configure per-channel types
const buttonPerChannel =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("setPerChannel")
.setLabel("Configure Per-Channel Types")
.setStyle(ButtonStyle.Secondary),
);

interaction.update({
content: null,
embeds: [emb],
components: [buttonGlobal, buttonPerChannel],
options: {
ephemeral: true,
},
});
},
};

export default button;
99 changes: 99 additions & 0 deletions src/buttons/selectionMenus/selectMenuPerChannel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
EmbedBuilder,
StringSelectMenuBuilder,
StringSelectMenuOptionBuilder,
type MessageActionRowComponentBuilder,
} from "discord.js";
import type { Button } from "../../interfaces";
import { Modal, type ModalData } from "../../util/modalHandler";

const typeRegex = /^(regular|custom|mixed)$/;

const button: Button = {
name: "selectMenuPerChannel",
cooldown: false,
execute: async (interaction, client, guildDb) => {
const newChannel = (interaction as any).values[0];
const chan = interaction.guild?.channels.cache.get(newChannel);
const { data } = await new Modal({
title: `${chan?.name}'s Question Type`,
customId: "questionTypePerChannel",
fields: [
{
customId: "input",
style: "line",
label: "Choose: Regular, Custom, or Mixed",
required: true,
placeholder: guildDb.customTypes,
},
],
} as ModalData).getData(interaction);

const value = data?.fieldValues[0].value;
if (!typeRegex.test(value as string)) {
data?.modal.reply({
ephemeral: true,
content:
"You must provide a valid type: `regular`, `custom`, or `mixed`.",
});
return;
}

if (guildDb.channelTypes.find((c) => c.channelId === newChannel)) {
guildDb.channelTypes = guildDb.channelTypes.filter(
(c) => c.channelId !== newChannel,
);
}

guildDb.channelTypes.push({
channelId: newChannel,
questionType: value as "regular" | "custom" | "mixed",
});

await client.database.updateGuild(interaction.guild?.id || "", {
...guildDb,
channelTypes: guildDb.channelTypes,
});

const emb = new EmbedBuilder()
.setTitle("Would You - Question Types")
.setDescription(
`**Global Question Type**: ${guildDb.customTypes}\n**Per-Channel Settings**: \n${guildDb.channelTypes.map((c) => `<#${c.channelId}>: ${c.questionType}`).join("\n")}`,
)
.setColor("#0598F6")
.setFooter({
text: "Would You",
iconURL: client.user?.displayAvatarURL() || undefined,
});

const buttonGlobal =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("customTypes")
.setLabel("Set Global Question Type")
.setStyle(ButtonStyle.Primary),
);

const buttonPerChannel =
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("setPerChannel")
.setLabel("Configure Per-Channel Types")
.setStyle(ButtonStyle.Secondary),
);

await (data?.modal as any).update({
content: null,
embeds: [emb],
components: [buttonGlobal, buttonPerChannel],
options: {
ephemeral: true,
},
});
},
};

export default button;
1 change: 1 addition & 0 deletions src/commands/game/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const command: ChatInputCommand = {
});

const DARE = await getQuestionsByType(
interaction.channelId,
"dare",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/commands/game/neverhaveiever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const command: ChatInputCommand = {
});

const NHIE = await getQuestionsByType(
interaction.channelId,
"neverhaveiever",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/commands/game/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const command: ChatInputCommand = {
});

const RANDOM = await getRandomTod(
interaction.channelId,
guildDb,
guildDb?.language != null
? guildDb.language
Expand Down
1 change: 1 addition & 0 deletions src/commands/game/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const command: ChatInputCommand = {
});

const TOPIC = await getQuestionsByType(
interaction.channelId,
"topic",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/commands/game/truth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const command: ChatInputCommand = {
});

const TRUTH = await getQuestionsByType(
interaction.channelId,
"truth",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/commands/game/whatwouldyoudo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const command: ChatInputCommand = {
});

const WWYD = await getQuestionsByType(
interaction.channelId,
"whatwouldyoudo",
guildDb,
guildDb?.language != null
Expand Down
1 change: 1 addition & 0 deletions src/commands/game/wouldyourather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const command: ChatInputCommand = {
});

const WYR = await getQuestionsByType(
interaction.channelId,
"wouldyourather",
guildDb,
guildDb?.language != null
Expand Down
Loading

0 comments on commit 43909e2

Please sign in to comment.