
This still needs some cleanup and some functionality straight up doesn't work or is only a POC
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { reactionRolesCmd } from "../types";
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
import { MessageActionRow, MessageButton, MessageComponentInteraction, TextChannel } from "discord.js";
|
|
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
|
import moment from "moment";
|
|
import { ButtonMenuActions } from "../util/buttonMenuActions";
|
|
|
|
export const PostButtonRolesCmd = reactionRolesCmd({
|
|
trigger: "reaction_roles post",
|
|
permission: "can_manage",
|
|
|
|
signature: {
|
|
button_group: ct.string(),
|
|
},
|
|
|
|
async run({ message: msg, args, pluginData }) {
|
|
const cfg = pluginData.config.get();
|
|
const group = cfg.button_groups[args.button_group];
|
|
|
|
if (!group) {
|
|
sendErrorMessage(pluginData, msg.channel, `No button group matches the name **${args.button_group}**`);
|
|
}
|
|
|
|
const channel = pluginData.guild.channels.resolve(group.channel_id);
|
|
if (!channel) {
|
|
await sendErrorMessage(
|
|
pluginData,
|
|
msg.channel,
|
|
`The ID ${group.channel_id} does not match a channel on the server`,
|
|
);
|
|
return;
|
|
}
|
|
|
|
const buttons: MessageButton[] = [];
|
|
for (const button of Object.values(group.default_buttons)) {
|
|
let customId = "";
|
|
if ((await pluginData.guild.roles.fetch(button.role_or_menu)) != null) {
|
|
// TODO: Make universal, currently can only handle custom emoji and not default ones
|
|
customId = `${args.button_group}::${ButtonMenuActions.GRANT_ROLE}::${button.role_or_menu}`;
|
|
} else {
|
|
customId = `${args.button_group}::${ButtonMenuActions.OPEN_MENU}::${button.role_or_menu}`;
|
|
}
|
|
|
|
const btn = new MessageButton()
|
|
.setLabel(button.label)
|
|
.setStyle("PRIMARY")
|
|
.setType("BUTTON")
|
|
.setCustomID(customId);
|
|
|
|
const emo = pluginData.client.emojis.resolve(button.emoji);
|
|
if (emo) btn.setEmoji(emo);
|
|
|
|
buttons.push(btn);
|
|
}
|
|
const row = new MessageActionRow().addComponents(buttons);
|
|
|
|
try {
|
|
await (channel as TextChannel).send({ content: group.message, components: [row], split: false });
|
|
} catch (e) {
|
|
sendErrorMessage(pluginData, msg.channel, `Error trying to post message: ${e}`);
|
|
return;
|
|
}
|
|
await sendSuccessMessage(pluginData, msg.channel, `Successfully posted message in <#${channel.id}>`);
|
|
},
|
|
});
|