2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-02 23:25:20 +00:00

Add isMaster util function

This commit is contained in:
GingerPlusPlus
2018-05-04 19:51:49 +02:00
parent 7b34308462
commit 2fafa93b10
6 changed files with 39 additions and 16 deletions

20
utils/config.js Normal file
View File

@@ -0,0 +1,20 @@
'use strict';
const config = require('../config');
const eq = require('./eq');
const masterById = /^\d+$/.test(config.master);
const masterByUsername = /^@?\w+$/.test(config.master);
if (!masterById && !masterByUsername) {
throw new Error('Invalid value for `master` in config file: ' +
config.master);
}
const isMaster = masterById
? user => user.id === Number(config.master)
: user => user.username && eq.username(user.username, config.master);
module.exports = {
isMaster,
};