Remove manual mutes (#33)
The unmute command can now unmute users who have had the mute role manually applied to them
This commit is contained in:
parent
5d49a3b5eb
commit
4eb28c3bd8
2 changed files with 24 additions and 9 deletions
|
@ -892,16 +892,16 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
async unmuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod?: Member }) {
|
async unmuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod?: Member }) {
|
||||||
const user = await this.resolveUser(args.user);
|
const user = await this.resolveUser(args.user);
|
||||||
if (!user) return this.sendErrorMessage(msg.channel, `User not found`);
|
if (!user) return this.sendErrorMessage(msg.channel, `User not found`);
|
||||||
|
const memberToUnmute = await this.getMember(user.id);
|
||||||
|
const mutesPlugin = this.getPlugin<MutesPlugin>("mutes");
|
||||||
|
const hasMuteRole = mutesPlugin.hasMutedRole(memberToUnmute);
|
||||||
|
|
||||||
// Check if they're muted in the first place
|
// Check if they're muted in the first place
|
||||||
if (!(await this.mutes.isMuted(args.user))) {
|
if (!(await this.mutes.isMuted(args.user)) && !hasMuteRole) {
|
||||||
this.sendErrorMessage(msg.channel, "Cannot unmute: member is not muted");
|
this.sendErrorMessage(msg.channel, "Cannot unmute: member is not muted");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the server member to unmute
|
|
||||||
const memberToUnmute = await this.getMember(user.id);
|
|
||||||
|
|
||||||
if (!memberToUnmute) {
|
if (!memberToUnmute) {
|
||||||
const isBanned = await this.isBanned(user.id);
|
const isBanned = await this.isBanned(user.id);
|
||||||
const prefix = this.guildConfig.prefix;
|
const prefix = this.guildConfig.prefix;
|
||||||
|
|
|
@ -275,14 +275,18 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
caseArgs: Partial<CaseArgs> = {},
|
caseArgs: Partial<CaseArgs> = {},
|
||||||
): Promise<UnmuteResult> {
|
): Promise<UnmuteResult> {
|
||||||
const existingMute = await this.mutes.findExistingMuteForUserId(userId);
|
const existingMute = await this.mutes.findExistingMuteForUserId(userId);
|
||||||
if (!existingMute) return;
|
|
||||||
|
|
||||||
const user = await this.resolveUser(userId);
|
const user = await this.resolveUser(userId);
|
||||||
const member = await this.getMember(userId, true); // Grab the fresh member so we don't have stale role info
|
const member = await this.getMember(userId, true); // Grab the fresh member so we don't have stale role info
|
||||||
|
|
||||||
|
if (!existingMute && !this.hasMutedRole(member)) return;
|
||||||
|
|
||||||
if (unmuteTime) {
|
if (unmuteTime) {
|
||||||
// Schedule timed unmute (= just set the mute's duration)
|
// Schedule timed unmute (= just set the mute's duration)
|
||||||
await this.mutes.updateExpiryTime(userId, unmuteTime);
|
if (!existingMute) {
|
||||||
|
await this.mutes.addMute(userId, unmuteTime);
|
||||||
|
} else {
|
||||||
|
await this.mutes.updateExpiryTime(userId, unmuteTime);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unmute immediately
|
// Unmute immediately
|
||||||
if (member) {
|
if (member) {
|
||||||
|
@ -295,8 +299,9 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
`Member ${userId} not found in guild ${this.guild.name} (${this.guildId}) when attempting to unmute`,
|
`Member ${userId} not found in guild ${this.guild.name} (${this.guildId}) when attempting to unmute`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (existingMute) {
|
||||||
await this.mutes.clear(userId);
|
await this.mutes.clear(userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
|
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
|
||||||
|
@ -308,6 +313,9 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
} else {
|
} else {
|
||||||
noteDetails.push(`Unmuted immediately`);
|
noteDetails.push(`Unmuted immediately`);
|
||||||
}
|
}
|
||||||
|
if (!existingMute) {
|
||||||
|
noteDetails.push(`Removed external mute`);
|
||||||
|
}
|
||||||
|
|
||||||
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
|
const casesPlugin = this.getPlugin<CasesPlugin>("cases");
|
||||||
const createdCase = await casesPlugin.createCase({
|
const createdCase = await casesPlugin.createCase({
|
||||||
|
@ -338,6 +346,13 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hasMutedRole(member: Member) {
|
||||||
|
if (member.roles.includes(this.getConfig().mute_role)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@d.command("mutes", [], {
|
@d.command("mutes", [], {
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue