generated from mezotv/Discord-Bot-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
469f521
commit 43909e2
Showing
24 changed files
with
593 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.