-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (46 loc) · 1.31 KB
/
main.js
File metadata and controls
52 lines (46 loc) · 1.31 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
const API = require('./API')
const App = require('./App')
const Package = require('./Package')
const Util = require('./Util')
class Main {
constructor() {
App.init().then(() => {
this.api = new API()
return this.api.authorize()
}).then(() => {
this.initEvents()
})
}
initEvents() {
this.api.on('ready', () => {
for (const pack of Util.settings.package)
this.packages.push(Package.getPackage(pack))
this.api.listen()
})
this.api.on('error', err => {
if (err.message === 'No live was found') {
Util.msgbox({
type: 'warning',
message: Util._('canNotFindLive') + Util._('doAgain'),
detail: Util._('wait'),
buttons: [Util._('yes'), Util._('cancel')],
only: 0,
}).then(() => this.api.reacquire())
} else if (err.message === 'Can not find chat') {
Util.msgbox({
type: 'warning',
message: Util._('canNotFindChat') + Util._('doAgain'),
detail: Util._('wait'),
buttons: [Util._('yes'), Util._('cancel')],
only: 0,
}).then(() => this.api.reacquire())
} else
Util.showError(err)
})
this.api.on('message', data => {
for (const pack of this.packages)
pack.message(data)
})
}
}
module.exports = Main