-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinitFunctions.js
More file actions
60 lines (43 loc) · 1.48 KB
/
initFunctions.js
File metadata and controls
60 lines (43 loc) · 1.48 KB
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
51
52
53
54
55
56
57
58
59
60
const fs = require('fs');
const dir = './commands/handler/functions/';
let data = {
functions: {},
allChannels: {},
allowedChannelsFunctions: {}
};
/**
* Возвращает функции-обработчики сообщений пользователя
* @return {Object} functions Объект функций модуля
* @return {Object} allChannels Объект названий функций, вызываемых при
* сообщении в любом канале
* @return {Object} allowedChannelsFunctions Объект каналов и категориий,
* содержашие объекты функций
*/
module.exports = async () => {
const files = fs.readdirSync(dir);
for (const file of files) {
const timeStart = process.hrtime();
const name = file.split('.')[0];
let func = require('./functions/' + file);
if (func[name] && func[name].active) {
func = func[name];
}
if (func.active) data.functions[name] = await func.init();
if (func.active) {
if (func.allChannels) {
data.allChannels[name] = true;
} else {
for (let id in func.allowedChannels) {
if (!data.allowedChannelsFunctions[id]) {
data.allowedChannelsFunctions[id] = {};
}
data.allowedChannelsFunctions[id][name] = func.allowedChannels[id];
}
}
}
const timeEnd = process.hrtime(timeStart);
const pref = (timeEnd[0] * 1000) + (timeEnd[1] / 1000000);
log.initText += log.load(dir + file, pref, func.active);
}
return data;
};