mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Make message with default buttons stateful
This commit is contained in:
parent
5efdf5ce95
commit
5c7c3c8cba
10 changed files with 158 additions and 47 deletions
|
@ -0,0 +1,41 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { ReactionRolesPluginType } from "../types";
|
||||
import { ButtonMenuActions } from "./buttonMenuActions";
|
||||
|
||||
export const BUTTON_CONTEXT_SEPARATOR = "::";
|
||||
|
||||
export async function getButtonAction(pluginData: GuildPluginData<ReactionRolesPluginType>, roleOrMenu: string) {
|
||||
if (await pluginData.guild.roles.fetch(roleOrMenu)) {
|
||||
return ButtonMenuActions.GRANT_ROLE;
|
||||
} else {
|
||||
return ButtonMenuActions.OPEN_MENU;
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateStatelessCustomId(
|
||||
pluginData: GuildPluginData<ReactionRolesPluginType>,
|
||||
groupName: string,
|
||||
roleOrMenu: string,
|
||||
) {
|
||||
let id = groupName + BUTTON_CONTEXT_SEPARATOR;
|
||||
|
||||
id += `${await getButtonAction(pluginData, roleOrMenu)}${BUTTON_CONTEXT_SEPARATOR}${roleOrMenu}`;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
export async function resolveStatefulCustomId(pluginData: GuildPluginData<ReactionRolesPluginType>, id: string) {
|
||||
const button = await pluginData.state.buttonRoles.getForButtonId(id);
|
||||
|
||||
if (button) {
|
||||
const group = pluginData.config.get().button_groups[button.button_group];
|
||||
const cfgButton = group.default_buttons[button.button_name];
|
||||
|
||||
return {
|
||||
groupName: button.button_group,
|
||||
action: await getButtonAction(pluginData, cfgButton.role_or_menu),
|
||||
roleOrMenu: cfgButton.role_or_menu,
|
||||
stateless: false,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue