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

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,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.