diff options
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/listeners/bush/supportThread.ts | 63 | ||||
-rw-r--r-- | src/listeners/message/autoThread.ts | 65 | ||||
-rw-r--r-- | yarn.lock | 16 |
4 files changed, 81 insertions, 65 deletions
diff --git a/package.json b/package.json index 05ad67a..9d4ffd4 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "@sentry/tracing": "^6.18.1", "canvas": "^2.9.0", "chalk": "^5.0.0", + "common-tags": "^1.8.2", "deep-lock": "^1.0.0", "discord-akairo": "npm:@notenoughupdates/discord-akairo@dev", "discord-api-types": "0.27.3", @@ -90,6 +91,7 @@ "devDependencies": { "@sapphire/snowflake": "^3.1.0", "@sentry/types": "^6.18.1", + "@types/common-tags": "^1", "@types/eslint": "^8.4.1", "@types/express": "^4.17.13", "@types/lodash": "^4.14.179", diff --git a/src/listeners/bush/supportThread.ts b/src/listeners/bush/supportThread.ts new file mode 100644 index 0000000..d408eef --- /dev/null +++ b/src/listeners/bush/supportThread.ts @@ -0,0 +1,63 @@ +import { BushListener, BushTextChannel, type BushClientEvents } from '#lib'; +import assert from 'assert'; +import { stripIndent } from 'common-tags'; +import { Embed, MessageType, PermissionFlagsBits } from 'discord.js'; + +export default class SupportThreadListener extends BushListener { + public constructor() { + super('supportThread', { + emitter: 'client', + event: 'messageCreate', + category: 'bush' + }); + } + + public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<Promise<void> | undefined> { + if (!client.config.isProduction || !message.inGuild()) return; + if (![MessageType.Default, MessageType.Reply].includes(message.type)) return; + if (message.thread) return; + if (message.author.bot && (message.author.id !== '444871677176709141' || !message.content.includes('uploaded a log,'))) + return; + + if (message.guild.id !== '516977525906341928') return; // mb + if (message.channel.id !== '714332750156660756') return; // neu-support + + if ( + [await message.guild.getSetting('prefix'), `<@!${client.user!.id}>`, `<@${client.user!.id}>`].some((v) => + message.content.trim().startsWith(v) + ) && + client.commandHandler.aliases.some((alias) => message.content.includes(alias)) + ) + return; + + assert(message.channel instanceof BushTextChannel); + + if (!message.channel.permissionsFor(message.guild.me!).has(PermissionFlagsBits.CreatePublicThreads)) return; + const thread = await message + .startThread({ + name: `Support - ${message.author.username}#${message.author.discriminator}`, + autoArchiveDuration: 60, + reason: 'Support Thread' + }) + .catch(() => null); + if (!thread) return; + const embed = new Embed() + .setTitle('NotEnoughUpdates Support') + .setDescription( + stripIndent` + Welcome to Moulberry Bush Support:tm: + + Please make sure you have the latest version found in <#693586404256645231>. + Additionally if you need help installing the mod be sure to read <#737444942724726915> for a guide on how to do so.` + ) + .setColor(util.colors.Blurple); + void thread + .send({ embeds: [embed] }) + .then(() => + client.console.info( + 'supportThread', + `opened a support thread for <<${message.author.tag}>> in <<${message.channel.name}>> in <<${message.guild!.name}>>.` + ) + ); + } +} diff --git a/src/listeners/message/autoThread.ts b/src/listeners/message/autoThread.ts deleted file mode 100644 index 540f479..0000000 --- a/src/listeners/message/autoThread.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { BushListener, type BushClientEvents, type BushTextChannel } from '#lib'; -import { Embed, GuildTextBasedChannel, MessageType, PermissionFlagsBits } from 'discord.js'; - -export default class autoThreadListener extends BushListener { - public constructor() { - super('autoThread', { - emitter: 'client', - event: 'messageCreate', - category: 'message' - }); - } - - public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<Promise<void> | undefined> { - if (!client.config.isProduction) return; - if (!message.guild || !message.channel) return; - if (![MessageType.Default, MessageType.Reply].includes(message.type)) return; - if ( - message.author.bot && - message.author.id === '444871677176709141' && //fire - message.content.includes('has been banished from') && - message.content.includes('<:yes:822211477624586260>') - ) - return; - - if ( - (message.content.trim().startsWith(await message.guild.getSetting('prefix')) || - message.content.trim().startsWith(`<@!${client.user!.id}>`) || - message.content.trim().startsWith(`<@${client.user!.id}>`)) && - client.commandHandler.aliases.some((alias) => message.content.includes(alias)) - ) - return; - - if (message.thread) 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(PermissionFlagsBits.CreatePublicThreads)) - return; - const thread = await message - .startThread({ - name: `Support - ${message.author.username}#${message.author.discriminator}`, - autoArchiveDuration: 60, - reason: 'Support Thread' - }) - .catch(() => null); - if (!thread) return; - const embed = new Embed() - .setTitle('NotEnoughUpdates Support') - .setDescription( - `Welcome to Moulberry Bush Support:tm:\n\nPlease make sure you have the latest version 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(util.colors.Blurple); - void thread - .send({ embeds: [embed] }) - .then(() => - client.console.info( - 'supportThread', - `opened a support thread for <<${message.author.tag}>> in <<${(message.channel as GuildTextBasedChannel).name}>> in <<${ - message.guild!.name - }>>.` - ) - ); - } -} @@ -347,6 +347,13 @@ __metadata: languageName: node linkType: hard +"@types/common-tags@npm:^1": + version: 1.8.1 + resolution: "@types/common-tags@npm:1.8.1" + checksum: bec6f68c8c434834380abd1dc057aa6ba26661bb0c65c700b65049e9b104d7be96a987d93dbe8726be68554a23a52514a6967d8903fdb51fb8c78cf909d1e4c1 + languageName: node + linkType: hard + "@types/connect@npm:*": version: 3.4.35 resolution: "@types/connect@npm:3.4.35" @@ -962,6 +969,7 @@ __metadata: "@sentry/node": ^6.18.1 "@sentry/tracing": ^6.18.1 "@sentry/types": ^6.18.1 + "@types/common-tags": ^1 "@types/eslint": ^8.4.1 "@types/express": ^4.17.13 "@types/lodash": ^4.14.179 @@ -977,6 +985,7 @@ __metadata: "@typescript-eslint/parser": ^5.13.0 canvas: ^2.9.0 chalk: ^5.0.0 + common-tags: ^1.8.2 deep-lock: ^1.0.0 discord-akairo: "npm:@notenoughupdates/discord-akairo@dev" discord-api-types: 0.27.3 @@ -1157,6 +1166,13 @@ __metadata: languageName: node linkType: hard +"common-tags@npm:^1.8.2": + version: 1.8.2 + resolution: "common-tags@npm:1.8.2" + checksum: 767a6255a84bbc47df49a60ab583053bb29a7d9687066a18500a516188a062c4e4cd52de341f22de0b07062e699b1b8fe3cfa1cb55b241cb9301aeb4f45b4dff + languageName: node + linkType: hard + "complex.js@npm:^2.0.15": version: 2.0.15 resolution: "complex.js@npm:2.0.15" |