This commit is contained in:
Erik 2022-07-21 15:47:50 +03:00
parent 393337fbbd
commit ce6b430771
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
6 changed files with 29 additions and 21 deletions

View File

@ -86,7 +86,7 @@ class PollCommand extends SlashCommand {
}),
fields: questions,
color: 619452,
timestamp: new Date()
timestamp: new Date().toISOString()
};
let pollMsg = null;

View File

@ -52,7 +52,7 @@ class MuteInfraction extends Infraction {
switch (setting.type) {
case 0:
try {
this.member.roles.add(role, this._reason);
await this.member.roles.add(role, this._reason);
} catch (e) {
this.client.logger.debug(`Mute fail, type 1:\n${e.stack}`);
return this._fail('COMMAND_MUTE_1FAIL');
@ -63,9 +63,9 @@ class MuteInfraction extends Infraction {
r.comparePositionTo(this.guild.members.me.roles.highest) < 0 &&
r.id !== this.guild.id);
try {
this.member.roles.set([
await this.member.roles.set([
...this.member.roles.cache.filter((r) => r.managed ||
r.comparePositionTo(this.guild.members.me.roles.highest) > 0 ||
r.comparePositionTo(this.guild.members.me.roles.highest) >= 0 ||
r.id === this.guild.id).values(),
role
], this._reason);
@ -79,8 +79,8 @@ class MuteInfraction extends Infraction {
r.comparePositionTo(this.guild.members.me.roles.highest) < 0 &&
r.id !== this.guild.id);
try {
this.member.roles.set(this.member.roles.cache.filter((r) => r.managed ||
r.comparePositionTo(this.guild.members.me.roles.highest) > 0 ||
await this.member.roles.set(this.member.roles.cache.filter((r) => r.managed ||
r.comparePositionTo(this.guild.members.me.roles.highest) >= 0 ||
r.id === this.guild.id), this._reason);
} catch (error) {
this.client.logger.error(`Mute infraction failed to calculate removeable roles, might want to check this out.\n${error.stack || error}`);
@ -89,7 +89,7 @@ class MuteInfraction extends Infraction {
break;
case 3:
try {
this.member.timeout(this.duration, this._reason);
await this.member.timeout(this.duration, this._reason);
} catch (e) {
this.client.logger.error(`Mute timeout failed:\n${e.stack || e}`);
return this._fail(`COMMAND_MUTE_4FAIL`);

View File

@ -1,3 +1,4 @@
const { AuditLogEvent } = require("discord.js");
const { Observer, Infraction } = require("../../interfaces");
class AuditLogObserver extends Observer {
@ -118,11 +119,13 @@ class AuditLogObserver extends Observer {
async _logRoleMute(oldMember, newMember) {
const { guildWrapper: wrapper } = newMember;
const settings = await wrapper.settings();
console.log(1);
if (!settings.moderation.channel) return undefined;
const mutedRole = settings.mute.role;
if (!mutedRole) return undefined;
const audit = await this._fetchFirstEntry(newMember.guild, newMember.user, 'MemberRoleUpdate');
console.log(audit);
if (!audit) return undefined;
let type = null;
@ -148,6 +151,7 @@ class AuditLogObserver extends Observer {
async _fetchFirstEntry(guild, user, type, subtype = null) {
if (!guild.members.me.permissions.has('ViewAuditLog')) return null;
type = AuditLogEvent[type];
const audit = await guild.fetchAuditLogs({ limit: 1, type });
if (audit.entries.size === 0) return null;

View File

@ -1,4 +1,4 @@
const { EmbedBuilder, Message } = require('discord.js');
const { EmbedBuilder, Message, ChannelType } = require('discord.js');
const { Util } = require('../../../utilities');
const { InvokerWrapper, MessageWrapper } = require('../../client/wrappers');
const { Observer, CommandError } = require('../../interfaces/');
@ -314,13 +314,13 @@ class CommandHandler extends Observer {
},
TEXT_CHANNELS: async (string) => {
const args = Util.parseQuotes(string).map(([str]) => str);
const channels = await guild.resolveChannels(args, null, (channel) => channel.type === 'GUILD_TEXT');
const channels = await guild.resolveChannels(args, null, (channel) => channel.type === ChannelType.GuildText);
if(!channels.length) return { error: true };
return { value: channels };
},
VOICE_CHANNELS: async (string) => {
const args = Util.parseQuotes(string).map(([str]) => str);
const channels = await guild.resolveChannels(args, null, (channel) => channel.type === 'GUILD_VOICE');
const channels = await guild.resolveChannels(args, null, (channel) => channel.type === ChannelType.GuildVoice);
if (!channels.length) return { error: true };
return { value: channels };
},
@ -389,12 +389,12 @@ class CommandHandler extends Observer {
},
TEXT_CHANNEL: async (channel) => {
channel = await guild.resolveChannel(channel);
if(channel.type !== 'GUILD_TEXT') return { error: true };
if(channel.type !== ChannelType.GuildText) return { error: true };
return { error: false, value: channel };
},
VOICE_CHANNEL: async (channel) => {
channel = await guild.resolveChannel(channel);
if(channel.type !== 'GUILD_VOICE') return { error: true };
if(channel.type !== ChannelType.GuildVoice) return { error: true };
return { error: false, value: channel };
},
CHANNEL: async (channel) => {

View File

@ -191,7 +191,7 @@ class GuildLogger extends Observer {
footer: {
text: wrapper.format('MSGLOG_DELETE_FOOTER', { msgID: id, userID: author.id })
},
timestamp: message.createdAt,
timestamp: message.createdAt.toISOString(),
fields: []
};
@ -580,7 +580,7 @@ class GuildLogger extends Observer {
},
description: wrapper.format('MSGLOG_EDIT_JUMP', { guild: guild.id, channel: channel.id, message: oldMessage.id }),
color: CONSTANTS.COLORS.YELLOW,
timestamp: oldMessage.createdAt,
timestamp: oldMessage.createdAt.toISOString(),
fields: []
};

View File

@ -95,12 +95,16 @@ class Infraction {
if (moderation.channel) {
if (moderation.infractions.includes(this.type)) {
this._moderationLog = await this.client.resolver.resolveChannel(moderation.channel, true, this.guild);
if (!this._moderationLog) return;
if (this._moderationLog) {
this.modlogId = this._moderationLog.id;
try {
this._logMessage = await this._moderationLog.send({ embeds: [this._embed()] });
this.modLogMessageId = this._logMessage.id;
} catch (e) { } //eslint-disable-line no-empty
} catch (e) {
console.log(e);
} //eslint-disable-line no-empty
}
} else {
this.client.logger.debug(`Did not log infraction ${this.type} because it is not in the infractions.`);
}
@ -160,7 +164,7 @@ class Infraction {
name: `${this.target.displayName || this.target.username || this.target.name} (${this.targetId})`,
icon_url: this.targetIcon //eslint-disable-line camelcase
},
timestamp: this.timestamp,
timestamp: new Date(this.timestamp).toISOString(),
color: this.color,
footer: {
text: `》 Case ${this.case}`