From ce6b4307714e0a6b661730b7fd220234b6cfa44a Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 21 Jul 2022 15:47:50 +0300 Subject: [PATCH] bugfixes --- .../components/commands/utility/Poll.js | 2 +- src/structure/components/infractions/Mute.js | 12 ++++++------ src/structure/components/observers/AuditLog.js | 4 ++++ .../components/observers/CommandHandler.js | 10 +++++----- .../components/observers/GuildLogging.js | 4 ++-- src/structure/interfaces/Infraction.js | 18 +++++++++++------- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/structure/components/commands/utility/Poll.js b/src/structure/components/commands/utility/Poll.js index e75714b..25236a9 100644 --- a/src/structure/components/commands/utility/Poll.js +++ b/src/structure/components/commands/utility/Poll.js @@ -86,7 +86,7 @@ class PollCommand extends SlashCommand { }), fields: questions, color: 619452, - timestamp: new Date() + timestamp: new Date().toISOString() }; let pollMsg = null; diff --git a/src/structure/components/infractions/Mute.js b/src/structure/components/infractions/Mute.js index 3756750..6e063a3 100644 --- a/src/structure/components/infractions/Mute.js +++ b/src/structure/components/infractions/Mute.js @@ -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`); diff --git a/src/structure/components/observers/AuditLog.js b/src/structure/components/observers/AuditLog.js index 01933c5..9213ea4 100644 --- a/src/structure/components/observers/AuditLog.js +++ b/src/structure/components/observers/AuditLog.js @@ -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; diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index cc872d2..d1a393d 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -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) => { diff --git a/src/structure/components/observers/GuildLogging.js b/src/structure/components/observers/GuildLogging.js index 04b7dae..a8feb64 100644 --- a/src/structure/components/observers/GuildLogging.js +++ b/src/structure/components/observers/GuildLogging.js @@ -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: [] }; diff --git a/src/structure/interfaces/Infraction.js b/src/structure/interfaces/Infraction.js index 977fc57..3b8810b 100644 --- a/src/structure/interfaces/Infraction.js +++ b/src/structure/interfaces/Infraction.js @@ -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; - 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 + 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) { + 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}`