3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-18 15:45:03 +00:00

mute command can now remove muted role from users who are not in the mutes DB table

This commit is contained in:
roflmaoqwerty 2020-01-19 11:23:51 +11:00
parent 0818b0479b
commit 3172abe5a8
2 changed files with 21 additions and 8 deletions

View file

@ -892,16 +892,17 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
async unmuteCmd(msg: Message, args: { user: string; time?: number; reason?: string; mod?: Member }) {
const user = await this.resolveUser(args.user);
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
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");
return;
}
// Find the server member to unmute
const memberToUnmute = await this.getMember(user.id);
if (!memberToUnmute) {
const isBanned = await this.isBanned(user.id);
const prefix = this.guildConfig.prefix;

View file

@ -275,14 +275,18 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
caseArgs: Partial<CaseArgs> = {},
): Promise<UnmuteResult> {
const existingMute = await this.mutes.findExistingMuteForUserId(userId);
if (!existingMute) return;
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
if (!existingMute && !this.hasMutedRole(member)) return;
if (unmuteTime) {
// Schedule timed unmute (= just set the mute's duration)
if (!existingMute) {
await this.mutes.addMute(userId, unmuteTime);
} else {
await this.mutes.updateExpiryTime(userId, unmuteTime);
}
} else {
// Unmute immediately
if (member) {
@ -295,9 +299,10 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
`Member ${userId} not found in guild ${this.guild.name} (${this.guildId}) when attempting to unmute`,
);
}
if (existingMute) {
await this.mutes.clear(userId);
}
}
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
@ -338,6 +343,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", [], {
options: [
{