3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

WIP: Button Reactions

This still needs some cleanup and some functionality straight up doesn't work or is only a POC
This commit is contained in:
Dark 2021-06-06 04:57:05 +02:00
parent 43c23263f0
commit 7c757d4b96
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
5 changed files with 177 additions and 0 deletions

View file

@ -0,0 +1,65 @@
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}>`);
},
});