diff --git a/src/plugins/Slowmode.ts b/src/plugins/Slowmode.ts index 9b463509..5745a653 100644 --- a/src/plugins/Slowmode.ts +++ b/src/plugins/Slowmode.ts @@ -1,9 +1,11 @@ import { decorators as d, IPluginOptions } from "knub"; import { GuildChannel, Message, TextChannel, Constants as ErisConstants, User } from "eris"; -import { convertDelayStringToMS, errorMessage, noop, successMessage } from "../utils"; +import { convertDelayStringToMS, createChunkedMessage, errorMessage, noop, successMessage } from "../utils"; import { GuildSlowmodes } from "../data/GuildSlowmodes"; import humanizeDuration from "humanize-duration"; import { ZeppelinPlugin } from "./ZeppelinPlugin"; +import { SavedMessage } from "../data/entities/SavedMessage"; +import { GuildSavedMessages } from "../data/GuildSavedMessages"; interface ISlowmodePluginConfig { use_native_slowmode: boolean; @@ -18,8 +20,11 @@ export class SlowmodePlugin extends ZeppelinPlugin { return { config: { @@ -45,11 +50,16 @@ export class SlowmodePlugin extends ZeppelinPlugin this.clearExpiredSlowmodes(), 2000); + + this.onMessageCreateFn = this.onMessageCreate.bind(this); + this.savedMessages.events.on("create", this.onMessageCreateFn); } onUnload() { clearInterval(this.clearInterval); + this.savedMessages.events.off("create", this.onMessageCreateFn); } /** @@ -174,6 +184,44 @@ export class SlowmodePlugin extends ZeppelinPlugin = []; + + for (const channel of channels.values()) { + if (!(channel instanceof TextChannel)) continue; + + // Bot slowmode + const botSlowmode = await this.slowmodes.getChannelSlowmode(channel.id); + if (botSlowmode) { + slowmodes.push({ channel, seconds: botSlowmode.slowmode_seconds, native: false }); + continue; + } + + // Native slowmode + if (channel.rateLimitPerUser) { + slowmodes.push({ channel, seconds: channel.rateLimitPerUser, native: true }); + continue; + } + } + + if (slowmodes.length) { + const lines = slowmodes.map(slowmode => { + const humanized = humanizeDuration(slowmode.seconds * 1000); + + const type = slowmode.native ? "native slowmode" : "bot slowmode"; + + return `<#${slowmode.channel.id}> **${humanized}** ${type}`; + }); + + createChunkedMessage(msg.channel, lines.join("\n")); + } else { + msg.channel.createMessage(errorMessage("No active slowmodes!")); + } + } + /** * COMMAND: Set slowmode for the specified channel */ @@ -229,21 +277,39 @@ export class SlowmodePlugin extends ZeppelinPlugin