-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
twitch.js
69 lines (65 loc) · 2.38 KB
/
twitch.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
const loggers = require("../libs/loggers");
const settings = require("../libs/settings");
const state = require("../libs/twitch/state");
const twitchLogin = require("../libs/twitch/login");
const chatJoin = require("../libs/twitch/chat/join");
const setEvent = require("../libs/twitch/api/setEvent");
const getEvents = require("../libs/twitch/api/getEvents");
const chatConnect = require("../libs/twitch/chat/connect");
const addCommand = require("../libs/twitch/api/addCommand");
const updateReward = require("../libs/twitch/api/updateReward");
const updateCommand = require("../libs/twitch/api/updateCommand");
const removeCommand = require("../libs/twitch/api/removeCommand");
const getRewardList = require("../libs/twitch/api/getRewardList");
const getCommandList = require("../libs/twitch/api/getCommandList");
const getCommandNames = require("../libs/twitch/api/getCommandNames");
const getLastFollowers = require("../libs/twitch/api/getLastFollowers");
const logger = loggers.get("server");
module.exports = {
async login() {
const user = await twitchLogin();
await chatConnect();
const join = await chatJoin(user.display_name);
if (!join.alreadyJoined) {
logger.info("Chat connected");
settings.set("twitch.currentChannel", user.display_name);
}
return user;
},
addCommand(command) {
return addCommand(command).then(({ dataValues }) => {
this.notify("twitch.addCommand", dataValues);
return dataValues;
});
},
updateCommand(command) {
return updateCommand(command).then((result) => {
this.notify("twitch.updateCommand", command);
return result;
});
},
removeCommand(command) {
return removeCommand(command).then((result) => {
this.notify("twitch.removeCommand", command);
return result;
});
},
updateReward(reward) {
return updateReward(reward).then((result) => {
this.notify("twitch.updateReward", reward);
return result;
});
},
getEvents: () => getEvents(),
setEvent: (event) => setEvent(event),
getRewardList: () => getRewardList(),
getCommandList: () => getCommandList(),
getCommandNames: () => getCommandNames(),
getLastFollowers: () => getLastFollowers(),
getState: () => state.get(),
updateState: (state) => state.update(state),
getSettings: () => settings.getAll("twitch."),
setSetting: (key, value) => {
return settings.set(`twitch.${key}`, value);
},
};