diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-29 21:16:30 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-29 21:16:30 -0400 |
| commit | 1c6d451ffd63f9805b978e8565807e8a6b528681 (patch) | |
| tree | 97ae6b3746b42ed21eb0fc3a3888bbfca36a1806 /src/lib/extensions/discord-akairo | |
| parent | 7990abdb511eeec2a114b124a3628b10bfefc342 (diff) | |
| download | tanzanite-1c6d451ffd63f9805b978e8565807e8a6b528681.tar.gz tanzanite-1c6d451ffd63f9805b978e8565807e8a6b528681.tar.bz2 tanzanite-1c6d451ffd63f9805b978e8565807e8a6b528681.zip | |
added a rudimentary automod, fixed a bunch of stuff, added some more listeners
Diffstat (limited to 'src/lib/extensions/discord-akairo')
| -rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 12 | ||||
| -rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 86 | ||||
| -rw-r--r-- | src/lib/extensions/discord-akairo/BushCommand.ts | 7 |
3 files changed, 100 insertions, 5 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 10db18d..54b5250 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -1,6 +1,7 @@ import chalk from 'chalk'; import { AkairoClient } from 'discord-akairo'; import { + Collection, Guild, Intents, InteractionReplyOptions, @@ -31,6 +32,7 @@ import { BushCache } from '../../utils/BushCache'; import { BushConstants } from '../../utils/BushConstants'; import { BushLogger } from '../../utils/BushLogger'; import { Config } from '../../utils/Config'; +import { BushApplicationCommand } from '../discord.js/BushApplicationCommand'; import { BushButtonInteraction } from '../discord.js/BushButtonInteraction'; import { BushCategoryChannel } from '../discord.js/BushCategoryChannel'; import { BushCommandInteraction } from '../discord.js/BushCommandInteraction'; @@ -42,6 +44,7 @@ import { BushMessage } from '../discord.js/BushMessage'; import { BushMessageReaction } from '../discord.js/BushMessageReaction'; import { BushNewsChannel } from '../discord.js/BushNewsChannel'; import { BushPresence } from '../discord.js/BushPresence'; +import { BushReactionEmoji } from '../discord.js/BushReactionEmoji'; import { BushRole } from '../discord.js/BushRole'; import { BushSelectMenuInteraction } from '../discord.js/BushSelectMenuInteraction'; import { BushStoreChannel } from '../discord.js/BushStoreChannel'; @@ -66,6 +69,15 @@ export type BushThreadMemberResolvable = BushThreadMember | BushUserResolvable; export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember; export type BushGuildMemberResolvable = BushGuildMember | BushUserResolvable; export type BushRoleResolvable = BushRole | Snowflake; +export type BushMessageResolvable = BushMessage | Snowflake; +export type BushEmojiResolvable = Snowflake | BushGuildEmoji | BushReactionEmoji; +export type BushEmojiIdentifierResolvable = string | BushEmojiResolvable; +export type BushThreadChannelResolvable = BushThreadChannel | Snowflake; +export type BushApplicationCommandResolvable = BushApplicationCommand | Snowflake; +export interface BushFetchedThreads { + threads: Collection<Snowflake, BushThreadChannel>; + hasMore?: boolean; +} const rl = readline.createInterface({ input: process.stdin, diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index ebac9eb..926a529 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -38,7 +38,10 @@ import { } from 'discord.js'; import got from 'got'; import humanizeDuration from 'humanize-duration'; +import moment from 'moment'; import { inspect, InspectOptions, promisify } from 'util'; +import _badLinks from '../../badlinks.json'; // Stolen from https://github.com/nacrt/SkyblockClient-REPO/blob/main/files/scamlinks.json +import badWords from '../../badwords.json'; import { ActivePunishment, ActivePunishmentType } from '../../models/ActivePunishment'; import { BushNewsChannel } from '../discord.js/BushNewsChannel'; import { BushTextChannel } from '../discord.js/BushTextChannel'; @@ -752,8 +755,13 @@ export class BushClientUtil extends ClientUtil { return typeMap[type]; } - public humanizeDuration(duration: number): string { - return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 }); + public humanizeDuration(duration: number, largest?: number): string { + if (largest) return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2, largest }); + else return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 }); + } + + public dateDelta(date: Date, largest?: number) { + return this.humanizeDuration(moment(date).diff(moment()), largest ?? 3); } public async findUUID(player: string): Promise<string> { @@ -790,8 +798,78 @@ export class BushClientUtil extends ClientUtil { /* eslint-enable @typescript-eslint/no-unused-vars */ public async automod(message: BushMessage) { - const autoModPhases = await message.guild.getSetting('autoModPhases'); - if (autoModPhases.includes(message.content.toString()) && message.deletable) return await message.delete(); + if (message.guild.id !== client.consts.mappings.guilds.bush) return; // just temporary + /* await message.guild.getSetting('autoModPhases'); */ + const badLinks = _badLinks.map((link) => { + return { [link]: 3 }; + }); + + const wordArray = [...Object.keys(badWords), ...Object.keys(badLinks)]; + const offences: { [key: string]: number } = {}; + wordArray.forEach((word) => { + if (message.content?.toLowerCase().replace(/ /g, '').includes(word.toLowerCase().replace(/ /g, ''))) { + if (offences[word]) offences[word] = wordArray[word]; + } + }); + if (!Object.keys(offences)?.length) return; + + const highestOffence = Object.values(offences).sort((a, b) => b - a)[0]; + + switch (highestOffence) { + case 0: { + if (message.deletable) void message.delete(); + break; + } + case 1: { + if (message.deletable) void message.delete(); + void message.member.warn({ + moderator: message.guild.me, + reason: 'Saying a blacklisted word.' + }); + break; + } + case 2: { + if (message.deletable) void message.delete(); + void message.member.mute({ + moderator: message.guild.me, + reason: 'Saying a blacklisted word.', + duration: 900_000 // 15 minutes + }); + break; + } + case 3: { + if (message.deletable) void message.delete(); + void message.member.mute({ + moderator: message.guild.me, + reason: 'Saying a blacklisted word.', + duration: 0 // perm + }); + break; + } + } + + const color = + highestOffence === 0 + ? util.colors.lightGray + : highestOffence === 1 + ? util.colors.yellow + : highestOffence === 2 + ? util.colors.orange + : util.colors.red; + void (message.guild.channels.cache.get('783088333055066212') as TextChannel).send({ + embeds: [ + new MessageEmbed() + .setTitle(`[Severity ${highestOffence}] Automod Action Performed`) + .setDescription( + `**User:** ${message.author} (${message.author.tag})\n**Blacklisted Words:** ${util + .surroundArray(Object.keys(offences), '`') + .join()}` + ) + .addField('Message Content', `${this.codeblock(message.content, 1024)}`) + .setColor(color) + .setTimestamp() + ] + }); } public capitalizeFirstLetter(string: string): string { diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 0127a59..3f79aeb 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -78,7 +78,7 @@ export interface BushArgumentOptions extends BaseBushArgumentOptions { type?: BushArgumentType; } export interface CustomBushArgumentOptions extends BaseBushArgumentOptions { - type?: ArgumentTypeCaster | (string | string[])[] | RegExp | string; + customType?: ArgumentTypeCaster | (string | string[])[] | RegExp | string; } export interface BushCommandOptions extends CommandOptions { @@ -122,6 +122,11 @@ export class BushCommand extends Command { this.restrictedChannels = options.restrictedChannels; this.restrictedGuilds = options.restrictedGuilds; this.completelyHide = options.completelyHide; + if (options.args && typeof options.args !== 'function') { + options.args.forEach((arg: BushArgumentOptions | CustomBushArgumentOptions) => { + if (arg['customType']) arg.type = arg['customType']; + }); + } } public exec(message: BushMessage, args: any): any; |
