-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
50 lines (42 loc) · 1.07 KB
/
user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
const _ = require('lodash');
const debug = require('debug')('user');
const Settings = require('./settings');
let adminIds;
/**
* Get settings value
* @param {Number} chatId
* @returns {Promise}
*/
let getWordCount = function(chatId) {
return Settings.getOne({key: 'wordCount', chatId: chatId});
};
/**
* Set settings value
* @param {Number} wordCount
* @param {Number} chatId
* @returns {Promise}
*/
let setWordCount = function(wordCount, chatId) {
return Settings.set({key: 'wordCount', chatId: chatId}, wordCount);
};
/**
* Determines if user with gived id is an admin
* @param {Number} chatId Chat / user id
* @returns {Boolean}
*/
const isAdmin = function(chatId) {
return getAdminIds().indexOf(chatId) !== -1;
};
const getAdminIds = function() {
if (_.isUndefined(adminIds)) {
adminIds = _.map((process.env.ADMIN_IDS || '').split(','), number => parseInt(number));
}
return adminIds;
};
module.exports = {
getWordCount: getWordCount,
setWordCount: setWordCount,
getAdminIds: getAdminIds,
isAdmin: isAdmin
};