ModActions: add helper function for checking if user can act on another

This commit is contained in:
Dragory 2018-07-12 01:42:18 +03:00
parent 22e2dbced1
commit 7401cdb88c

View file

@ -272,16 +272,10 @@ export class ModActionsPlugin extends Plugin {
}
// Make sure we're allowed to mute this member
if (msg.member.id !== args.member.id) {
const ourLevel = this.getMemberLevel(msg.member);
const memberLevel = this.getMemberLevel(args.member);
if (ourLevel <= memberLevel) {
msg.channel.createMessage(
errorMessage("Cannot mute: insufficient permissions")
);
if (!this.canActOn(msg.member, args.member)) {
msg.channel.createMessage(errorMessage("Cannot mute: insufficient permissions"));
return;
}
}
// Convert mute time from e.g. "2h30m" to milliseconds
const muteTime = args.time ? convertDelayStringToMS(args.time) : null;
@ -382,6 +376,16 @@ export class ModActionsPlugin extends Plugin {
}
}
protected canActOn(member1, member2) {
if (member1.id === member2.id) {
return true;
}
const ourLevel = this.getMemberLevel(member1);
const memberLevel = this.getMemberLevel(member2);
return (ourLevel > memberLevel);
}
/**
* Attempts to message the specified user through DMs and/or the message channel.
* Returns a promise that resolves to a boolean indicating whether we were able to message them or not.