Support role and user IDs in inboxServerPermission. Allow specifying multiple values for inboxServerPermission.

master
Dragory 2018-09-20 22:27:59 +03:00
parent 8d475609fb
commit 1ec0a811d9
2 changed files with 30 additions and 2 deletions

View File

@ -135,4 +135,13 @@ if (! Array.isArray(finalConfig['mainGuildId'])) {
finalConfig['mainGuildId'] = [finalConfig['mainGuildId']];
}
// Make sure inboxServerPermission is always an array
if (! Array.isArray(finalConfig['inboxServerPermission'])) {
if (finalConfig['inboxServerPermission'] == null) {
finalConfig['inboxServerPermission'] = [];
} else {
finalConfig['inboxServerPermission'] = [finalConfig['inboxServerPermission']];
}
}
module.exports = finalConfig;

View File

@ -78,8 +78,20 @@ function postError(str) {
* @returns {boolean}
*/
function isStaff(member) {
if (! config.inboxServerPermission) return true;
return member.permission.has(config.inboxServerPermission);
if (config.inboxServerPermission.length === 0) return true;
return config.inboxServerPermission.some(perm => {
if (isSnowflake(perm)) {
// If perm is a snowflake, check it against the member's user id and roles
if (member.id === perm) return true;
if (member.roles.includes(perm)) return true;
} else {
// Otherwise assume perm is the name of a permission
return member.permission.has(perm);
}
return false;
});
}
/**
@ -274,6 +286,11 @@ function setDataModelProps(target, props) {
}
}
const snowflakeRegex = /^[0-9]{17,}$/;
function isSnowflake(str) {
return snowflakeRegex.test(str);
}
module.exports = {
BotError,
@ -302,4 +319,6 @@ module.exports = {
trimAll,
setDataModelProps,
isSnowflake,
};