feat: add member cache; handle all role changes with RoleManagerPlugin; exit gracefully

This commit is contained in:
Dragory 2023-05-07 17:56:55 +03:00
parent fd60a09947
commit fa50110766
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
48 changed files with 755 additions and 264 deletions

View file

@ -1,10 +1,13 @@
import { GuildMember } from "discord.js";
import { guildPluginEventListener } from "knub";
import { SECONDS } from "../../../utils";
import { parseCustomId } from "../../../utils/parseCustomId";
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
import { getAllRolesInButtons } from "../functions/getAllRolesInButtons";
import { RoleButtonsPluginType, TRoleButtonOption } from "../types";
const ROLE_BUTTON_CD = 5 * SECONDS;
export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginType>()({
event: "interactionCreate",
async listener({ pluginData, args }) {
@ -33,6 +36,16 @@ export const onButtonInteraction = guildPluginEventListener<RoleButtonsPluginTyp
return;
}
const cdIdentifier = `${args.interaction.user.id}-${optionIndex}`;
if (pluginData.cooldowns.isOnCooldown(cdIdentifier)) {
args.interaction.reply({
ephemeral: true,
content: "Please wait before clicking the button again",
});
return;
}
pluginData.cooldowns.setCooldown(cdIdentifier, ROLE_BUTTON_CD);
const member = args.interaction.member as GuildMember;
const role = pluginData.guild.roles.cache.get(option.role_id);
const roleName = role?.name || option.role_id;