-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_commands.js
147 lines (120 loc) · 4.11 KB
/
_commands.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
Contains all logic responsible for answering to custom commands
# Potential USAGE
Games - Show games that can be bet on - outputs gameID, date, time, team names.
/games - shows all games
/games [nhl, nfl, nba] - shows the current games for the specified league
/games [current, upcoming] - shows current or upcoming games
Bet - Place/View your bets
*/
controller.setupWebserver(8657, function (err, webserver) {
controller.createWebhookEndpoints(webserver);
});
controller.on('slash_command', function (slashCommand, message) {
console.log("Received command: " + message.command);
switch (message.command) {
case "/games":
showGames(slashCommand, message);
break;
case "/bet":
placeBet(slashCommand, message);
break;
case "/stats":
showStats(slashCommand, message);
break;
case "/leaderboard":
showLeaderboard(slashCommand, message);
break;
default:
slashCommand.replyPublic(message, "I'm afraid I don't know how to " + message.command + " yet.");
}
});
/**
* Show upcoming games
* Optionally show only upcoming games of a specified league
*/
function showGames(slashCommand, message) {
var gameType = message.text.toLowerCase();
var gameList = null;
switch (gameType) {
case "nba":
gameList = gbotSportsAPI.getNbaGames();
break;
case "nhl":
gameList = gbotSportsAPI.getNhlGames();
break;
case "nfl":
// to do
default:
slashCommand.replyPublic(
message,
"Please choose a league to display (e.g /games nba)",
function () { /* Response sent*/ }
);
}
// Resolve promise - output games
if (gameList != null & gameList instanceof Promise) {
gameList.then(function (games) {
var responseObj = gbotUtil.createUpcomingGamesAttachment(games);
slashCommand.replyPublic(message, responseObj, function () {
// Response sent
});
}).catch(function (err) {
console.error("Error in showGames(): ", err);
});
}
}
function placeBet(slashCommand, message) {
// TODO
// if (gameType == "mine") {
// var responseObj = getMyBets(bets, slashCommand);
// slashCommand.reply(message, responseObj, function (err, resp) {
// console.log(err, resp);
// });
// }
// else if (gameType == "all") {
// var responseObj = getAllBets(bets);
// slashCommand.reply(message, responseObj, function (err, resp) {
// console.log(err, resp);
// });
// }
// else {
// slashCommand.replyPublic(message, "Use /bets all or /bets mine to see all bets or your bets. Or, use @stellabot place bet to place a bet.", function () { });
// }
var arg = message ? message.text : "";
switch (arg) {
case "mine":
var responseObj = getMyBets(message);
break;
case "all":
var responseObj = getAllBets(message);
break;
case "place":
placeBet(bot, message);
default:
slashCommand.replyPublic(
message,
"Please try again. Usage: /bet mine, /bet all, /bet place",
function () { /* Response sent*/ }
);
}
slashCommand.replyPublic(message, responseObj, function () {
// Response sent
});
}
function showStats(slashCommand, message) {
// TODO
}
function showLeaderboard(slashCommand, message) {
var gameType = message ? message.text : "";
var leaderboard = [
{ rank: 1, name: "stellarxo", points: 10 },
{ rank: 2, name: "alisterdev", points: 6 },
{ rank: 3, name: "dramos", points: 3 },
{ rank: 4, name: "blynks", points: 1 },
];
var responseObj = getLeaderboard(leaderboard);
slashCommand.replyPublic(message, responseObj, function () {
// Response sent
});
}