From 44d68bf608a5a3e3b82d049a77b4d5e94f992778 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 23 Apr 2022 22:55:04 +0300 Subject: [PATCH 1/4] fix: fix error when trying to fetch an unknown channel in role buttons --- .../src/plugins/RoleButtons/functions/applyRoleButtons.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts b/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts index b3fc76f4..bbd290a2 100644 --- a/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts +++ b/backend/src/plugins/RoleButtons/functions/applyRoleButtons.ts @@ -18,7 +18,7 @@ export async function applyRoleButtons( // Remove existing role buttons, if any if (existingSavedButtons?.channel_id) { - const existingChannel = await pluginData.guild.channels.fetch(configItem.message.channel_id); + const existingChannel = await pluginData.guild.channels.fetch(configItem.message.channel_id).catch(() => null); const existingMessage = await (existingChannel?.isText() && existingChannel.messages.fetch(existingSavedButtons.message_id).catch(() => null)); if (existingMessage && existingMessage.components.length) { @@ -31,7 +31,7 @@ export async function applyRoleButtons( // Find or create message for role buttons if ("message_id" in configItem.message) { // channel id + message id: apply role buttons to existing message - const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id); + const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id).catch(() => null); const messageCandidate = await (channel?.isText() && channel.messages.fetch(configItem.message.message_id).catch(() => null)); if (!messageCandidate) { @@ -54,7 +54,7 @@ export async function applyRoleButtons( return null; } - const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id); + const channel = await pluginData.guild.channels.fetch(configItem.message.channel_id).catch(() => null); if (!channel || !channel.isText()) { pluginData.getPlugin(LogsPlugin).logBotAlert({ body: `Text channel not found for role_buttons/${configItem.name}`, From d93097306c14288ac5043684247240ca421a2580 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 23 Apr 2022 23:26:16 +0300 Subject: [PATCH 2/4] fix: allow servers with button_groups in their reaction_roles config to load with a warning --- .../src/plugins/ReactionRoles/ReactionRolesPlugin.ts | 11 ++++++----- backend/src/plugins/ReactionRoles/types.ts | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts index 523ab7bd..6767e965 100644 --- a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts +++ b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts @@ -68,11 +68,12 @@ export const ReactionRolesPlugin = zeppelinGuildPlugin( }, afterLoad(pluginData) { - // let autoRefreshInterval = pluginData.config.get().auto_refresh_interval; - // if (autoRefreshInterval != null) { - // autoRefreshInterval = Math.max(MIN_AUTO_REFRESH, autoRefreshInterval); - // autoRefreshLoop(pluginData, autoRefreshInterval); - // } + const config = pluginData.config.get(); + if (config.button_groups) { + pluginData.getPlugin(LogsPlugin).logBotAlert({ + body: "The 'button_groups' option of the 'reaction_roles' plugin is deprecated and non-functional. Consider using the new 'role_buttons' plugin instead!", + }); + } }, beforeUnload(pluginData) { diff --git a/backend/src/plugins/ReactionRoles/types.ts b/backend/src/plugins/ReactionRoles/types.ts index d77b71fb..412d798a 100644 --- a/backend/src/plugins/ReactionRoles/types.ts +++ b/backend/src/plugins/ReactionRoles/types.ts @@ -3,11 +3,13 @@ import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub import { GuildReactionRoles } from "../../data/GuildReactionRoles"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { Queue } from "../../Queue"; +import { tNullable } from "../../utils"; export const ConfigSchema = t.type({ auto_refresh_interval: t.number, remove_user_reactions: t.boolean, can_manage: t.boolean, + button_groups: tNullable(t.unknown), }); export type TConfigSchema = t.TypeOf; From ef78fbc0654fce071ba3eb8af9f93202b65afeb9 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 24 Apr 2022 02:55:35 +0300 Subject: [PATCH 3/4] fix: fix crash when custom id data is not valid JSON --- backend/src/utils/parseCustomId.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/src/utils/parseCustomId.ts b/backend/src/utils/parseCustomId.ts index 2d95a3a1..7988e5ef 100644 --- a/backend/src/utils/parseCustomId.ts +++ b/backend/src/utils/parseCustomId.ts @@ -1,3 +1,5 @@ +import { logger } from "../logger"; + const customIdFormat = /^([^:]+):\d+:(.*)$/; export function parseCustomId(customId: string): { namespace: string; data: any } { @@ -9,6 +11,17 @@ export function parseCustomId(customId: string): { namespace: string; data: any }; } + let parsedData: any; + try { + parsedData = JSON.parse(parts[2]); + } catch (err) { + logger.debug(`Error while parsing custom id data (custom id: ${customId}): ${String(err)}`); + return { + namespace: "", + data: null, + }; + } + return { namespace: parts[1], // Skipping timestamp From 8445c37f6410683b7b1b53811cf49eee61b9068a Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 24 Apr 2022 02:56:13 +0300 Subject: [PATCH 4/4] chore: add default value for no-op button_groups option to stop TS from complaining --- backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts index 6767e965..53068bdc 100644 --- a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts +++ b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts @@ -19,6 +19,8 @@ const defaultOptions: PluginOptions = { remove_user_reactions: true, can_manage: false, + + button_groups: null, }, overrides: [