3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-17 11:25:03 +00:00

refactor: don't create 'name' property in config dynamically

This commit is contained in:
Dragory 2024-11-10 13:47:40 +02:00
parent 0810dd3f0e
commit 395a750e9d
No known key found for this signature in database
19 changed files with 86 additions and 154 deletions

View file

@ -6,26 +6,26 @@ import { applyRoleButtons } from "./applyRoleButtons.js";
export async function applyAllRoleButtons(pluginData: GuildPluginData<RoleButtonsPluginType>) {
const savedRoleButtons = await pluginData.state.roleButtons.getSavedRoleButtons();
const config = pluginData.config.get();
for (const buttons of Object.values(config.buttons)) {
for (const [configName, configItem] of Object.entries(config.buttons)) {
// Use the hash of the config to quickly check if we need to update buttons
const hash = createHash("md5").update(JSON.stringify(buttons)).digest("hex");
const savedButtonsItem = savedRoleButtons.find((bt) => bt.name === buttons.name);
const hash = createHash("md5").update(JSON.stringify(configItem)).digest("hex");
const savedButtonsItem = savedRoleButtons.find((bt) => bt.name === configName);
if (savedButtonsItem?.hash === hash) {
// No changes
continue;
}
if (savedButtonsItem) {
await pluginData.state.roleButtons.deleteRoleButtonItem(buttons.name);
await pluginData.state.roleButtons.deleteRoleButtonItem(configName);
}
const applyResult = await applyRoleButtons(pluginData, buttons, savedButtonsItem ?? null);
const applyResult = await applyRoleButtons(pluginData, configItem, configName, savedButtonsItem ?? null);
if (!applyResult) {
return;
}
await pluginData.state.roleButtons.saveRoleButtonItem(
buttons.name,
configName,
applyResult.channel_id,
applyResult.message_id,
hash,