misc fixes n stuff

This commit is contained in:
Erik 2022-09-16 17:31:26 +03:00
parent f340017492
commit 12d39a832f
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
8 changed files with 30 additions and 11 deletions

View File

@ -194,6 +194,9 @@ The amount must be more than `1` and less than `300`.
[C_PRUNE_INSUFFICIENTPERMISSIONS] [C_PRUNE_INSUFFICIENTPERMISSIONS]
I don't have permission to manage messages I don't have permission to manage messages
[C_PRUNE_NON_TEXTCHANNEL]
Cannot prune a non-text based channel
[C_PRUNE_NOTFETCHED] [C_PRUNE_NOTFETCHED]
I was unable to fetch any messages I was unable to fetch any messages

View File

@ -61,6 +61,8 @@ class Logger {
write(type = 'info', string = '', shard = null, api = false, broadcast = false) { write(type = 'info', string = '', shard = null, api = false, broadcast = false) {
if (string.includes('ECONNRESET')) return;
type = type.toLowerCase(); type = type.toLowerCase();
let color = Constants.Colors[type]; let color = Constants.Colors[type];

View File

@ -303,6 +303,14 @@ class ModerationManager {
}; };
if (target instanceof GuildMember) {
// The cached member is sometimes outdated, ensure we get the latest member so the perm checks don't fail
// Would help if members had a cached timestamp, might have to change this to work with a wrapper
target = await guild.members.fetch({ user: target, force: true });
} else if (!(target instanceof User)) {
target = await wrapper.channels.fetch(target.id, { force: true });
}
const infraction = new Infraction(this.client, { const infraction = new Infraction(this.client, {
target, target,
type, type,

View File

@ -90,7 +90,7 @@ class CaseCommand extends SlashCommand {
if (guild._settings.modpoints.enabled) description += '\n' + invoker.format('COMMAND_CASE_MODPOINTS', { if (guild._settings.modpoints.enabled) description += '\n' + invoker.format('COMMAND_CASE_MODPOINTS', {
points: infraction.points, points: infraction.points,
expires: `<t:${Math.round(infraction.expiration / 1000)}:R>` expires: infraction.expiration ? `<t:${Math.round(infraction.expiration / 1000)}:R>` : false
}); });
description += '\n\n' + invoker.format('COMMAND_CASE_REASON', { reason: infraction.reason }); description += '\n\n' + invoker.format('COMMAND_CASE_REASON', { reason: infraction.reason });
@ -137,7 +137,7 @@ class CaseCommand extends SlashCommand {
})); }));
embed.footer = { embed.footer = {
text: invoker.format('COMMAND_CASE_CHANGES_AMOUNT', { changes: infraction.changes.length }) text: invoker.format('COMMAND_CASE_CHANGES_AMOUNT', { changes: infraction.changes?.length || 0 })
}; };
return embed; return embed;

View File

@ -161,14 +161,14 @@ class HistoryCommand extends SlashCommand {
const infraction = results[i]; const infraction = results[i];
let target = null; let target = null;
if (infraction.targetType === 'USER') { if (infraction.targetType === 'USER') {
target = await this.client.resolver.resolveUser(infraction.target); target = await this.client.users.fetch(infraction.target);
} else { } else {
target = await guild.resolveChannel(infraction.target); target = await guild.resolveChannel(infraction.target);
} }
const executor = await this.client.resolver.resolveUser(infraction.executor); const executor = await this.client.resolver.resolveUser(infraction.executor);
let string = stripIndents`**Target:** ${Util.escapeMarkdown(target.tag || target.name)}${verbose?.value ? ` (${target.id})` : ''} let string = stripIndents`**Target:** ${target ? Util.escapeMarkdown(target.tag || target.name) : 'Missing Target'}${verbose?.value ? ` (${target?.id})` : ''}
**Moderator:** ${executor ? `${Util.escapeMarkdown(executor.tag)}${verbose?.value ? ` (${infraction.executor})` : ''}` : infraction.executor}`; **Moderator:** ${executor ? `${Util.escapeMarkdown(executor.tag)}${verbose?.value ? ` (${infraction.executor})` : ''}` : infraction.executor}`;
if (infraction.data?.roleIds) { if (infraction.data?.roleIds) {

View File

@ -192,7 +192,7 @@ class CommandHandler extends Observer {
this._generateError(invoker, { error, type: 'command' }); this._generateError(invoker, { error, type: 'command' });
} else { } else {
if (!(invoker.command instanceof SettingsCommand)) invoker.command.error(now); if (!(invoker.command instanceof SettingsCommand)) invoker.command.error(now);
this.logger.error(`Command ${debugstr} errored:\nGuild: ${invoker.guild?.name || 'dms'} (${invoker.guild?.id || ''})\nOptions:\n${Object.keys(options).map((key) => `[${key}: ${options[key]._rawValue}]`).join('\n')}\n${error.stack || error}`); this.logger.error(`\n[${invoker.type.toUpperCase()}] Command ${debugstr} errored:\nGuild: ${invoker.guild?.name || 'dms'} (${invoker.guild?.id || ''})\nOptions:\n${Object.keys(options).map((key) => `[${key}: ${options[key].value} (${options[key]._rawValue})]`).join('\n')}\n${error.stack || error}`);
this._generateError(invoker, { type: 'commandHandler' }); this._generateError(invoker, { type: 'commandHandler' });
} }
return; return;

View File

@ -161,7 +161,9 @@ class MuteInfraction extends Infraction {
let message = null, let message = null,
error = false; error = false;
const { removedRoles, muteType, muteRole } = this.data; const settings = await this.guild.settings();
const { removedRoles = [], muteType = settings.mute.type, muteRole = settings.mute.role } = this.data || {};
const member = await this.guild.memberWrapper(this.targetId).catch(() => null); const member = await this.guild.memberWrapper(this.targetId).catch(() => null);
const callback = await member.getCallback(this.type); const callback = await member.getCallback(this.type);
if (callback) this.client.moderationManager.removeCallback(callback.infraction); if (callback) this.client.moderationManager.removeCallback(callback.infraction);

View File

@ -172,11 +172,14 @@ class PruneInfraction extends Infraction {
async fetchMessages(message, amount) { async fetchMessages(message, amount) {
let fetched = new Collection(); let fetched = new Collection();
const msgMgr = this.channel.messages;
const after = this.arguments.after?.value || null;
const fetch = async (lastMessage, amount) => { const fetch = async (lastMessage, amount) => {
const messages = await this.target.messages.fetch({ const messages = await msgMgr.fetch({
limit: amount > 100 ? 100 : amount, limit: amount > 100 ? 100 : amount,
before: lastMessage, before: lastMessage,
after: this.arguments.after ? this.arguments.after.value : null after
}); });
fetched = fetched.concat(messages); fetched = fetched.concat(messages);
@ -198,9 +201,10 @@ class PruneInfraction extends Infraction {
async verify() { async verify() {
const me = await this.guild.resolveMember(this.client.user); const me = await this.guild.resolveMember(this.client.user);
const perms = this.target.permissionsFor(me); const perms = this.channel.permissionsFor(me);
if (perms.missing('ViewChannel', 'ReadMessageHistory').length) return this._fail('C_PRUNE_MISSING_ACCESS', true); if (perms.missing('ViewChannel', 'ReadMessageHistory').length) return this._fail('C_PRUNE_MISSING_ACCESS');
if (perms.missing('ManageMessages').length) return this._fail('C_PRUNE_INSUFFICIENTPERMISSIONS', true); if (perms.missing('ManageMessages').length) return this._fail('C_PRUNE_INSUFFICIENTPERMISSIONS');
if (!this.channel.messages) return this._fail('C_PRUNE_NON_TEXTCHANNEL');
return super._verify(); return super._verify();