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:
commit
61a721a8c6
4 changed files with 26 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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>;
|
||||
|
||||
|
|
|
@ -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}`,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue