-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.js
74 lines (67 loc) · 1.88 KB
/
API.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
const {EventEmitter} = require('events')
const TwitCasting = require('./API/TwitCasting')
const Twitch = require('./API/Twitch')
const Twitter = require('./API/Twitter')
const YouTube = require('./API/YouTube')
const Util = require('./Util')
class API extends EventEmitter {
/**
* Arrange API methods
* @extends EventEmitter
*/
constructor() {
super()
this.names = Util.settings.app.service
this.services = {}
for (const service of this.names) {
switch (service) {
case 'twitcasting': this.services.twitcasting = new TwitCasting(); break
case 'twitch': this.services.twitch = new Twitch(); break
case 'twitter': this.services.twitter = new Twitter(); break
case 'youtube': this.services.youtube = new YouTube(); break
default: () => {
Util.showError(`${Util._('invalidService')} - "${service}"`)
this.names = this.names.filter(i => i !== service)
}
}
}
for (const name in this.services) {
this.services[name].on('error', data => this.emit('error', data))
this.services[name].on('ready', data => this.emit('ready', data))
this.services[name].on('message', data => this.emit('message', data))
}
}
/**
* Authorize
*/
authorize() {
for (const name in this.services)
this.services[name].authorize()
}
/**
* Get message
* @param {Number} [timeout] interval
*/
listen(timeout) {
for (const name in this.services)
this.services[name].listen(timeout)
}
/**
* Send message
* @param {String} message content
*/
send(message) {
for (const name in this.services)
this.services[name].send(message)
}
/**
* Get live info again
*/
reacquire(service) {
this.services[service].reacquire()
}
get service() {
return this.services
}
}
module.exports = API