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 836448a054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View file

@ -19,6 +19,8 @@ const defaultOptions: PluginOptions<ReactionRolesPluginType> = {
remove_user_reactions: true,
can_manage: false,
button_groups: null,
},
overrides: [
@ -68,11 +70,12 @@ export const ReactionRolesPlugin = zeppelinGuildPlugin<ReactionRolesPluginType>(
},
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) {

View file

@ -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<typeof ConfigSchema>;

View file

@ -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}`,

View file

@ -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