3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-07 16: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,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);