mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-08 00:05:01 +00:00
Fixes, refactoring and PR feedback
This commit is contained in:
parent
0be54912c4
commit
893a77d562
202 changed files with 1037 additions and 1069 deletions
|
@ -9,6 +9,7 @@ import { RefreshReactionRolesCmd } from "./commands/RefreshReactionRolesCmd";
|
|||
import { AddReactionRoleEvt } from "./events/AddReactionRoleEvt";
|
||||
import { MessageDeletedEvt } from "./events/MessageDeletedEvt";
|
||||
import { ReactionRolesPluginType, zReactionRolesConfig } from "./types";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin";
|
||||
|
||||
const MIN_AUTO_REFRESH = 1000 * 60 * 15; // 15min minimum, let's not abuse the API
|
||||
|
||||
|
@ -63,6 +64,10 @@ export const ReactionRolesPlugin = guildPlugin<ReactionRolesPluginType>()({
|
|||
state.pendingRefreshes = new Set();
|
||||
},
|
||||
|
||||
beforeStart(pluginData) {
|
||||
pluginData.state.common = pluginData.getPlugin(CommonPlugin);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
const config = pluginData.config.get();
|
||||
if (config.button_groups) {
|
||||
|
|
|
@ -15,7 +15,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
|||
async run({ message: msg, args, pluginData }) {
|
||||
const existingReactionRoles = pluginData.state.reactionRoles.getForMessage(args.message.messageId);
|
||||
if (!existingReactionRoles) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Message doesn't have reaction roles on it");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Message doesn't have reaction roles on it");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
|||
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
|
||||
} catch (err) {
|
||||
if (isDiscordAPIError(err) && err.code === 50001) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Missing access to the specified message");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Missing access to the specified message");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,6 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
|||
|
||||
await targetMessage.reactions.removeAll();
|
||||
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Reaction roles cleared");
|
||||
void pluginData.state.common.sendSuccessMessage(msg, "Reaction roles cleared");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -34,9 +34,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (!canReadChannel(args.message.channel, msg.member)) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, "You can't add reaction roles to channels you can't see yourself");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You can't add reaction roles to channels you can't see yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -45,7 +43,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
|
||||
} catch (e) {
|
||||
if (isDiscordAPIError(e)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Error ${e.code} while getting message: ${e.message}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Error ${e.code} while getting message: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -73,26 +71,22 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
// Verify the specified emojis and roles are valid and usable
|
||||
for (const pair of emojiRolePairs) {
|
||||
if (pair[0] === CLEAR_ROLES_EMOJI) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, `The emoji for clearing roles (${CLEAR_ROLES_EMOJI}) is reserved and cannot be used`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `The emoji for clearing roles (${CLEAR_ROLES_EMOJI}) is reserved and cannot be used`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidEmoji(pair[0])) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Invalid emoji: ${pair[0]}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Invalid emoji: ${pair[0]}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canUseEmoji(pluginData.client, pair[0])) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, "I can only use regular emojis and custom emojis from servers I'm on");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "I can only use regular emojis and custom emojis from servers I'm on");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pluginData.guild.roles.cache.has(pair[1] as Snowflake)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Unknown role ${pair[1]}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Unknown role ${pair[1]}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -123,11 +117,9 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
);
|
||||
|
||||
if (errors?.length) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, `Errors while adding reaction roles:\n${errors.join("\n")}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Errors while adding reaction roles:\n${errors.join("\n")}`);
|
||||
} else {
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Reaction roles added");
|
||||
void pluginData.state.common.sendSuccessMessage(msg, "Reaction roles added");
|
||||
}
|
||||
|
||||
(await progressMessage).delete().catch(noop);
|
||||
|
|
|
@ -13,12 +13,12 @@ export const RefreshReactionRolesCmd = reactionRolesCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (pluginData.state.pendingRefreshes.has(`${args.message.channel.id}-${args.message.messageId}`)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Another refresh in progress");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Another refresh in progress");
|
||||
return;
|
||||
}
|
||||
|
||||
await refreshReactionRoles(pluginData, args.message.channel.id, args.message.messageId);
|
||||
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Reaction roles refreshed");
|
||||
void pluginData.state.common.sendSuccessMessage(msg, "Reaction roles refreshed");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand } from "knub";
|
||||
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand, pluginUtils } from "knub";
|
||||
import z from "zod";
|
||||
import { Queue } from "../../Queue";
|
||||
import { GuildReactionRoles } from "../../data/GuildReactionRoles";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin";
|
||||
|
||||
export const zReactionRolesConfig = z.strictObject({
|
||||
auto_refresh_interval: z.number(),
|
||||
|
@ -37,6 +38,8 @@ export interface ReactionRolesPluginType extends BasePluginType {
|
|||
pendingRefreshes: Set<string>;
|
||||
|
||||
autoRefreshTimeout: NodeJS.Timeout;
|
||||
|
||||
common: pluginUtils.PluginPublicInterface<typeof CommonPlugin>;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue