-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservices.js
112 lines (90 loc) · 2.35 KB
/
services.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @file Connect all modules and make sure all resources are functional.
*
* @name Jonin-Services
* @usage new services()
* @version 1.0.0
*/
/**
* This function merges multiple objects into one.
*
* @name mergify
* @param {object} main Master object (All other objects merge into this).
* @param {array} subs Array of objects to merge into `main`.
* @return {object} Master object (`main`) with `subs` merged.
*/
Object.mergify = (main, ...subs) => {
if (typeof main !== `object` || main === null) throw new Error(`Must pass an object type data`)
for (let obj of subs) if (typeof obj !== `object` || obj === null) throw new Error(`Must pass an object type data`)
for (let obj of subs) for (let attrname in obj) main[attrname] = obj[attrname]
return main
}
/**
* This class sets-up all the modules.
*
* @name services
* @param {array} reject Array of modules that will not be set-up.
* @return {null}
*/
module.exports = class services {
constructor(key) {
let [files, modules] = [[`binary`, `chatbot`, `env`, `profanity`, `sloc`, `weather`], [`fetch`, `moment`]]
for (let file of files) this[file] = new (require(`./modules/${file}/${file}.js`))()
for (let file of modules) this[file] = require(`./modules/${file}/${file}.js`)
if (key && key.osu) this.osu = new (require(`./modules/osu/osu.js`))(key.osu)
}
/**
* @File Binary converter.
*
* @name binary
*/
binary() { this.binary }
/**
* @File Chatbot with history.
*
* @name chatbot
*/
chatbot() { this.chatbot }
/**
* @File Access `.env` through process.
*
* @name env
*/
env() { this.env }
/**
* @File node-fetch module.
*
* @name fetch
*/
fetch() { this.fetch }
/**
* @File moment-duration-format module.
*
* @name moment
*/
moment() { this.moment }
/**
* @File osu! info module.
*
* @name osu
*/
osu() { this.osu }
/**
* @File Clear out profanity from text.
*
* @name profanity
*/
profanity() { this.profanity }
/**
* @File File data and sloc getter.
*
* @name sloc
*/
sloc() { this.sloc }
/**
* @File Current/Forcast weather fetcher.
*
* @name weather
*/
weather() { this.weather }
}