3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 10:25:01 +00:00

Merge branch 'ZeppelinBot:master' into master

This commit is contained in:
Ruby 2022-04-27 18:08:25 +04:00 committed by GitHub
commit 61a721a8c6
4 changed files with 26 additions and 8 deletions

View file

@ -19,6 +19,8 @@ const defaultOptions: PluginOptions<ReactionRolesPluginType> = {
remove_user_reactions: true, remove_user_reactions: true,
can_manage: false, can_manage: false,
button_groups: null,
}, },
overrides: [ overrides: [
@ -68,11 +70,12 @@ export const ReactionRolesPlugin = zeppelinGuildPlugin<ReactionRolesPluginType>(
}, },
afterLoad(pluginData) { afterLoad(pluginData) {
// let autoRefreshInterval = pluginData.config.get().auto_refresh_interval; const config = pluginData.config.get();
// if (autoRefreshInterval != null) { if (config.button_groups) {
// autoRefreshInterval = Math.max(MIN_AUTO_REFRESH, autoRefreshInterval); pluginData.getPlugin(LogsPlugin).logBotAlert({
// autoRefreshLoop(pluginData, autoRefreshInterval); 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) { beforeUnload(pluginData) {

View file

@ -3,11 +3,13 @@ import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub
import { GuildReactionRoles } from "../../data/GuildReactionRoles"; import { GuildReactionRoles } from "../../data/GuildReactionRoles";
import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { Queue } from "../../Queue"; import { Queue } from "../../Queue";
import { tNullable } from "../../utils";
export const ConfigSchema = t.type({ export const ConfigSchema = t.type({
auto_refresh_interval: t.number, auto_refresh_interval: t.number,
remove_user_reactions: t.boolean, remove_user_reactions: t.boolean,
can_manage: t.boolean, can_manage: t.boolean,
button_groups: tNullable(t.unknown),
}); });
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>; export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;

View file

@ -18,7 +18,7 @@ export async function applyRoleButtons(
// Remove existing role buttons, if any // Remove existing role buttons, if any
if (existingSavedButtons?.channel_id) { 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() && const existingMessage = await (existingChannel?.isText() &&
existingChannel.messages.fetch(existingSavedButtons.message_id).catch(() => null)); existingChannel.messages.fetch(existingSavedButtons.message_id).catch(() => null));
if (existingMessage && existingMessage.components.length) { if (existingMessage && existingMessage.components.length) {
@ -31,7 +31,7 @@ export async function applyRoleButtons(
// Find or create message for role buttons // Find or create message for role buttons
if ("message_id" in configItem.message) { if ("message_id" in configItem.message) {
// channel id + message id: apply role buttons to existing 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() && const messageCandidate = await (channel?.isText() &&
channel.messages.fetch(configItem.message.message_id).catch(() => null)); channel.messages.fetch(configItem.message.message_id).catch(() => null));
if (!messageCandidate) { if (!messageCandidate) {
@ -54,7 +54,7 @@ export async function applyRoleButtons(
return null; 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()) { if (!channel || !channel.isText()) {
pluginData.getPlugin(LogsPlugin).logBotAlert({ pluginData.getPlugin(LogsPlugin).logBotAlert({
body: `Text channel not found for role_buttons/${configItem.name}`, body: `Text channel not found for role_buttons/${configItem.name}`,

View file

@ -1,3 +1,5 @@
import { logger } from "../logger";
const customIdFormat = /^([^:]+):\d+:(.*)$/; const customIdFormat = /^([^:]+):\d+:(.*)$/;
export function parseCustomId(customId: string): { namespace: string; data: any } { 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 { return {
namespace: parts[1], namespace: parts[1],
// Skipping timestamp // Skipping timestamp