From b7f254cd426138880318d2ba6a06e8e86ae407bf Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 26 Aug 2021 13:43:22 -0400 Subject: finished feature command and did some refactoring --- src/listeners/message/autoPublisher.ts | 2 +- src/listeners/message/autoThread.ts | 44 ++++++++++++++++++++++++++++++++ src/listeners/message/automodCreate.ts | 4 +-- src/listeners/message/blacklistedFile.ts | 8 +----- src/listeners/message/booster.ts | 20 --------------- src/listeners/message/boosterMessage.ts | 21 +++++++++++++++ src/listeners/message/level.ts | 9 +++---- src/listeners/message/supportThreads.ts | 44 -------------------------------- src/listeners/message/verbose.ts | 2 +- 9 files changed, 73 insertions(+), 81 deletions(-) create mode 100644 src/listeners/message/autoThread.ts delete mode 100644 src/listeners/message/booster.ts create mode 100644 src/listeners/message/boosterMessage.ts delete mode 100644 src/listeners/message/supportThreads.ts (limited to 'src/listeners/message') diff --git a/src/listeners/message/autoPublisher.ts b/src/listeners/message/autoPublisher.ts index a1d61f7..1be58a3 100644 --- a/src/listeners/message/autoPublisher.ts +++ b/src/listeners/message/autoPublisher.ts @@ -11,7 +11,7 @@ export default class autoPublisherListener extends BushListener { } public override async exec(...[message]: BushClientEvents['messageCreate']): Promise { - if (!message.guild) return; + if (!message.guild || !(await message.guild.hasFeature('autoPublish'))) return; const autoPublishChannels = await message.guild.getSetting('autoPublishChannels'); if (autoPublishChannels) { if (message.channel.type === 'GUILD_NEWS' && autoPublishChannels.some((x) => message.channel.id.includes(x))) { diff --git a/src/listeners/message/autoThread.ts b/src/listeners/message/autoThread.ts new file mode 100644 index 0000000..eb54554 --- /dev/null +++ b/src/listeners/message/autoThread.ts @@ -0,0 +1,44 @@ +import { GuildTextBasedChannels } from 'discord-akairo'; +import { MessageEmbed } from 'discord.js'; +import { BushListener, BushTextChannel } from '../../lib'; +import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; + +export default class autoThreadListener extends BushListener { + public constructor() { + super('autoThread', { + emitter: 'client', + event: 'messageCreate', + category: 'message' + }); + } + + public override async exec(...[message]: BushClientEvents['messageCreate']): Promise | undefined> { + if (client.config.isDevelopment) return; + if (!message.guild || !message.channel) return; + // todo: make these configurable etc... + if (message.guild.id !== '516977525906341928') return; // mb + if (message.channel.id !== '714332750156660756') return; // neu-support-1 + if (!(message.channel as BushTextChannel).permissionsFor(message.guild.me!).has('USE_PUBLIC_THREADS')) return; + const thread = await message.startThread({ + name: `Support - ${message.author.username}#${message.author.discriminator}`, + autoArchiveDuration: 60, + reason: 'Support Thread' + }); + const embed = new MessageEmbed() + .setTitle('NotEnoughUpdates Support') + .setDescription( + `Welcome to Moulberry Bush Support:tm:\n\nPlease make sure you have the latest prerelease found in <#693586404256645231>.\nAdditionally if you need help installing the mod be sure to read <#737444942724726915> for a guide on how to do so.` + ) + .setColor('BLURPLE'); + void thread + .send({ embeds: [embed] }) + .then(() => + client.console.info( + 'supportThread', + `opened a support thread for <<${message.author.tag}>> in <<${ + (message.channel as GuildTextBasedChannels).name + }>> in <<${message.guild!.name}>>.` + ) + ); + } +} diff --git a/src/listeners/message/automodCreate.ts b/src/listeners/message/automodCreate.ts index ca61dd0..f78efec 100644 --- a/src/listeners/message/automodCreate.ts +++ b/src/listeners/message/automodCreate.ts @@ -22,8 +22,8 @@ export default class AutomodMessageCreateListener extends BushListener { } public static async automod(message: BushMessage): Promise { - if (message.channel.type === 'DM') return; - if (message.guild?.id !== client.consts.mappings.guilds.bush) return; // just temporary + if (message.channel.type === 'DM' || !message.guild) return; + if (!(await message.guild.hasFeature('automod'))) return; /* await message.guild.getSetting('autoModPhases'); */ const badLinks: { [key: string]: number } = {}; let temp = _badLinks; diff --git a/src/listeners/message/blacklistedFile.ts b/src/listeners/message/blacklistedFile.ts index a9c5c46..5aa5477 100644 --- a/src/listeners/message/blacklistedFile.ts +++ b/src/listeners/message/blacklistedFile.ts @@ -66,13 +66,7 @@ export default class BlacklistedFileListener extends BushListener { } public override async exec(...[message]: BushClientEvents['messageCreate']): Promise { - if (!message.guild) return; - const guildWhitelist = [ - client.consts.mappings.guilds.bush, - client.consts.mappings.guilds.tree, - client.consts.mappings.guilds.space_ship - ]; - if (!guildWhitelist.includes(message.guild!.id)) return; + if (!message.guild || !(await message.guild.hasFeature('blacklistedFile'))) return; const embedAttachments = message.embeds.filter((e) => ['image', 'video', 'gifv'].includes(e.type)); const foundEmojis = [...message.content.matchAll(/<(?a?):\w+:(?\d+)>/g)]; if (message.attachments.size + embedAttachments.length + foundEmojis.length < 1) return; diff --git a/src/listeners/message/booster.ts b/src/listeners/message/booster.ts deleted file mode 100644 index 603e535..0000000 --- a/src/listeners/message/booster.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { BushListener } from '../../lib'; -import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; - -export default class BoosterMessageListener extends BushListener { - public constructor() { - super('boosterMessage', { - emitter: 'client', - event: 'messageCreate', - category: 'message' - }); - } - - public override async exec(...[message]: BushClientEvents['messageCreate']): Promise { - if (message.type === 'USER_PREMIUM_GUILD_SUBSCRIPTION' && message.guild!.id === this.client.consts.mappings.guilds.bush) { - return await message.react('<:nitroboost:785160348885975062>').catch(() => { - void this.client.console.warn('BoosterMessage', `Failed to react to <<${message.id}>>.`); - }); - } - } -} diff --git a/src/listeners/message/boosterMessage.ts b/src/listeners/message/boosterMessage.ts new file mode 100644 index 0000000..5d49661 --- /dev/null +++ b/src/listeners/message/boosterMessage.ts @@ -0,0 +1,21 @@ +import { BushListener } from '../../lib'; +import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; + +export default class BoosterMessageListener extends BushListener { + public constructor() { + super('boosterMessage', { + emitter: 'client', + event: 'messageCreate', + category: 'message' + }); + } + + public override async exec(...[message]: BushClientEvents['messageCreate']): Promise { + if (!message.guild || !(await message.guild?.hasFeature('boosterMessageReact'))) return; + if (message.type === 'USER_PREMIUM_GUILD_SUBSCRIPTION') { + return await message.react('<:nitroboost:785160348885975062>').catch(() => { + void this.client.console.warn('BoosterMessage', `Failed to react to <<${message.id}>>.`); + }); + } + } +} diff --git a/src/listeners/message/level.ts b/src/listeners/message/level.ts index 0077276..33e7b08 100644 --- a/src/listeners/message/level.ts +++ b/src/listeners/message/level.ts @@ -12,10 +12,7 @@ export default class LevelListener extends BushListener { }); } public override async exec(...[message]: BushCommandHandlerEvents['messageInvalid']): Promise { - if (message.author.bot) return; - if (!message.author) return; - if (!message.guild) return; - if (message.util?.parsed?.command) return; + if (message.author.bot || !message.author || !message.guild) return; if (this.#levelCooldowns.has(`${message.guild.id}-${message.author.id}`)) return; if (this.#blacklistedChannels.includes(message.channel.id)) return; const allowedMessageTypes: MessageType[] = ['DEFAULT', 'REPLY']; // this is so ts will yell at me when discord.js makes some unnecessary breaking change @@ -33,12 +30,12 @@ export default class LevelListener extends BushListener { }); const xpToGive = Level.genRandomizedXp(); const success = await user.increment('xp', { by: xpToGive }).catch((e) => { - void client.logger.error('LevelMessageListener', e?.stack || e); + void client.logger.error('levelMessageListener', e?.stack || e); return false; }); if (success) void client.logger.verbose( - `LevelMessageListener`, + `levelMessageListener`, `Gave <<${xpToGive}>> XP to <<${message.author.tag}>> in <<${message.guild}>>.` ); this.#levelCooldowns.add(`${message.guild.id}-${message.author.id}`); diff --git a/src/listeners/message/supportThreads.ts b/src/listeners/message/supportThreads.ts deleted file mode 100644 index 9b3ea3e..0000000 --- a/src/listeners/message/supportThreads.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { GuildTextBasedChannels } from 'discord-akairo'; -import { MessageEmbed } from 'discord.js'; -import { BushListener, BushTextChannel } from '../../lib'; -import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; - -export default class SupportThreadListener extends BushListener { - public constructor() { - super('supportThreads', { - emitter: 'client', - event: 'messageCreate', - category: 'message' - }); - } - - public override async exec(...[message]: BushClientEvents['messageCreate']): Promise | undefined> { - if (client.config.isDevelopment) return; - if (!message.guild || !message.channel) return; - // todo: make these configurable etc... - if (message.guild.id !== '516977525906341928') return; // mb - if (message.channel.id !== '714332750156660756') return; // neu-support-1 - if (!(message.channel as BushTextChannel).permissionsFor(message.guild.me!).has('USE_PUBLIC_THREADS')) return; - const thread = await message.startThread({ - name: `Support - ${message.author.username}#${message.author.discriminator}`, - autoArchiveDuration: 60, - reason: 'Support Thread' - }); - const embed = new MessageEmbed() - .setTitle('NotEnoughUpdates Support') - .setDescription( - `Welcome to Moulberry Bush Support:tm:\n\nPlease make sure you have the latest prerelease found in <#693586404256645231>.\nAdditionally if you need help installing the mod be sure to read <#737444942724726915> for a guide on how to do so.` - ) - .setColor('BLURPLE'); - void thread - .send({ embeds: [embed] }) - .then(() => - client.console.info( - 'supportThread', - `opened a support thread for <<${message.author.tag}>> in <<${ - (message.channel as GuildTextBasedChannels).name - }>> in <<${message.guild!.name}>>.` - ) - ); - } -} diff --git a/src/listeners/message/verbose.ts b/src/listeners/message/verbose.ts index f1530ce..9404412 100644 --- a/src/listeners/message/verbose.ts +++ b/src/listeners/message/verbose.ts @@ -13,7 +13,7 @@ export default class MessageVerboseListener extends BushListener { public override exec(...[message]: BushClientEvents['messageCreate']): Promise | undefined { if (message.channel?.type === 'DM') return; void this.client.console.verbose( - 'Message', + 'messageVerbose', `A message was sent by <<${message.author.tag}>> in <<${message.channel.name}>> in <<${message.guild!.name}>>.` ); } -- cgit