ModActions: add helper function for checking if user can act on another
This commit is contained in:
parent
22e2dbced1
commit
7401cdb88c
1 changed files with 13 additions and 9 deletions
|
@ -272,15 +272,9 @@ 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")
|
||||
);
|
||||
return;
|
||||
}
|
||||
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
|
||||
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue