aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-16 14:32:18 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-16 14:32:18 -0400
commit0e87bbd3940d89defcb04926587b35c8f4d1947f (patch)
treee50860d4dc25a11d4c3977b583284c4bcad1b077 /src/lib/extensions/discord.js
parent661e4c9935aeb8760dafc7ced4bbec6cc356a033 (diff)
downloadtanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.gz
tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.bz2
tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.zip
remove util classes, move config out of src
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r--src/lib/extensions/discord.js/ExtendedGuild.ts33
-rw-r--r--src/lib/extensions/discord.js/ExtendedGuildMember.ts26
2 files changed, 31 insertions, 28 deletions
diff --git a/src/lib/extensions/discord.js/ExtendedGuild.ts b/src/lib/extensions/discord.js/ExtendedGuild.ts
index b8b7b22..c199899 100644
--- a/src/lib/extensions/discord.js/ExtendedGuild.ts
+++ b/src/lib/extensions/discord.js/ExtendedGuild.ts
@@ -1,7 +1,9 @@
import {
AllowedMentions,
banResponse,
+ colors,
dmResponse,
+ emojis,
permissionsResponse,
punishmentEntryRemove,
type BanResponse,
@@ -36,9 +38,10 @@ import {
type WebhookMessageOptions
} from 'discord.js';
import _ from 'lodash';
-import { Moderation } from '../../common/util/Moderation.js';
+import * as Moderation from '../../common/util/Moderation.js';
import { Guild as GuildDB } from '../../models/instance/Guild.js';
import { ModLogType } from '../../models/instance/ModLog.js';
+import { addOrRemoveFromArray, resolveNonCachedUser } from '../../utils/BushUtils.js';
declare module 'discord.js' {
export interface Guild {
@@ -152,7 +155,7 @@ export class ExtendedGuild extends Guild {
*/
public override async addFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildModel['enabledFeatures']> {
const features = await this.getSetting('enabledFeatures');
- const newFeatures = util.addOrRemoveFromArray('add', features, feature);
+ const newFeatures = addOrRemoveFromArray('add', features, feature);
return (await this.setSetting('enabledFeatures', newFeatures, moderator)).enabledFeatures;
}
@@ -163,7 +166,7 @@ export class ExtendedGuild extends Guild {
*/
public override async removeFeature(feature: GuildFeatures, moderator?: GuildMember): Promise<GuildModel['enabledFeatures']> {
const features = await this.getSetting('enabledFeatures');
- const newFeatures = util.addOrRemoveFromArray('remove', features, feature);
+ const newFeatures = addOrRemoveFromArray('remove', features, feature);
return (await this.setSetting('enabledFeatures', newFeatures, moderator)).enabledFeatures;
}
@@ -251,7 +254,7 @@ export class ExtendedGuild extends Guild {
*/
public override async error(title: string, message: string): Promise<void> {
void client.console.info(_.camelCase(title), message.replace(/\*\*(.*?)\*\*/g, '<<$1>>'));
- void this.sendLogChannel('error', { embeds: [{ title: title, description: message, color: util.colors.error }] });
+ void this.sendLogChannel('error', { embeds: [{ title: title, description: message, color: colors.error }] });
}
/**
@@ -265,7 +268,7 @@ export class ExtendedGuild extends Guild {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const user = await util.resolveNonCachedUser(options.user);
+ const user = await resolveNonCachedUser(options.user);
const moderator = client.users.resolve(options.moderator ?? client.user!);
if (!user || !moderator) return banResponse.CANNOT_RESOLVE_USER;
@@ -408,7 +411,7 @@ export class ExtendedGuild extends Guild {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const user = await util.resolveNonCachedUser(options.user);
+ const user = await resolveNonCachedUser(options.user);
const moderator = client.users.resolve(options.moderator ?? client.user!);
if (!user || !moderator) return unbanResponse.CANNOT_RESOLVE_USER;
@@ -534,7 +537,7 @@ export class ExtendedGuild extends Guild {
author: { name: moderator.user.tag, icon_url: moderator.displayAvatarURL() },
title: `This channel has been ${options.unlock ? 'un' : ''}locked`,
description: options.reason ?? 'No reason provided',
- color: options.unlock ? util.colors.Green : util.colors.Red,
+ color: options.unlock ? colors.Green : colors.Red,
timestamp: new Date().toISOString()
}
]
@@ -600,16 +603,16 @@ export class ExtendedGuild extends Guild {
case MessageType.RecipientAdd: {
const recipient = rawQuote.mentions[0];
if (!recipient) {
- sendOptions.content = `${util.emojis.error} Cannot resolve recipient.`;
+ sendOptions.content = `${emojis.error} Cannot resolve recipient.`;
break;
}
if (quote.channel.isThread()) {
const recipientDisplay = quote.guild?.members.cache.get(recipient.id)?.displayName ?? recipient.username;
- sendOptions.content = `${util.emojis.join} ${displayName} added ${recipientDisplay} to the thread.`;
+ sendOptions.content = `${emojis.join} ${displayName} added ${recipientDisplay} to the thread.`;
} else {
// this should never happen
- sendOptions.content = `${util.emojis.join} ${displayName} added ${recipient.username} to the group.`;
+ sendOptions.content = `${emojis.join} ${displayName} added ${recipient.username} to the group.`;
}
break;
@@ -617,16 +620,16 @@ export class ExtendedGuild extends Guild {
case MessageType.RecipientRemove: {
const recipient = rawQuote.mentions[0];
if (!recipient) {
- sendOptions.content = `${util.emojis.error} Cannot resolve recipient.`;
+ sendOptions.content = `${emojis.error} Cannot resolve recipient.`;
break;
}
if (quote.channel.isThread()) {
const recipientDisplay = quote.guild?.members.cache.get(recipient.id)?.displayName ?? recipient.username;
- sendOptions.content = `${util.emojis.leave} ${displayName} removed ${recipientDisplay} from the thread.`;
+ sendOptions.content = `${emojis.leave} ${displayName} removed ${recipientDisplay} from the thread.`;
} else {
// this should never happen
- sendOptions.content = `${util.emojis.leave} ${displayName} removed ${recipient.username} from the group.`;
+ sendOptions.content = `${emojis.leave} ${displayName} removed ${recipient.username} from the group.`;
}
break;
@@ -661,7 +664,7 @@ export class ExtendedGuild extends Guild {
// this is the same way that the discord client decides what message to use.
const message = messages[timestamp % messages.length].replace(/{username}/g, displayName);
- sendOptions.content = `${util.emojis.join} ${message}`;
+ sendOptions.content = `${emojis.join} ${message}`;
break;
}
case MessageType.UserPremiumGuildSubscription:
@@ -717,7 +720,7 @@ export class ExtendedGuild extends Guild {
case MessageType.ChannelIconChange:
case MessageType.Call:
default:
- sendOptions.content = `${util.emojis.error} I cannot quote **${
+ sendOptions.content = `${emojis.error} I cannot quote **${
MessageType[quote.type] || quote.type
}** messages, please report this to my developers.`;
diff --git a/src/lib/extensions/discord.js/ExtendedGuildMember.ts b/src/lib/extensions/discord.js/ExtendedGuildMember.ts
index 28acc1a..ad29236 100644
--- a/src/lib/extensions/discord.js/ExtendedGuildMember.ts
+++ b/src/lib/extensions/discord.js/ExtendedGuildMember.ts
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
-import { BushClientEvents, Moderation, ModLogType, PunishmentTypeDM, Time } from '#lib';
+import { BushClientEvents, formatError, Moderation, ModLogType, PunishmentTypeDM, resolveNonCachedUser, Time } from '#lib';
import {
ChannelType,
GuildChannelResolvable,
@@ -148,7 +148,7 @@ export class ExtendedGuildMember extends GuildMember {
public override async bushWarn(options: BushPunishmentOptions): Promise<{ result: WarnResponse; caseNum: number | null }> {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return { result: warnResponse.CANNOT_RESOLVE_USER, caseNum: null };
const ret = await (async (): Promise<{ result: WarnResponse; caseNum: number | null }> => {
@@ -195,7 +195,7 @@ export class ExtendedGuildMember extends GuildMember {
if (ifShouldAddRole !== true) return ifShouldAddRole;
let caseID: string | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return addRoleResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -266,7 +266,7 @@ export class ExtendedGuildMember extends GuildMember {
if (ifShouldAddRole !== true) return ifShouldAddRole;
let caseID: string | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return removeRoleResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -362,7 +362,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return muteResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -448,7 +448,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return unmuteResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -456,7 +456,7 @@ export class ExtendedGuildMember extends GuildMember {
const muteSuccess = await this.roles
.remove(muteRole, `[Unmute] ${moderator.tag} | ${options.reason ?? 'No reason provided.'}`)
.catch(async (e) => {
- await client.console.warn('muteRoleAddError', util.formatError(e, true));
+ await client.console.warn('muteRoleAddError', formatError(e, true));
return false;
});
if (!muteSuccess) return unmuteResponse.ACTION_ERROR;
@@ -526,7 +526,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return kickResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
// add modlog entry
@@ -580,7 +580,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return banResponse.CANNOT_RESOLVE_USER;
// ignore result, they should still be banned even if their mute cannot be removed
@@ -663,7 +663,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return blockResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -754,7 +754,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return unblockResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -839,7 +839,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return timeoutResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {
@@ -901,7 +901,7 @@ export class ExtendedGuildMember extends GuildMember {
let caseID: string | undefined = undefined;
let dmSuccessEvent: boolean | undefined = undefined;
- const moderator = await util.resolveNonCachedUser(options.moderator ?? this.guild.members.me);
+ const moderator = await resolveNonCachedUser(options.moderator ?? this.guild.members.me);
if (!moderator) return removeTimeoutResponse.CANNOT_RESOLVE_USER;
const ret = await (async () => {