mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-08 00:05:01 +00:00
Merge branch '240811_application_commands_merge_2' into next
This commit is contained in:
commit
43b8017985
279 changed files with 6192 additions and 3044 deletions
|
@ -2,6 +2,7 @@ import { PluginOptions, guildPlugin } from "knub";
|
|||
import { Queue } from "../../Queue.js";
|
||||
import { GuildReactionRoles } from "../../data/GuildReactionRoles.js";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin.js";
|
||||
import { ClearReactionRolesCmd } from "./commands/ClearReactionRolesCmd.js";
|
||||
import { InitReactionRolesCmd } from "./commands/InitReactionRolesCmd.js";
|
||||
|
@ -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) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Message } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
|
||||
import { isDiscordAPIError } from "../../../utils.js";
|
||||
import { reactionRolesCmd } from "../types.js";
|
||||
|
||||
|
@ -15,7 +14,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
|||
async run({ message: msg, args, pluginData }) {
|
||||
const existingReactionRoles = pluginData.state.reactionRoles.getForMessage(args.message.messageId);
|
||||
if (!existingReactionRoles) {
|
||||
sendErrorMessage(pluginData, msg.channel, "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 +25,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
|||
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
|
||||
} catch (err) {
|
||||
if (isDiscordAPIError(err) && err.code === 50001) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Missing access to the specified message");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -35,6 +34,6 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
|||
|
||||
await targetMessage.reactions.removeAll();
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, "Reaction roles cleared");
|
||||
void pluginData.state.common.sendSuccessMessage(msg, "Reaction roles cleared");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
|
||||
import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils.js";
|
||||
import { canReadChannel } from "../../../utils/canReadChannel.js";
|
||||
import { TReactionRolePair, reactionRolesCmd } from "../types.js";
|
||||
|
@ -34,7 +33,10 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (!canReadChannel(args.message.channel, msg.member)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "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;
|
||||
}
|
||||
|
||||
|
@ -43,7 +45,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
|
||||
} catch (e) {
|
||||
if (isDiscordAPIError(e)) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Error ${e.code} while getting message: ${e.message}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Error ${e.code} while getting message: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -71,30 +73,28 @@ 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) {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
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])) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Invalid emoji: ${pair[0]}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Invalid emoji: ${pair[0]}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!canUseEmoji(pluginData.client, pair[0])) {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
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)) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Unknown role ${pair[1]}`);
|
||||
void pluginData.state.common.sendErrorMessage(msg, `Unknown role ${pair[1]}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -125,9 +125,9 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
|||
);
|
||||
|
||||
if (errors?.length) {
|
||||
sendErrorMessage(pluginData, msg.channel, `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 {
|
||||
sendSuccessMessage(pluginData, msg.channel, "Reaction roles added");
|
||||
void pluginData.state.common.sendSuccessMessage(msg, "Reaction roles added");
|
||||
}
|
||||
|
||||
(await progressMessage).delete().catch(noop);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
|
||||
import { reactionRolesCmd } from "../types.js";
|
||||
import { refreshReactionRoles } from "../util/refreshReactionRoles.js";
|
||||
|
||||
|
@ -13,12 +12,12 @@ export const RefreshReactionRolesCmd = reactionRolesCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (pluginData.state.pendingRefreshes.has(`${args.message.channel.id}-${args.message.messageId}`)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "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);
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, "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.js";
|
||||
import { GuildReactionRoles } from "../../data/GuildReactionRoles.js";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages.js";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin.js";
|
||||
|
||||
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