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']]; 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; module.exports = finalConfig;

View File

@ -78,8 +78,20 @@ function postError(str) {
* @returns {boolean} * @returns {boolean}
*/ */
function isStaff(member) { function isStaff(member) {
if (! config.inboxServerPermission) return true; if (config.inboxServerPermission.length === 0) return true;
return member.permission.has(config.inboxServerPermission);
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 = { module.exports = {
BotError, BotError,
@ -302,4 +319,6 @@ module.exports = {
trimAll, trimAll,
setDataModelProps, setDataModelProps,
isSnowflake,
}; };