diff --git a/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts b/backend/src/plugins/ReactionRoles/ReactionRolesPlugin.ts index 523ab7bd..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: [ @@ -68,11 +70,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; 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}`, 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