diff --git a/src/structure/components/commands/moderation/Mute.js b/src/structure/components/commands/moderation/Mute.js index c81d14d..5d281a0 100644 --- a/src/structure/components/commands/moderation/Mute.js +++ b/src/structure/components/commands/moderation/Mute.js @@ -16,6 +16,7 @@ class MuteCommand extends ModerationCommand { guildOnly: true, showUsage: true, memberPermissions: ['MODERATE_MEMBERS'] + // Mute client permissions are handled in the infraction.verify due to being able to use both timeout and role based mutes }); } diff --git a/src/structure/components/infractions/Unmute.js b/src/structure/components/infractions/Unmute.js index 369caa0..da1d056 100644 --- a/src/structure/components/infractions/Unmute.js +++ b/src/structure/components/infractions/Unmute.js @@ -39,6 +39,8 @@ class UnmuteInfraction extends Infraction { let removedRoles = [], muteType = null, role = null; + const settings = await this.guild.settings(), + now = Date.now(); let callback = null; const memberWrapper = await this.guild.memberWrapper(this.member); @@ -53,18 +55,19 @@ class UnmuteInfraction extends Infraction { muteType = callback.infraction.data.muteType; //eslint-disable-line prefer-destructuring role = callback.infraction.data.muteRole; //eslint-disable-line prefer-destructuring } else { - role = this.guild._settings.mute.role; //eslint-disable-line prefer-destructuring + role = settings.mute.role; //eslint-disable-line prefer-destructuring } } + if (!removedRoles) removedRoles = []; // So it doesn't error out later if the property is undefined role = await this.guild.resolveRole(role); // The role used in the mute was probably deleted but an unmute was attempted? // Idk which would be the ideal solution, // to attempt removing the default role anyway or throw an error due to unexpected state // doing this for now - if (!role) role = await this.guild.resolveRole(this.guild._settings.mute.role); - - if (!callback) { + if (!role) role = await this.guild.resolveRole(settings.mute.role); + + if (!callback && settings.mute.type < 3) { if (role && this.member.roles.cache.has(role.id)) { try { this.member.roles.remove(role, this._reason); @@ -75,6 +78,7 @@ class UnmuteInfraction extends Infraction { return this._fail('C_UNMUTE_CANNOTFINDMUTE'); } } + const roles = [...new Set([...this.member.roles.cache.map((r) => r.id), ...removedRoles])]; @@ -107,6 +111,10 @@ class UnmuteInfraction extends Infraction { return this._fail('C_UNMUTE_3FAIL'); } break; + case 3: + // Unironically hate this property name, why is it so cumbersome + if (this.member.communicationDisabledUntilTimestamp > now) await this.member.timeout(null, this._reason); + break; } if(callback) this.client.moderationManager.removeCallback(callback); diff --git a/src/structure/interfaces/Infraction.js b/src/structure/interfaces/Infraction.js index 1aa8443..4baad63 100644 --- a/src/structure/interfaces/Infraction.js +++ b/src/structure/interfaces/Infraction.js @@ -406,8 +406,13 @@ class Infraction { }; const member = await this.guild.memberWrapper(this.target); const callback = await member.getCallback(this.type, true); - this.duration = duration; + + if (this.data.muteType === 3) { + const time = this.callback - Date.now(); + await member.timeout(time < 0 ? null : time, `Duration edit of case ${this.case}`); + } + if(callback) await this.client.moderationManager.removeCallback(callback); await this.client.moderationManager.handleCallbacks([this.json]); @@ -442,7 +447,7 @@ class Infraction { return infraction; } - this._patch(data); + await this._patch(data); return this; } diff --git a/src/structure/interfaces/commands/SettingsCommand.js b/src/structure/interfaces/commands/SettingsCommand.js index 94cc59a..bfc3843 100644 --- a/src/structure/interfaces/commands/SettingsCommand.js +++ b/src/structure/interfaces/commands/SettingsCommand.js @@ -114,7 +114,8 @@ class SettingsCommand extends SlashCommand { if (!result.error) { settings[setting.name] = _setting; await guild.updateSettings(settings); - await invoker.reply({ ...obj, emoji: 'success', _edit: invoker.replied }); + const emoji = result.emoji ? result.emoji : 'success'; + await invoker.reply({ ...obj, emoji, _edit: invoker.replied }); } else { await invoker.reply({ ...obj, emoji: 'failure', _edit: invoker.replied }); } diff --git a/src/utilities/SettingsMigrator.js b/src/utilities/SettingsMigrator.js index 82f85c8..65db1e6 100644 --- a/src/utilities/SettingsMigrator.js +++ b/src/utilities/SettingsMigrator.js @@ -221,7 +221,7 @@ class SettingsMigrator { settings.mute = { role: result.muterole || null, type: result.mutetype || 0, - defaultDuration: 3600, + default: 3600, permanent: false };