aboutsummaryrefslogtreecommitdiff
path: root/src/lib/common
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-17 20:03:05 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-17 20:03:05 -0400
commite1c613829950a534d9f45c00a033b83575be3b3c (patch)
tree2de1e5231217211ae4087c46cc74dc46c584507a /src/lib/common
parent0e87bbd3940d89defcb04926587b35c8f4d1947f (diff)
downloadtanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.gz
tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.bz2
tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.zip
remove global client variable
Diffstat (limited to 'src/lib/common')
-rw-r--r--src/lib/common/AutoMod.ts30
-rw-r--r--src/lib/common/ButtonPaginator.ts2
-rw-r--r--src/lib/common/ConfirmationPrompt.ts2
-rw-r--r--src/lib/common/DeleteButton.ts2
-rw-r--r--src/lib/common/HighlightManager.ts8
-rw-r--r--src/lib/common/util/Arg.ts2
-rw-r--r--src/lib/common/util/Moderation.ts53
7 files changed, 57 insertions, 42 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts
index 7f19e63..0910352 100644
--- a/src/lib/common/AutoMod.ts
+++ b/src/lib/common/AutoMod.ts
@@ -1,4 +1,4 @@
-import { banResponse, codeblock, colors, emojis, format, formatError, getShared, Moderation, resolveNonCachedUser } from '#lib';
+import { banResponse, colors, emojis, format, formatError, Moderation } from '#lib';
import assert from 'assert';
import chalk from 'chalk';
import {
@@ -31,7 +31,7 @@ export class AutoMod {
*/
private message: Message
) {
- if (message.author.id === client.user?.id) return;
+ if (message.author.id === message.client.user?.id) return;
void this.handle();
}
@@ -56,9 +56,9 @@ export class AutoMod {
traditional: {
if (this.isImmune) break traditional;
- const badLinksArray = getShared('badLinks');
- const badLinksSecretArray = getShared('badLinksSecret');
- const badWordsRaw = getShared('badWords');
+ const badLinksArray = this.message.client.utils.getShared('badLinks');
+ const badLinksSecretArray = this.message.client.utils.getShared('badLinksSecret');
+ const badWordsRaw = this.message.client.utils.getShared('badWords');
const customAutomodPhrases = (await this.message.guild.getSetting('autoModPhases')) ?? [];
const uniqueLinks = [...new Set([...badLinksArray, ...badLinksSecretArray])];
@@ -167,7 +167,9 @@ export class AutoMod {
.setDescription(
`**User:** ${this.message.author} (${this.message.author.tag})\n**Sent From:** <#${this.message.channel.id}> [Jump to context](${this.message.url})`
)
- .addFields([{ name: 'Message Content', value: `${await codeblock(this.message.content, 1024)}` }])
+ .addFields([
+ { name: 'Message Content', value: `${await this.message.client.utils.codeblock(this.message.content, 1024)}` }
+ ])
.setColor(color)
.setTimestamp()
],
@@ -186,12 +188,12 @@ export class AutoMod {
private async checkPerspectiveApi() {
return;
- if (!client.config.isDevelopment) return;
+ if (!this.message.client.config.isDevelopment) return;
if (!this.message.content) return;
- client.perspective.comments.analyze(
+ this.message.client.perspective.comments.analyze(
{
- key: client.config.credentials.perspectiveApiKey,
+ key: this.message.client.config.credentials.perspectiveApiKey,
resource: {
comment: {
text: this.message.content
@@ -301,7 +303,7 @@ export class AutoMod {
{
title: 'AutoMod Error',
description: `Unable to delete triggered message.`,
- fields: [{ name: 'Error', value: await codeblock(`${formatError(e)}`, 1024, 'js', true) }],
+ fields: [{ name: 'Error', value: await this.message.client.utils.codeblock(`${formatError(e)}`, 1024, 'js', true) }],
color: colors.error
}
]
@@ -316,7 +318,7 @@ export class AutoMod {
* @param offences The other offences that were also matched in the message
*/
private async log(highestOffence: BadWordDetails, color: number, offences: BadWordDetails[]) {
- void client.console.info(
+ void this.message.client.console.info(
'autoMod',
`Severity <<${highestOffence.severity}>> action performed on <<${this.message.author.tag}>> (<<${
this.message.author.id
@@ -332,7 +334,9 @@ export class AutoMod {
this.message.channel.id
}> [Jump to context](${this.message.url})\n**Blacklisted Words:** ${offences.map((o) => `\`${o.match}\``).join(', ')}`
)
- .addFields([{ name: 'Message Content', value: `${await codeblock(this.message.content, 1024)}` }])
+ .addFields([
+ { name: 'Message Content', value: `${await this.message.client.utils.codeblock(this.message.content, 1024)}` }
+ ])
.setColor(color)
.setTimestamp()
.setAuthor({ name: this.message.author.tag, url: this.message.author.displayAvatarURL() })
@@ -386,7 +390,7 @@ export class AutoMod {
evidence: (interaction.message as Message).url ?? undefined
});
- const victimUserFormatted = (await resolveNonCachedUser(userId))?.tag ?? userId;
+ const victimUserFormatted = (await interaction.client.utils.resolveNonCachedUser(userId))?.tag ?? userId;
if (result === banResponse.SUCCESS)
return interaction.reply({
content: `${emojis.success} Successfully banned **${victimUserFormatted}**.`,
diff --git a/src/lib/common/ButtonPaginator.ts b/src/lib/common/ButtonPaginator.ts
index 9560247..708b374 100644
--- a/src/lib/common/ButtonPaginator.ts
+++ b/src/lib/common/ButtonPaginator.ts
@@ -97,7 +97,7 @@ export class ButtonPaginator {
* @param interaction The interaction received
*/
protected async collect(interaction: MessageComponentInteraction) {
- if (interaction.user.id !== this.message.author.id && !client.config.owners.includes(interaction.user.id))
+ if (interaction.user.id !== this.message.author.id && !this.message.client.config.owners.includes(interaction.user.id))
return await interaction?.deferUpdate().catch(() => null);
switch (interaction.customId) {
diff --git a/src/lib/common/ConfirmationPrompt.ts b/src/lib/common/ConfirmationPrompt.ts
index 4593d24..38d078a 100644
--- a/src/lib/common/ConfirmationPrompt.ts
+++ b/src/lib/common/ConfirmationPrompt.ts
@@ -43,7 +43,7 @@ export class ConfirmationPrompt {
collector.on('collect', async (interaction: MessageComponentInteraction) => {
await interaction.deferUpdate().catch(() => undefined);
- if (interaction.user.id == this.message.author.id || client.config.owners.includes(interaction.user.id)) {
+ if (interaction.user.id == this.message.author.id || this.message.client.config.owners.includes(interaction.user.id)) {
if (interaction.customId === 'confirmationPrompt_confirm') {
responded = true;
collector.stop();
diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts
index b561d94..bc0da17 100644
--- a/src/lib/common/DeleteButton.ts
+++ b/src/lib/common/DeleteButton.ts
@@ -45,7 +45,7 @@ export class DeleteButton {
collector.on('collect', async (interaction: MessageComponentInteraction) => {
await interaction.deferUpdate().catch(() => undefined);
- if (interaction.user.id == this.message.author.id || client.config.owners.includes(interaction.user.id)) {
+ if (interaction.user.id == this.message.author.id || this.message.client.config.owners.includes(interaction.user.id)) {
if (msg.deletable && !CommandUtil.deletedMessages.has(msg.id)) await msg.delete();
}
});
diff --git a/src/lib/common/HighlightManager.ts b/src/lib/common/HighlightManager.ts
index caaa6a5..cd89c89 100644
--- a/src/lib/common/HighlightManager.ts
+++ b/src/lib/common/HighlightManager.ts
@@ -232,10 +232,10 @@ export class HighlightManager {
const lastDM = this.lastedDMedUserCooldown.get(user);
if (!lastDM) break dmCooldown;
- const cooldown = client.ownerID.includes(user) ? OWNER_NOTIFY_COOLDOWN : NOTIFY_COOLDOWN;
+ const cooldown = message.client.ownerID.includes(user) ? OWNER_NOTIFY_COOLDOWN : NOTIFY_COOLDOWN;
if (new Date().getTime() - lastDM.getTime() < cooldown) {
- void client.console.verbose('Highlight', `User <<${user}>> has been dmed recently.`);
+ void message.client.console.verbose('Highlight', `User <<${user}>> has been dmed recently.`);
return false;
}
}
@@ -248,7 +248,7 @@ export class HighlightManager {
const talked = lastTalked.getTime();
if (now - talked < LAST_MESSAGE_COOLDOWN) {
- void client.console.verbose('Highlight', `User <<${user}>> has talked too recently.`);
+ void message.client.console.verbose('Highlight', `User <<${user}>> has talked too recently.`);
setTimeout(() => {
const newTalked = this.userLastTalkedCooldown.get(message.guildId)?.get(user)?.getTime();
@@ -268,7 +268,7 @@ export class HighlightManager {
.first(4)
.reverse();
- return client.users
+ return message.client.users
.send(user, {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
content: `In ${format.input(message.guild.name)} ${message.channel}, your highlight "${hl.word}" was matched:`,
diff --git a/src/lib/common/util/Arg.ts b/src/lib/common/util/Arg.ts
index a7795b1..325f821 100644
--- a/src/lib/common/util/Arg.ts
+++ b/src/lib/common/util/Arg.ts
@@ -18,7 +18,7 @@ export async function cast<T extends ATC>(type: T, message: CommandMessage | Sla
export async function cast<T extends KBAT>(type: T, message: CommandMessage | SlashMessage, phrase: string): Promise<BAT[T]>;
export async function cast(type: AT | ATC, message: CommandMessage | SlashMessage, phrase: string): Promise<any>;
export async function cast(type: ATC | AT, message: CommandMessage | SlashMessage, phrase: string): Promise<any> {
- return Argument.cast(type as any, client.commandHandler.resolver, message as Message, phrase);
+ return Argument.cast(type as any, message.client.commandHandler.resolver, message as Message, phrase);
}
/**
diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts
index a08dfa4..cb6b4db 100644
--- a/src/lib/common/util/Moderation.ts
+++ b/src/lib/common/util/Moderation.ts
@@ -5,10 +5,8 @@ import {
emojis,
format,
Guild as GuildDB,
- handleError,
humanizeDuration,
ModLog,
- resolveNonCachedUser,
type ModLogType
} from '#lib';
import assert from 'assert';
@@ -16,6 +14,7 @@ import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
+ Client,
EmbedBuilder,
PermissionFlagsBits,
type Guild,
@@ -129,9 +128,9 @@ export async function createModLogEntry(
options: CreateModLogEntryOptions,
getCaseNumber = false
): Promise<{ log: ModLog | null; caseNum: number | null }> {
- const user = (await resolveNonCachedUser(options.user))!.id;
- const moderator = (await resolveNonCachedUser(options.moderator))!.id;
- const guild = client.guilds.resolveId(options.guild)!;
+ const user = (await options.client.utils.resolveNonCachedUser(options.user))!.id;
+ const moderator = (await options.client.utils.resolveNonCachedUser(options.moderator))!.id;
+ const guild = options.client.guilds.resolveId(options.guild)!;
return createModLogEntrySimple(
{
@@ -172,7 +171,7 @@ export async function createModLogEntrySimple(
hidden: options.hidden ?? false
});
const saveResult: ModLog | null = await modLogEntry.save().catch(async (e) => {
- await handleError('createModLogEntry', e);
+ await options.client.utils.handleError('createModLogEntry', e);
return null;
});
@@ -191,8 +190,8 @@ export async function createModLogEntrySimple(
*/
export async function createPunishmentEntry(options: CreatePunishmentEntryOptions): Promise<ActivePunishment | null> {
const expires = options.duration ? new Date(+new Date() + options.duration ?? 0) : undefined;
- const user = (await resolveNonCachedUser(options.user))!.id;
- const guild = client.guilds.resolveId(options.guild)!;
+ const user = (await options.client.utils.resolveNonCachedUser(options.user))!.id;
+ const guild = options.client.guilds.resolveId(options.guild)!;
const type = findTypeEnum(options.type)!;
const entry = ActivePunishment.build(
@@ -201,7 +200,7 @@ export async function createPunishmentEntry(options: CreatePunishmentEntryOption
: { user, type, guild, expires, modlog: options.modlog }
);
return await entry.save().catch(async (e) => {
- await handleError('createPunishmentEntry', e);
+ await options.client.utils.handleError('createPunishmentEntry', e);
return null;
});
}
@@ -212,8 +211,8 @@ export async function createPunishmentEntry(options: CreatePunishmentEntryOption
* @returns Whether or not the entry was destroyed.
*/
export async function removePunishmentEntry(options: RemovePunishmentEntryOptions): Promise<boolean> {
- const user = await resolveNonCachedUser(options.user);
- const guild = client.guilds.resolveId(options.guild);
+ const user = await options.client.utils.resolveNonCachedUser(options.user);
+ const guild = options.client.guilds.resolveId(options.guild);
const type = findTypeEnum(options.type);
if (!user || !guild) return false;
@@ -226,13 +225,13 @@ export async function removePunishmentEntry(options: RemovePunishmentEntryOption
? { user: user.id, guild: guild, type, extraInfo: options.extraInfo }
: { user: user.id, guild: guild, type }
}).catch(async (e) => {
- await handleError('removePunishmentEntry', e);
+ await options.client.utils.handleError('removePunishmentEntry', e);
success = false;
});
if (entries) {
const promises = entries.map(async (entry) =>
entry.destroy().catch(async (e) => {
- await handleError('removePunishmentEntry', e);
+ await options.client.utils.handleError('removePunishmentEntry', e);
success = false;
})
);
@@ -298,9 +297,9 @@ export async function punishDM(options: PunishDMOptions): Promise<boolean> {
new ActionRowBuilder<ButtonBuilder>({
components: [
new ButtonBuilder({
- customId: `appeal;${punishmentToPresentTense(options.punishment)};${options.guild.id};${client.users.resolveId(
- options.user
- )};${options.modlog}`,
+ customId: `appeal;${punishmentToPresentTense(options.punishment)};${
+ options.guild.id
+ };${options.client.users.resolveId(options.user)};${options.modlog}`,
style: ButtonStyle.Primary,
label: 'Appeal'
}).toJSON()
@@ -308,7 +307,7 @@ export async function punishDM(options: PunishDMOptions): Promise<boolean> {
})
];
- const dmSuccess = await client.users
+ const dmSuccess = await options.client.users
.send(options.user, {
content,
embeds: dmEmbed ? [dmEmbed] : undefined,
@@ -318,7 +317,7 @@ export async function punishDM(options: PunishDMOptions): Promise<boolean> {
return !!dmSuccess;
}
-interface BaseCreateModLogEntryOptions {
+interface BaseCreateModLogEntryOptions extends BaseOptions {
/**
* The type of modlog entry.
*/
@@ -355,6 +354,11 @@ interface BaseCreateModLogEntryOptions {
*/
export interface CreateModLogEntryOptions extends BaseCreateModLogEntryOptions {
/**
+ * The client.
+ */
+ client: Client;
+
+ /**
* The user that a modlog entry is created for.
*/
user: GuildMemberResolvable;
@@ -393,7 +397,7 @@ export interface SimpleCreateModLogEntryOptions extends BaseCreateModLogEntryOpt
/**
* Options for creating a punishment entry.
*/
-export interface CreatePunishmentEntryOptions {
+export interface CreatePunishmentEntryOptions extends BaseOptions {
/**
* The type of punishment.
*/
@@ -428,7 +432,7 @@ export interface CreatePunishmentEntryOptions {
/**
* Options for removing a punishment entry.
*/
-export interface RemovePunishmentEntryOptions {
+export interface RemovePunishmentEntryOptions extends BaseOptions {
/**
* The type of punishment.
*/
@@ -453,7 +457,7 @@ export interface RemovePunishmentEntryOptions {
/**
* Options for sending a user a punishment dm.
*/
-export interface PunishDMOptions {
+export interface PunishDMOptions extends BaseOptions {
/**
* The modlog case id so the user can make an appeal.
*/
@@ -496,6 +500,13 @@ export interface PunishDMOptions {
channel?: Snowflake;
}
+interface BaseOptions {
+ /**
+ * The client.
+ */
+ client: Client;
+}
+
export type PunishmentTypeDM =
| 'warned'
| 'muted'