Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
65 lines (60 loc) · 2.5 KB
/
Copy pathutils.js
File metadata and controls
65 lines (60 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ButtonBuilder } from "discord.js";
import { interactionReply } from "ewilib";
import { pronounsButtonHandler } from "../admin/pronouns.js";
import { settingsButtonHandler } from "./polls/pollsHandlers.js";
import { pollSelectMenuHandler } from "./polls/pollsSelectMenu.js";
import { allRolesButtonHandler } from "./allRoles.js";
import { announceButtonHandler } from "./announce.js";
import { eventRolesButtonHandler } from "./eventRoles.js";
import { giftButtonHandler } from "./gift/gift.js";
import { giftModalHandler } from "./gift/giftModal.js";
/**
* Create a button from ButtonBuilder
* @param {string} id Button id for recognition
* @param {?string} label Button label shown to user
* @param {string} style Button style
* @param {?string} emoji Emoji to add to button label
* @returns {ButtonBuilder}
*/
export const createButton = (id, label, style, emoji) => {
const button = new ButtonBuilder().setCustomId(id).setStyle(style);
if (label) button.setLabel(label);
if (emoji) button.setEmoji(emoji);
return button;
};
/**
* Dispatch button interaction between action functions (here gift and pronuns)
* @param {object} interaction
*/
export const buttonHandler = (interaction) => {
const { customId } = interaction;
if (customId.startsWith("gift")) giftButtonHandler(interaction);
else if (customId.startsWith("announce")) announceButtonHandler(interaction);
else if (customId.startsWith("allRoles")) allRolesButtonHandler(interaction);
else if (customId.startsWith("eventRole"))
eventRolesButtonHandler(interaction);
else if (customId.startsWith("polls_set")) settingsButtonHandler(interaction);
else if (customId.startsWith("polls"))
return; //poll vote buttons, handled in pollsCollectors.js
else if (customId.startsWith("pronouns")) pronounsButtonHandler(interaction);
else interactionReply(interaction, "ERROR 404");
};
/**
* Dispatch selectMenu interactions between corresponding functions
* @param {object} interaction
*/
export const selectMenuHandler = (interaction) => {
const { customId } = interaction;
console.log("menuHandler", customId);
if (customId.startsWith("polls_selectMenu"))
pollSelectMenuHandler(interaction);
};
export const modalHandler = (interaction) => {
const { customId } = interaction;
console.log("modal handler", customId);
if (customId.startsWith("gift_modal")) giftModalHandler(interaction);
else {
console.warn("modal handler not found!", interaction);
interactionReply(interaction, "ERROR - contactez une Sentinelle.");
}
};