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

Fixes, refactoring and PR feedback

This commit is contained in:
Lily Bergonzat 2024-04-15 15:51:45 +02:00
parent 0be54912c4
commit 893a77d562
202 changed files with 1037 additions and 1069 deletions

View file

@ -1,4 +1,5 @@
import {
Attachment,
ChatInputCommandInteraction,
Message,
MessageCreateOptions,
@ -7,11 +8,10 @@ import {
TextBasedChannel,
User,
} from "discord.js";
import { PluginOptions } from "knub";
import { PluginOptions, guildPlugin } from "knub";
import { logger } from "../../logger";
import { isContextInteraction, sendContextResponse } from "../../pluginUtils";
import { errorMessage, successMessage } from "../../utils";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { getErrorEmoji, getSuccessEmoji } from "./functions/getEmoji";
import { CommonPluginType, zCommonConfig } from "./types";
@ -19,30 +19,21 @@ const defaultOptions: PluginOptions<CommonPluginType> = {
config: {
success_emoji: "✅",
error_emoji: "❌",
attachment_storing_channel: null,
},
};
export const CommonPlugin = zeppelinGuildPlugin<CommonPluginType>()({
export const CommonPlugin = guildPlugin<CommonPluginType>()({
name: "common",
showInDocs: false,
info: {
prettyName: "Common",
},
dependencies: () => [],
configParser: (input) => zCommonConfig.parse(input),
defaultOptions,
public: {
getSuccessEmoji(pluginData) {
return () => getSuccessEmoji(pluginData);
},
public(pluginData) {
return {
getSuccessEmoji,
getErrorEmoji,
getErrorEmoji(pluginData) {
return () => getErrorEmoji(pluginData);
},
sendSuccessMessage(pluginData) {
return async (
sendSuccessMessage: async (
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
body: string,
allowedMentions?: MessageMentionOptions,
@ -89,11 +80,9 @@ export const CommonPlugin = zeppelinGuildPlugin<CommonPluginType>()({
return undefined;
}) as Promise<Message>;
};
},
},
sendErrorMessage(pluginData) {
return async (
sendErrorMessage: async (
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
body: string,
allowedMentions?: MessageMentionOptions,
@ -140,7 +129,25 @@ export const CommonPlugin = zeppelinGuildPlugin<CommonPluginType>()({
return undefined;
}) as Promise<Message>;
};
},
},
storeAttachmentsAsMessage: async (attachments: Attachment[], backupChannel?: TextBasedChannel | null) => {
const attachmentChannelId = pluginData.config.get().attachment_storing_channel;
const channel = attachmentChannelId
? (pluginData.guild.channels.cache.get(attachmentChannelId) as TextBasedChannel) ?? backupChannel
: backupChannel;
if (!channel) {
throw new Error(
'Cannot store attachments: no attachment storing channel configured, and no backup channel passed'
);
}
return channel!.send({
content: `Storing ${attachments.length} attachment${attachments.length === 1 ? "" : "s"}`,
files: attachments.map((a) => a.url),
});
},
}
},
});