-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.bots.js
40 lines (34 loc) · 1.02 KB
/
data.bots.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
const clone = require('clone');
const bots = require('./data.storage.file').get('bots');
//ïðåâðàòèì âñå ñîáûòèÿ xxx:1;2;3 â òðè ñîáûòèÿ - xxx:1, xxx:2 è xxx:3 è ò.ä.
Object.keys(bots.data).forEach( bot_token => {
const bot = bots.data[bot_token];
splitActionsWithSemicolon(bot);
bot.wf.forEach( wf_step => {
splitActionsWithSemicolon(wf_step);
})
})
function splitActionsWithSemicolon(o) {
const actions = o.on || {};
Object.keys(actions).forEach( key => {
const prefix = key.split(':')[0];
const subkeys = key.split(':')[1] || '';
if (subkeys.indexOf(';') !== -1) {
subkeys.split(';').forEach( subkey => {
o.on[prefix + ':' + subkey] = o.on[key];
})
delete o.on[key];
}
});
}
//íåëüçÿ ìåíÿòü áîòîâ íà ëåòó, âîò òàê-òî
bots.data = Object.freeze(bots.data);
Object.keys(bots.data).forEach( (bot_token, index) => {
console.log(` bot[${index}]`, bot_token);
})
function get(bot_token) {
return clone(bots.data[bot_token]);
}
module.exports = {
get,
}