-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
178 lines (167 loc) · 5.55 KB
/
index.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// IMPORTS
const axios = require("axios");
const Discord = require("discord.js");
const dotenv = require('dotenv');
// const { GoogleSpreadsheet } = require("google-spreadsheet");
// PROJECT IMPORTS
// const creds = require("./client_secret.json");
// const config = require("./config.json");
const constants = require("./constants");
const draft = require("./drafting-utils");
dotenv.config();
const client = new Discord.Client();
// Using battlefy api endpoint
const tournamentApi = axios.create({
baseURL: "https://dtmwra1jsgyb0.cloudfront.net/"
});
let isActive = false;
client.on("message", async function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(constants.PREFIX)) return;
const commandBody = message.content.slice(constants.PREFIX.length);
const args = commandBody.split(" ");
const command = args.shift().toLowerCase();
let resp, selector, team1, team2;
// Command handler
switch (command) {
case "help":
message.channel.send(constants.HELP_MSG);
break;
// case "mh":
// resp = "";
// if (args[0] === undefined) {
// return;
// }
// selector = args[0];
// if (Object.keys(constants.TEAM_MAP).includes(selector)) {
// let translated = constants.TEAM_MAP[selector];
// let res = await getTournamentStageMatches("605ecea334f4d511922a813c");
// resp +=
// "Pulling match history for " +
// translated +
// " : \n" +
// "##################################### \n";
// resp +=
// "W: " +
// res[translated][0].length +
// " L: " +
// res[translated][1].length +
// "\n";
// for (let i = 0; i < res[translated][0].length; i++) {
// resp += res[translated][0][i] + " **Win** \n";
// }
// resp += "------------------------------------- \n";
// for (let i = 0; i < res[translated][1].length; i++) {
// resp += res[translated][1][i] + " **Loss** \n";
// }
// } else {
// resp = "Not a valid argument. Format is as follows: !mh [TEAM]. ";
// }
// message.channel.send(resp);
// break;
case "draftlol":
if (args.length <= 1) {
return;
}
team1 = args[0];
team2 = args[1];
let blueBanCount = (args[2] ? args[2] : 5);
let redBanCount = (args[3] ? args[3] : 5);
resp = await draft.generateDraftLOL(team1, team2, blueBanCount, redBanCount);
message.channel.send(resp);
break;
case "prodraft":
if (args.length <= 1) {
return;
}
team1 = args[0];
team2 = args[1];
resp = await draft.generateProDraft(team1, team2);
message.channel.send(resp);
break;
// case "league-rules":
// message.channel.send("Rules: " + constants.RULES);
// break;
// case "league-signup":
// message.channel.send("Players: " + constants.SIGNUPS.PLAYER);
// message.channel.send("Captains: " + constants.SIGNUPS.CAPTAIN);
// break;
// case "standings":
// let res = await getTournamentStageMatches("");
// let sorted = Object.keys(res).map(function(key) {
// return [key, [res[key][0].length, res[key][1].length]];
// });
// // console.log(sorted);
// // First = Wins, Second = Losses
// // Sort first based on wins, second on who has lost more
// sorted.sort(function(first, second) {
// if (first[1][0] === second[1][0]) {
// return first[1][1] - second[1][1];
// } else {
// return second[1][0] - first[1][0];
// }
// });
// // console.log(sorted);
// let standings = "Here are the current standings: \n \n";
// for (item in sorted) {
// standings +=
// "*" +
// (parseInt(item) + 1).toString() +
// ": " +
// sorted[item][0] +
// "* (W: " +
// sorted[item][1][0] +
// " L: " +
// sorted[item][1][1] +
// ")\n";
// }
// message.channel.send(standings);
// break;
default:
// message.channel.send("Not a valid command. Type !ff for help. ");
break;
}
});
client.login(process.env.DISCORD_TOKEN);
async function getTournamentStageMatches(stage) {
const response = await tournamentApi.get(`stages/${stage}/matches`);
let teams = {
// "Rubber Ducky Team": [[], []],
// "Luck of the Draw": [[], []],
// "ULTIMATE DAN": [[], []],
// "On the Spot": [[], []],
// "Mailbox's Angels": [[], []],
// "BaeDCarry Fan Club": [[], []],
// "Natural Big Boys Club": [[], []],
// "Frank n' Beans": [[], []],
// "LAMAR JACKSON FAN CLUB": [[], []],
// "Big Shmeat Gang": [[], []]
};
Object.values(constants.TEAM_MAP_10).forEach(key => {
teams[key.toString()] = [[], []]
})
for (match in response.data) {
var winner;
if (response.data[match].top.winner === true) {
winner = "top";
teams[response.data[match].top.team.name][0].push(
response.data[match].bottom.team.name
);
teams[response.data[match].bottom.team.name][1].push(
response.data[match].top.team.name
);
} else if (response.data[match].top.winner === false) {
winner = "bottom";
teams[response.data[match].top.team.name][1].push(
response.data[match].bottom.team.name
);
teams[response.data[match].bottom.team.name][0].push(
response.data[match].top.team.name
);
} else {
winner = "undefined";
}
response.data[match].winner = winner;
}
return teams;
}