Bugfixes to eventhooker and infraction dms
This commit is contained in:
parent
f65604ec2b
commit
9d88266f41
@ -76,7 +76,7 @@ class EventHooker
|
|||||||
const eventArgs = [];
|
const eventArgs = [];
|
||||||
for (const arg of args)
|
for (const arg of args)
|
||||||
{
|
{
|
||||||
if (arg && typeof arg === 'object' && 'guild' in arg)
|
if (arg && typeof arg === 'object' && 'guild' in arg && arg.guild)
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
arg.guildWrapper = this.#target.getGuildWrapper(arg.guild!.id);
|
arg.guildWrapper = this.#target.getGuildWrapper(arg.guild!.id);
|
||||||
|
@ -626,7 +626,7 @@ class ModerationManager implements Initialisable
|
|||||||
if (updateCase)
|
if (updateCase)
|
||||||
await this.#client.storage.mongodb.infractions.updateOne(
|
await this.#client.storage.mongodb.infractions.updateOne(
|
||||||
{ id: infraction.id },
|
{ id: infraction.id },
|
||||||
{ _callbacked: true }
|
{ $set: { _callbacked: true } }
|
||||||
).catch((e) =>
|
).catch((e) =>
|
||||||
{
|
{
|
||||||
this.#logger.error(`Error during update of infraction:\n${e.stack || e}`);
|
this.#logger.error(`Error during update of infraction:\n${e.stack || e}`);
|
||||||
|
@ -132,7 +132,7 @@ class ImportCommand extends SlashCommand
|
|||||||
for (const log of existingLogs)
|
for (const log of existingLogs)
|
||||||
{
|
{
|
||||||
log.case += highestOldId;
|
log.case += highestOldId;
|
||||||
await this.client.mongodb.infractions.updateOne({ _id: log._id }, { case: log.case });
|
await this.client.mongodb.infractions.updateOne({ _id: log._id }, { $set: { case: log.case } });
|
||||||
}
|
}
|
||||||
await this.client.mongodb.infractions.insertMany(imported);
|
await this.client.mongodb.infractions.insertMany(imported);
|
||||||
if (!guild.data.caseId)
|
if (!guild.data.caseId)
|
||||||
@ -193,12 +193,12 @@ class ImportCommand extends SlashCommand
|
|||||||
else if (version === '3')
|
else if (version === '3')
|
||||||
{
|
{
|
||||||
delete webhook.feature;
|
delete webhook.feature;
|
||||||
await this.client.storageManager.mongodb.webhooks.updateOne({ feature: 'messages', guild: guild.id }, webhook);
|
await this.client.storageManager.mongodb.webhooks.updateOne({ feature: 'messages', guild: guild.id }, { $set: webhook });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permissions)
|
if (permissions)
|
||||||
await this.client.storageManager.mongodb.permissions.updateOne({ guildId: guild.id }, permissions);
|
await this.client.storageManager.mongodb.permissions.updateOne({ guildId: guild.id }, { $set: permissions });
|
||||||
|
|
||||||
const { premium } = imported.settings;
|
const { premium } = imported.settings;
|
||||||
delete imported.settings.premium;
|
delete imported.settings.premium;
|
||||||
|
@ -48,9 +48,9 @@ class UtilityHook extends Observer
|
|||||||
|
|
||||||
await this.client.storageManager.mongodb.roleCache.updateOne({
|
await this.client.storageManager.mongodb.roleCache.updateOne({
|
||||||
member: member.id, guild: guild.id
|
member: member.id, guild: guild.id
|
||||||
}, {
|
}, { $set: {
|
||||||
roles: storeThese, timestamp: Date.now()
|
roles: storeThese, timestamp: Date.now()
|
||||||
});
|
} });
|
||||||
}
|
}
|
||||||
|
|
||||||
async automute (member: ExtendedGuildMember)
|
async automute (member: ExtendedGuildMember)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { CommandParams, FormatParams } from '../../../../../@types/Client.js';
|
import { CommandOptionType, CommandParams, FormatParams } from '../../../../../@types/Client.js';
|
||||||
import { ProtectionSettings, ProtectionType } from '../../../../../@types/Settings.js';
|
import { ProtectionSettings, ProtectionType } from '../../../../../@types/Settings.js';
|
||||||
import Util from '../../../../utilities/Util.js';
|
import Util from '../../../../utilities/Util.js';
|
||||||
import DiscordClient from '../../../DiscordClient.js';
|
import DiscordClient from '../../../DiscordClient.js';
|
||||||
@ -49,11 +49,11 @@ class ProtectionSetting extends Setting
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'enabled',
|
name: 'enabled',
|
||||||
description: 'Whether setting is active or not'
|
description: 'Whether setting is active or not',
|
||||||
|
type: CommandOptionType.BOOLEAN
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute (invoker: InvokerWrapper<true>, opts: CommandParams, setting: ProtectionSettings)
|
async execute (invoker: InvokerWrapper<true>, opts: CommandParams, setting: ProtectionSettings)
|
||||||
|
@ -121,7 +121,7 @@ class GuildWrapper
|
|||||||
const cb = { timeout: setTimeout(handler.bind(this), diff, data), data };
|
const cb = { timeout: setTimeout(handler.bind(this), diff, data), data };
|
||||||
this.#callbacks.set(data.id, cb);
|
this.#callbacks.set(data.id, cb);
|
||||||
if (update)
|
if (update)
|
||||||
await this.#client.mongodb.callbacks.updateOne({ id: data.id, guild: this.id }, data);
|
await this.#client.mongodb.callbacks.updateOne({ id: data.id, guild: this.id }, { $set: data });
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeCallback (id: string)
|
async removeCallback (id: string)
|
||||||
@ -228,7 +228,7 @@ class GuildWrapper
|
|||||||
data.settings = settings as GuildSettings;
|
data.settings = settings as GuildSettings;
|
||||||
data._version = configVersion;// '3.slash.2';
|
data._version = configVersion;// '3.slash.2';
|
||||||
await this.#client.mongodb.guilds.deleteOne({ guildId: this.id });
|
await this.#client.mongodb.guilds.deleteOne({ guildId: this.id });
|
||||||
await this.#client.mongodb.guilds.updateOne({ guildId: this.id }, data);
|
await this.#client.mongodb.guilds.updateOne({ guildId: this.id }, { $set: data });
|
||||||
}
|
}
|
||||||
this.#data = data;
|
this.#data = data;
|
||||||
return data;
|
return data;
|
||||||
@ -277,7 +277,7 @@ class GuildWrapper
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this.#client.mongodb.guilds.updateOne({ guildId: this.id }, { _version: configVersion, ...data });
|
await this.#client.mongodb.guilds.updateOne({ guildId: this.id }, { $set: { _version: configVersion, ...data } });
|
||||||
this.#data = { ...this.#data, ...data, _version: configVersion };
|
this.#data = { ...this.#data, ...data, _version: configVersion };
|
||||||
this.#storageLog(`Database update: Data (guild:${this.id})`);
|
this.#storageLog(`Database update: Data (guild:${this.id})`);
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ class GuildWrapper
|
|||||||
throw new Error('Permissions not loaded');
|
throw new Error('Permissions not loaded');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this.#client.mongodb.permissions.updateOne({ guildId: this.id }, this.#permissions, { upsert: true });
|
await this.#client.mongodb.permissions.updateOne({ guildId: this.id }, { $set: this.#permissions }, { upsert: true });
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
@ -423,7 +423,7 @@ class GuildWrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.#webhooks.set(feature, webhook);
|
this.#webhooks.set(feature, webhook);
|
||||||
await this.#client.mongodb.webhooks.updateOne({ feature, guild: this.id }, { hookId: webhook.id, token: webhook.token });
|
await this.#client.mongodb.webhooks.updateOne({ feature, guild: this.id }, { $set: { hookId: webhook.id, token: webhook.token } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,7 +152,7 @@ class UserWrapper
|
|||||||
{
|
{
|
||||||
await this.#client.mongodb.users.updateOne(
|
await this.#client.mongodb.users.updateOne(
|
||||||
{ guildId: this.id },
|
{ guildId: this.id },
|
||||||
data
|
{ $set: data }
|
||||||
);
|
);
|
||||||
this.#settings = {
|
this.#settings = {
|
||||||
...this.#settings,
|
...this.#settings,
|
||||||
|
@ -112,7 +112,7 @@ class UnlockdownInfraction extends Infraction
|
|||||||
if (callback)
|
if (callback)
|
||||||
await this.client.moderation.removeCallback(callback.infraction, true);
|
await this.client.moderation.removeCallback(callback.infraction, true);
|
||||||
else
|
else
|
||||||
await this.client.mongodb.infractions.updateOne({ id: latest.id }, { _callbacked: true });
|
await this.client.mongodb.infractions.updateOne({ id: latest.id }, { $set: { _callbacked: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.handle();
|
await this.handle();
|
||||||
|
@ -166,7 +166,6 @@ class Infraction
|
|||||||
|
|
||||||
async handle ()
|
async handle ()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Infraction was fetched from database, i.e. was already executed previously
|
// Infraction was fetched from database, i.e. was already executed previously
|
||||||
if (this.#fetched)
|
if (this.#fetched)
|
||||||
throw new Error('Cannot handle a fetched Infraction');
|
throw new Error('Cannot handle a fetched Infraction');
|
||||||
@ -197,7 +196,6 @@ class Infraction
|
|||||||
this.#dmLogMessage = await this.#moderationLog.send({ embeds: [ await this.#embed() ] }).catch(null);
|
this.#dmLogMessage = await this.#moderationLog.send({ embeds: [ await this.#embed() ] }).catch(null);
|
||||||
this.#modLogMessageId = this.#dmLogMessage?.id || null;
|
this.#modLogMessageId = this.#dmLogMessage?.id || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -218,30 +216,25 @@ class Infraction
|
|||||||
.replace(/\{infraction\}/ugim, this.dictionary.past)
|
.replace(/\{infraction\}/ugim, this.dictionary.past)
|
||||||
.replace(/\{from\|on\}/ugim, Constants.RemovedInfractions.includes(this.#type!) ? 'from' : 'on'); // add more if you want i should probably add a better system for this...
|
.replace(/\{from\|on\}/ugim, Constants.RemovedInfractions.includes(this.#type!) ? 'from' : 'on'); // add more if you want i should probably add a better system for this...
|
||||||
|
|
||||||
|
|
||||||
if (Util.isSendable(this.#target))
|
if (Util.isSendable(this.#target))
|
||||||
{
|
{
|
||||||
const logMessage = await this.#target.send({
|
const logMessage = await this.#target.send({
|
||||||
content: message,
|
content: message,
|
||||||
embeds: [ await this.#embed(true) ]
|
embeds: [ await this.#embed(true) ]
|
||||||
}).catch(null);
|
}).catch(() => null);
|
||||||
this.#dmLogMessageId = logMessage.id;
|
this.#dmLogMessageId = logMessage?.id ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#duration)
|
if (this.#duration)
|
||||||
{
|
|
||||||
await this.#client.moderation.handleCallbacks([ this.json ]);
|
await this.#client.moderation.handleCallbacks([ this.json ]);
|
||||||
}
|
|
||||||
|
|
||||||
/* LMAOOOO PLEASE DONT JUDGE ME */
|
/* LMAOOOO PLEASE DONT JUDGE ME */
|
||||||
if (this.#data.roles)
|
if (this.#data.roles)
|
||||||
delete this.#data.roles;
|
delete this.#data.roles;
|
||||||
|
|
||||||
|
|
||||||
return this.save();
|
return this.save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
execute (): Promise<InfractionSuccess | InfractionFail>
|
execute (): Promise<InfractionSuccess | InfractionFail>
|
||||||
@ -254,7 +247,7 @@ class Infraction
|
|||||||
const filter: {id: string, _id?: ObjectId} = { id: this.id };
|
const filter: {id: string, _id?: ObjectId} = { id: this.id };
|
||||||
if (this.#mongoId)
|
if (this.#mongoId)
|
||||||
filter._id = this.#mongoId;
|
filter._id = this.#mongoId;
|
||||||
return this.#client.mongodb.infractions.updateOne(filter, this.json)
|
return this.#client.mongodb.infractions.updateOne(filter, { $set: this.json })
|
||||||
.catch((error: Error) =>
|
.catch((error: Error) =>
|
||||||
{
|
{
|
||||||
this.#logger.error(`There was an issue saving infraction data to the database.\n${error.stack || error}\nInfraction data:\n${inspect(this.json)}`);
|
this.#logger.error(`There was an issue saving infraction data to the database.\n${error.stack || error}\nInfraction data:\n${inspect(this.json)}`);
|
||||||
@ -322,7 +315,6 @@ class Infraction
|
|||||||
if (this.description && this.description instanceof Function)
|
if (this.description && this.description instanceof Function)
|
||||||
description += this.description(dm);
|
description += this.description(dm);
|
||||||
|
|
||||||
|
|
||||||
if (this.#resolved)
|
if (this.#resolved)
|
||||||
{
|
{
|
||||||
description += '\n' + this.#guild.format('INFRACTION_RESOLVED');
|
description += '\n' + this.#guild.format('INFRACTION_RESOLVED');
|
||||||
@ -345,14 +337,12 @@ class Infraction
|
|||||||
}
|
}
|
||||||
|
|
||||||
embed.description = description;
|
embed.description = description;
|
||||||
|
|
||||||
return embed;
|
return embed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
description (_dm: boolean): string
|
description (_dm: boolean): string
|
||||||
{
|
{
|
||||||
throw new Error('Description is to be implemented by a subclass');
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get client ()
|
protected get client ()
|
||||||
|
@ -124,7 +124,7 @@ class Util
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
static isSendable (obj: any): obj is { send: () => Promise<Message>}
|
static isSendable (obj: any): obj is { send: () => Promise<Message>}
|
||||||
{
|
{
|
||||||
return Util.has(obj, 'send') && typeof obj.send === 'function';
|
return typeof obj.send === 'function';
|
||||||
}
|
}
|
||||||
|
|
||||||
// static hasProperty<T> (obj: any, name: string): obj is { [key in typeof name]: T }
|
// static hasProperty<T> (obj: any, name: string): obj is { [key in typeof name]: T }
|
||||||
|
Loading…
Reference in New Issue
Block a user