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

Added Discord attachment link reaction, fixed emoji configuration and moved util functions

This commit is contained in:
Lily Bergonzat 2024-02-16 11:51:58 +01:00
parent a4c4b17a14
commit 592d037148
173 changed files with 1540 additions and 1170 deletions

View file

@ -1,7 +1,7 @@
import { Message } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isDiscordAPIError } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { reactionRolesCmd } from "../types";
export const ClearReactionRolesCmd = reactionRolesCmd({
@ -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) {
sendErrorMessage(pluginData, msg.channel, "Message doesn't have reaction roles on it");
pluginData.getPlugin(CommonPlugin).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) {
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Missing access to the specified message");
return;
}
@ -35,6 +35,6 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
await targetMessage.reactions.removeAll();
sendSuccessMessage(pluginData, msg.channel, "Reaction roles cleared");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Reaction roles cleared");
},
});

View file

@ -1,8 +1,8 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { TReactionRolePair, reactionRolesCmd } from "../types";
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage";
@ -34,7 +34,9 @@ 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");
pluginData
.getPlugin(CommonPlugin)
.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}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Error ${e.code} while getting message: ${e.message}`);
return;
}
@ -71,30 +73,26 @@ 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,
`The emoji for clearing roles (${CLEAR_ROLES_EMOJI}) is reserved and cannot be used`,
);
pluginData
.getPlugin(CommonPlugin)
.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]}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Invalid emoji: ${pair[0]}`);
return;
}
if (!canUseEmoji(pluginData.client, pair[0])) {
sendErrorMessage(
pluginData,
msg.channel,
"I can only use regular emojis and custom emojis from servers I'm on",
);
pluginData
.getPlugin(CommonPlugin)
.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]}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Unknown role ${pair[1]}`);
return;
}
}
@ -125,9 +123,11 @@ export const InitReactionRolesCmd = reactionRolesCmd({
);
if (errors?.length) {
sendErrorMessage(pluginData, msg.channel, `Errors while adding reaction roles:\n${errors.join("\n")}`);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `Errors while adding reaction roles:\n${errors.join("\n")}`);
} else {
sendSuccessMessage(pluginData, msg.channel, "Reaction roles added");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Reaction roles added");
}
(await progressMessage).delete().catch(noop);

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { reactionRolesCmd } from "../types";
import { refreshReactionRoles } from "../util/refreshReactionRoles";
@ -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}`)) {
sendErrorMessage(pluginData, msg.channel, "Another refresh in progress");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Another refresh in progress");
return;
}
await refreshReactionRoles(pluginData, args.message.channel.id, args.message.messageId);
sendSuccessMessage(pluginData, msg.channel, "Reaction roles refreshed");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Reaction roles refreshed");
},
});