mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-11 13:07:20 +00:00
chore: remove old button roles implementation
This commit is contained in:
parent
49aa4d2c5e
commit
5f9af82943
12 changed files with 50 additions and 450 deletions
|
@ -1,4 +1,4 @@
|
|||
import { Message, Snowflake } from "discord.js";
|
||||
import { Message } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { isDiscordAPIError } from "../../../utils";
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
import { createHash } from "crypto";
|
||||
import { MessageButton, Snowflake } from "discord.js";
|
||||
import moment from "moment";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { reactionRolesCmd } from "../types";
|
||||
import { splitButtonsIntoRows } from "../util/splitButtonsIntoRows";
|
||||
|
||||
export const PostButtonRolesCmd = reactionRolesCmd({
|
||||
trigger: "reaction_roles post",
|
||||
permission: "can_manage",
|
||||
|
||||
signature: {
|
||||
channel: ct.textChannel(),
|
||||
buttonGroup: ct.string(),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const cfg = pluginData.config.get();
|
||||
if (!cfg.button_groups) {
|
||||
sendErrorMessage(pluginData, msg.channel, "No button groups defined in config");
|
||||
return;
|
||||
}
|
||||
const group = cfg.button_groups[args.buttonGroup];
|
||||
|
||||
if (!group) {
|
||||
sendErrorMessage(pluginData, msg.channel, `No button group matches the name **${args.buttonGroup}**`);
|
||||
return;
|
||||
}
|
||||
|
||||
const buttons: MessageButton[] = [];
|
||||
const toInsert: Array<{ customId; buttonGroup; buttonName }> = [];
|
||||
for (const [buttonName, button] of Object.entries(group.default_buttons)) {
|
||||
const customId = createHash("md5").update(`${buttonName}${moment.utc().valueOf()}`).digest("hex");
|
||||
|
||||
const btn = new MessageButton()
|
||||
.setLabel(button.label ?? "")
|
||||
.setStyle(button.style ?? "PRIMARY")
|
||||
.setCustomId(customId)
|
||||
.setDisabled(button.disabled ?? false);
|
||||
|
||||
if (button.emoji) {
|
||||
const emo = pluginData.client.emojis.resolve(button.emoji as Snowflake) ?? button.emoji;
|
||||
btn.setEmoji(emo);
|
||||
}
|
||||
|
||||
buttons.push(btn);
|
||||
toInsert.push({ customId, buttonGroup: args.buttonGroup, buttonName });
|
||||
}
|
||||
const rows = splitButtonsIntoRows(buttons, Object.values(group.default_buttons)); // new MessageActionRow().addComponents(buttons);
|
||||
|
||||
try {
|
||||
const newMsg = await args.channel.send({ content: group.message, components: rows });
|
||||
|
||||
for (const btn of toInsert) {
|
||||
await pluginData.state.buttonRoles.add(
|
||||
args.channel.id,
|
||||
newMsg.id,
|
||||
btn.customId,
|
||||
btn.buttonGroup,
|
||||
btn.buttonName,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Error trying to post message: ${e}`);
|
||||
return;
|
||||
}
|
||||
|
||||
await sendSuccessMessage(pluginData, msg.channel, `Successfully posted message in <#${args.channel.id}>`);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue