diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index f3a3b6af..beff3e22 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -16,6 +16,7 @@ import { ucfirst, UnknownUser, UserNotificationMethod, + trimLines, } from "../utils"; import humanizeDuration from "humanize-duration"; import { LogType } from "../data/LogType"; @@ -28,6 +29,7 @@ import { CaseArgs, CasesPlugin } from "./Cases"; import { Case } from "../data/entities/Case"; import * as t from "io-ts"; import { ERRORS, RecoverablePluginError } from "../RecoverablePluginError"; +import { GuildArchives } from "src/data/GuildArchives"; const ConfigSchema = t.type({ mute_role: tNullable(t.string), @@ -83,6 +85,7 @@ export class MutesPlugin extends ZeppelinPlugin { protected cases: GuildCases; protected serverLogs: GuildLogs; private muteClearIntervalId: NodeJS.Timer; + archives: GuildArchives; public static getStaticDefaultOptions(): IPluginOptions { return { @@ -123,6 +126,7 @@ export class MutesPlugin extends ZeppelinPlugin { this.mutes = GuildMutes.getGuildInstance(this.guildId); this.cases = GuildCases.getGuildInstance(this.guildId); this.serverLogs = new GuildLogs(this.guildId); + this.archives = GuildArchives.getGuildInstance(this.guildId); // Check for expired mutes every 5s const firstCheckTime = Math.max(Date.now(), FIRST_CHECK_TIME) + FIRST_CHECK_INCREMENT; @@ -380,10 +384,15 @@ export class MutesPlugin extends ZeppelinPlugin { name: "left", isSwitch: true, }, + { + name: "export", + shortcut: "e", + isSwitch: true, + }, ], }) @d.permission("can_view_list") - protected async muteListCmd(msg: Message, args: { age?: number; left?: boolean }) { + protected async muteListCmd(msg: Message, args: { age?: number; left?: boolean; export?: boolean }) { const lines = []; // Create a loading message as this can potentially take some time @@ -507,6 +516,15 @@ export class MutesPlugin extends ZeppelinPlugin { message = hasFilters ? "No mutes found with the specified filters!" : "No active mutes!"; } + if (args.export) { + const archiveId = await this.archives.create(trimLines(message), moment().add(1, "hour")); + const url = await this.archives.getUrl(this.knub.getGlobalConfig().url, archiveId); + + await msg.channel.createMessage(`Exported mutes results: ${url}`); + + return; + } + await loadingMessage.delete().catch(noop); const chunks = chunkMessageLines(message); for (const chunk of chunks) {