aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-02 19:49:21 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-02 19:49:21 -0400
commit29cebebc18e9570b699caef8ebb04f4d3934722d (patch)
tree15a47fb5bea3839098d7700b48ad0f8b33eb13fa /src/lib
parent39927eb63081eb8120f75ad38bc336bb48d0f2a7 (diff)
downloadtanzanite-29cebebc18e9570b699caef8ebb04f4d3934722d.tar.gz
tanzanite-29cebebc18e9570b699caef8ebb04f4d3934722d.tar.bz2
tanzanite-29cebebc18e9570b699caef8ebb04f4d3934722d.zip
clean up
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts5
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts38
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts1
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts51
-rw-r--r--src/lib/extensions/discord.js/BushMessage.ts8
-rw-r--r--src/lib/extensions/discord.js/BushThreadMember.ts1
-rw-r--r--src/lib/utils/BushConstants.ts5
-rw-r--r--src/lib/utils/BushLogger.ts23
8 files changed, 69 insertions, 63 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 2eaf3d3..8a21d32 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -304,7 +304,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
} catch (e) {
await this.console.error(
'startup',
- `Failed to connect to <<database>> with error:\n` + typeof e === 'object' ? e?.stack : e,
+ `Failed to connect to <<database>> with error:\n${typeof e}` === 'object' ? e?.stack : e,
false
);
}
@@ -312,7 +312,6 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
/** Starts the bot */
public async start(): Promise<void> {
- // eslint-disable-next-line @typescript-eslint/no-this-alias
const that = this;
eventsIntercept.patch(this);
//@ts-ignore: no typings
@@ -321,7 +320,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
return guild.members.fetch();
});
await Promise.all(promises);
- return done(null, 'intercepted ' + arg);
+ return done(null, `intercepted ${arg}`);
});
// global objects
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index fa5e3b0..c80bfb2 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -1,5 +1,3 @@
-/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
-
import {
BushArgumentType,
BushCache,
@@ -732,7 +730,7 @@ export class BushClientUtil extends ClientUtil {
} else {
await interaction
?.update({
- content: `${text ? text + '\n' : ''}Command closed by user.`,
+ content: `${text ? `${text}\n` : ''}Command closed by user.`,
embeds: [],
components: []
})
@@ -860,13 +858,13 @@ export class BushClientUtil extends ClientUtil {
*/
public async codeblock(code: string, length: number, language?: CodeBlockLang): Promise<string> {
let hasteOut = '';
- const prefix = '```' + language + '\n';
+ const prefix = `\`\`\`${language}\n`;
const suffix = '\n```';
language = language ?? 'txt';
if (code.length + (prefix + suffix).length >= length)
- hasteOut = 'Too large to display. Hastebin: ' + (await this.haste(code));
+ hasteOut = `Too large to display. Hastebin: ${await this.haste(code)}`;
- const FormattedHaste = hasteOut.length ? '\n' + hasteOut : '';
+ const FormattedHaste = hasteOut.length ? `\n${hasteOut}` : '';
const shortenedCode = hasteOut ? code.substring(0, length - (prefix + FormattedHaste + suffix).length) : code;
const code3 = code.length ? prefix + shortenedCode + suffix + FormattedHaste : prefix + suffix;
if (code3.length > length) {
@@ -1071,13 +1069,13 @@ export class BushClientUtil extends ClientUtil {
* @param type - The type of punishment - used to format the response.
* @param checkModerator - Whether or not to check if the victim is a moderator.
*/
- public moderationPermissionCheck(
+ public async moderationPermissionCheck(
moderator: BushGuildMember,
victim: BushGuildMember,
type: 'mute' | 'unmute' | 'warn' | 'kick' | 'ban' | 'unban' | 'add a punishment role to' | 'remove a punishment role from',
checkModerator = true,
force = false
- ): true | string {
+ ): Promise<true | string> {
if (force) return true;
// If the victim is not in the guild anymore it will be undefined
@@ -1086,18 +1084,30 @@ export class BushClientUtil extends ClientUtil {
if (moderator.guild.id !== victim.guild.id) {
throw new Error('moderator and victim not in same guild');
}
+
const isOwner = moderator.guild.ownerId === moderator.id;
- if (moderator.id === victim.id) {
+ if (moderator.id === victim.id && !type.startsWith('un')) {
return `${util.emojis.error} You cannot ${type} yourself.`;
}
- if (moderator.roles.highest.position <= victim.roles.highest.position && !isOwner) {
+ if (
+ moderator.roles.highest.position <= victim.roles.highest.position &&
+ !isOwner &&
+ !(type.startsWith('un') && moderator.id === victim.id)
+ ) {
return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as you do.`;
}
- if (victim.roles.highest.position >= victim.guild.me!.roles.highest.position) {
+ if (
+ victim.roles.highest.position >= victim.guild.me!.roles.highest.position &&
+ !(type.startsWith('un') && moderator.id === victim.id)
+ ) {
return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as I do.`;
}
- if (checkModerator && victim.permissions.has('MANAGE_MESSAGES')) {
- return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they are a moderator.`;
+ if (checkModerator && victim.permissions.has('MANAGE_MESSAGES') && !(type.startsWith('un') && moderator.id === victim.id)) {
+ if (await moderator.guild.hasFeature('modsCanPunishMods')) {
+ return true;
+ } else {
+ return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they are a moderator.`;
+ }
}
return true;
}
@@ -1249,7 +1259,7 @@ export class BushClientUtil extends ClientUtil {
vw.setUint32(0, parseInt(hex, 16), false);
const arrByte = new Uint8Array(arrBuff);
- return arrByte[1] + ', ' + arrByte[2] + ', ' + arrByte[3];
+ return `${arrByte[1]}, ${arrByte[2]}, ${arrByte[3]}`;
}
/* eslint-disable @typescript-eslint/no-unused-vars */
diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts
index 3a2c619..35046d7 100644
--- a/src/lib/extensions/discord-akairo/BushCommand.ts
+++ b/src/lib/extensions/discord-akairo/BushCommand.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ArgumentOptions, ArgumentPromptOptions, ArgumentTypeCaster, Command, CommandOptions } from 'discord-akairo';
import { Snowflake } from 'discord.js';
import { BushMessage } from '../discord.js/BushMessage';
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 67fa2fa..2c41873 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -1,5 +1,4 @@
-/* eslint-disable @typescript-eslint/no-unused-vars */
-import { GuildMember, Partialize, Role } from 'discord.js';
+import { GuildMember, MessageEmbed, Partialize, Role } from 'discord.js';
import { RawGuildMemberData } from 'discord.js/typings/rawDataTypes';
import { ModLogType } from '../../models/ModLog';
import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient';
@@ -86,6 +85,21 @@ export class BushGuildMember extends GuildMember {
super(client, data, guild);
}
+ private async punishDM(punishment: string, reason?: string | null, duration?: number, sendFooter = true): Promise<boolean> {
+ const ending = await this.guild.getSetting('punishmentEnding');
+ const dmEmbed =
+ ending && ending.length && sendFooter
+ ? new MessageEmbed().setDescription(ending).setColor(util.colors.newBlurple)
+ : undefined;
+ const dmSuccess = await this.send({
+ content: `You have been ${punishment} in **${this.guild.name}** ${
+ duration !== null || duration !== undefined ? (duration ? `for ${util.humanizeDuration(duration)}` : 'permanently') : ''
+ }for **${reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`,
+ embeds: dmEmbed ? [dmEmbed] : undefined
+ }).catch(() => false);
+ return !!dmSuccess;
+ }
+
public async warn(options: BushPunishmentOptions): Promise<{ result: WarnResponse | null; caseNum: number | null }> {
const moderator = (await util.resolveNonCachedUser(options.moderator ?? this.guild.me))!;
@@ -103,13 +117,7 @@ export class BushGuildMember extends GuildMember {
if (!result || !result.log) return { result: 'error creating modlog entry', caseNum: null };
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been warned in **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${
- ending ? `\n\n${ending}` : ''
- }`
- }).catch(() => false);
-
+ const dmSuccess = await this.punishDM('warned', options.reason);
if (!dmSuccess) return { result: 'failed to dm', caseNum: result.caseNum };
return { result: 'success', caseNum: result.caseNum };
@@ -244,12 +252,7 @@ export class BushGuildMember extends GuildMember {
if (!punishmentEntrySuccess) return 'error creating mute entry';
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been muted ${
- options.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
- } in **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('muted', options.reason, options.duration ?? 0);
if (!dmSuccess) return 'failed to dm';
@@ -297,9 +300,7 @@ export class BushGuildMember extends GuildMember {
if (!removePunishmentEntrySuccess) return 'error removing mute entry';
//dm user
- const dmSuccess = await this.send({
- content: `You have been unmuted in **${this.guild.name}** because **${options.reason ?? 'No reason provided'}**.`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('unmuted', options.reason, undefined, false);
if (!dmSuccess) return 'failed to dm';
@@ -313,12 +314,7 @@ export class BushGuildMember extends GuildMember {
const moderator = (await util.resolveNonCachedUser(options.moderator ?? this.guild.me))!;
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been kicked from **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${
- ending ? `\n\n${ending}` : ''
- }`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('kicked', options.reason);
// kick
const kickSuccess = await this.kick(`${moderator?.tag} | ${options.reason ?? 'No reason provided.'}`).catch(() => false);
@@ -344,12 +340,7 @@ export class BushGuildMember extends GuildMember {
const moderator = (await util.resolveNonCachedUser(options.moderator ?? this.guild.me))!;
// dm user
- const ending = await this.guild.getSetting('punishmentEnding');
- const dmSuccess = await this.send({
- content: `You have been banned ${
- options?.duration ? 'for ' + util.humanizeDuration(options.duration) : 'permanently'
- } from **${this.guild.name}** for **${options.reason ?? 'No reason provided'}**.${ending ? `\n\n${ending}` : ''}`
- }).catch(() => false);
+ const dmSuccess = await this.punishDM('banned', options.reason, options.duration ?? 0);
// ban
const banSuccess = await this.ban({
diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts
index 7907efe..f2dd02c 100644
--- a/src/lib/extensions/discord.js/BushMessage.ts
+++ b/src/lib/extensions/discord.js/BushMessage.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/no-empty-interface */
import { Message, Partialize } from 'discord.js';
import { RawMessageData } from 'discord.js/typings/rawDataTypes';
import { BushClient, BushTextBasedChannels } from '../discord-akairo/BushClient';
@@ -7,8 +6,11 @@ import { BushGuild } from './BushGuild';
import { BushGuildMember } from './BushGuildMember';
import { BushUser } from './BushUser';
-export interface PartialBushMessage
- extends Partialize<BushMessage, 'type' | 'system' | 'pinned' | 'tts', 'content' | 'cleanContent' | 'author'> {}
+export type PartialBushMessage = Partialize<
+ BushMessage,
+ 'type' | 'system' | 'pinned' | 'tts',
+ 'content' | 'cleanContent' | 'author'
+>;
export class BushMessage extends Message {
public declare readonly client: BushClient;
public override util!: BushCommandUtil;
diff --git a/src/lib/extensions/discord.js/BushThreadMember.ts b/src/lib/extensions/discord.js/BushThreadMember.ts
index 77f2b20..10c7e84 100644
--- a/src/lib/extensions/discord.js/BushThreadMember.ts
+++ b/src/lib/extensions/discord.js/BushThreadMember.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/ban-types */
import { ThreadMember } from 'discord.js';
import { RawThreadMemberData } from 'discord.js/typings/rawDataTypes';
import { BushGuildMember } from './BushGuildMember';
diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts
index 9eb96b3..5698b67 100644
--- a/src/lib/utils/BushConstants.ts
+++ b/src/lib/utils/BushConstants.ts
@@ -9,6 +9,7 @@ interface bushColors {
aqua: '#00bbff';
purple: '#8400ff';
blurple: '#5440cd';
+ newBlurple: '#5865f2';
pink: '#ff00e6';
green: '#00ff1e';
darkGreen: '#008f11';
@@ -98,6 +99,7 @@ export class BushConstants {
aqua: '#00bbff',
purple: '#8400ff',
blurple: '#5440cd',
+ newBlurple: '#5865f2',
pink: '#ff00e6',
green: '#00ff1e',
darkGreen: '#008f11',
@@ -149,8 +151,7 @@ export class BushConstants {
public static regex = {
snowflake: /\d{15,21}/im,
- // eslint-disable-next-line no-useless-escape
- discordEmoji: /<a?:(?<name>[a-zA-Z0-9\_]+):(?<id>\d{15,21})>/im
+ discordEmoji: /<a?:(?<name>[a-zA-Z0-9_]+):(?<id>\d{15,21})>/im
};
public static pronounMapping: { [x in PronounCode]: Pronoun } = {
diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts
index fd0aa4d..c2a9989 100644
--- a/src/lib/utils/BushLogger.ts
+++ b/src/lib/utils/BushLogger.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import chalk from 'chalk';
import { Message, MessageEmbed, Util } from 'discord.js';
import { inspect } from 'util';
@@ -105,7 +104,7 @@ export class BushLogger {
if (!client.config.logging.verbose) return;
const newContent = this.#inspectContent(content, depth, true);
console.info(
- `${chalk.bgGrey(this.#getTimeStamp())} ${chalk.grey(`[${header}]`)} ` + this.#parseFormatting(newContent, 'blackBright')
+ `${chalk.bgGrey(this.#getTimeStamp())} ${chalk.grey(`[${header}]`)} ${this.#parseFormatting(newContent, 'blackBright')}`
);
if (!sendChannel) return;
const embed = new MessageEmbed()
@@ -126,7 +125,7 @@ export class BushLogger {
if (!client.config.logging.info) return;
const newContent = this.#inspectContent(content, depth, true);
console.info(
- `${chalk.bgCyan(this.#getTimeStamp())} ${chalk.cyan(`[${header}]`)} ` + this.#parseFormatting(newContent, 'blueBright')
+ `${chalk.bgCyan(this.#getTimeStamp())} ${chalk.cyan(`[${header}]`)} ${this.#parseFormatting(newContent, 'blueBright')}`
);
if (!sendChannel) return;
const embed = new MessageEmbed()
@@ -146,8 +145,10 @@ export class BushLogger {
public static async warn(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
const newContent = this.#inspectContent(content, depth, true);
console.warn(
- `${chalk.bgYellow(this.#getTimeStamp())} ${chalk.yellow(`[${header}]`)} ` +
- this.#parseFormatting(newContent, 'yellowBright')
+ `${chalk.bgYellow(this.#getTimeStamp())} ${chalk.yellow(`[${header}]`)} ${this.#parseFormatting(
+ newContent,
+ 'yellowBright'
+ )}`
);
if (!sendChannel) return;
@@ -168,8 +169,10 @@ export class BushLogger {
public static async error(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
const newContent = this.#inspectContent(content, depth, true);
console.error(
- `${chalk.bgRedBright(this.#getTimeStamp())} ${chalk.redBright(`[${header}]`)} ` +
- this.#parseFormatting(newContent, 'redBright')
+ `${chalk.bgRedBright(this.#getTimeStamp())} ${chalk.redBright(`[${header}]`)} ${this.#parseFormatting(
+ newContent,
+ 'redBright'
+ )}`
);
if (!sendChannel) return;
const embed = new MessageEmbed()
@@ -190,8 +193,10 @@ export class BushLogger {
public static async success(header: string, content: any, sendChannel = true, depth = 0): Promise<void> {
const newContent = this.#inspectContent(content, depth, true);
console.log(
- `${chalk.bgGreen(this.#getTimeStamp())} ${chalk.greenBright(`[${header}]`)} ` +
- this.#parseFormatting(newContent, 'greenBright')
+ `${chalk.bgGreen(this.#getTimeStamp())} ${chalk.greenBright(`[${header}]`)} ${this.#parseFormatting(
+ newContent,
+ 'greenBright'
+ )}`
);
if (!sendChannel) return;
const embed = new MessageEmbed()