-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraftbot.js
More file actions
137 lines (123 loc) · 3.95 KB
/
draftbot.js
File metadata and controls
137 lines (123 loc) · 3.95 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
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
const util = require('/home/codenaugh/bots/util/util');
require('log-timestamp')
const err_formatting = 'Formatting Error. You may have forgotten the -, please try again.\nBase Command: **.draft** --- Example: **.draft-6.Sumeria.Scythia.Australia**\nBase Command: **.draftteam** Example (4v4): **.draftteam-8.2**';
process.on("uncaughtException", (err) => {
console.log("draftbot " + err);
});
// create an event listener for messages
util.client.on('message', message =>
{
let content = message.content;
if(content.startsWith(".showguilds")) {
message.delete();
guilds = util.client.guilds.array();
for ( var i = 0 ; i < guilds.length; i++ ) {
console.log(guilds[i].name);
}
//util.client.guilds.get('id').leave()
}
if(content.startsWith(".draftteam"))
{
const contentSplit = content.split('-');
if(contentSplit.length != 2)
{
message.channel.send(err_formatting)
return;
}
let options = contentSplit[1].split('.');
if(options.length != 2)
{
message.channel.send(err_formatting)
return;
}
let playerCount = parseInt( options[0] );
let teamCount = parseInt( options[1] );
if( playerCount % teamCount != 0)
{
if(teamCount % playerCount != 0)
{
message.channel.send("Error: playerCount not divisible by teamCount");
return;
}
// Wrong order. Swap them around for the people
[playerCount, teamCount] = [teamCount, playerCount];
}
// Shuffle Players
let players = [];
for(let i = 1; i <= playerCount; ++i) players.push( i );
util.shuffle(players);
/*let msg = '';
const perTeam = playerCount / teamCount;
for(let i = 0; i < teamCount; ++i)
{
msg += '**Team ' + (i+1) + '** ';
for(let j = 0; j < perTeam; ++j)
{
msg += players[i*perTeam+j] + ', ';
}
msg = msg.slice(0,-2) + '\n'; // remove trailing ', '
}*/
let msg = '';
const numbers = [ '0⃣ ', '1⃣ ', '2⃣ ', '3⃣ ', '4⃣ ', '5⃣ ', '6⃣ ', '7⃣ ', '8⃣ ', '9⃣ ', '🔟', '🇦', '🇧', '🇨', '🇩', '🇪', '🇫' ];
const perTeam = playerCount / teamCount;
for(let i = 1; i <= playerCount; ++i)
{
const pos = Math.floor((players.indexOf(i)) / perTeam) + 1;
msg += '**Player** ' + numbers[i] + ' **Team ** ';
for(let j=1; j < pos; ++j) msg += ' ';
msg += numbers[pos] + '\n';
}
message.channel.send(msg);
}
else if(content.startsWith(".draft"))
{
const contentSplit = content.split('-');
if(contentSplit.length != 2)
{
message.channel.send(err_formatting)
return;
}
let banned = contentSplit[1].split('.');
if(banned.length < 1)
{
message.channel.send(err_formatting)
return;
}
// Extract playerCount
const playerCount = parseInt( banned.shift() );
if (playerCount == 1)
{
message.channel.send("draft-1 is being re-worked... please choose a number greater than 1");
return;
}
util.createDraft(playerCount, Object.keys(util.civs), banned, (err, result) =>
{
if(err)
{
message.channel.send(err);
return;
}
//let currMsg = "Draft called for by: " + message.author + '\n';
let msg = "Draft called for by: " + message.author + '\n';
message.channel.send(msg);
for(let i = 0; i < result.length; ++i)
{
msg = " \n**Player " + (i+1) + "**\n";
result[i].forEach( j => { msg += '<' + util.civs[j]['tag'] + util.civs[j]['id'] + '> ' + j + /*', '*/ '\n'; });
message.channel.send(msg);
//let nextMsg = " \n**Player " + (i+1) + "**\n";
//result[i].forEach( j => { nextMsg += '<' + util.civs[j]['tag'] + util.civs[j]['id'] + '> ' + j + /*', '*/ '\n'; });
/*if (currMsg.length + nextMsg.length > 1980)
{
message.channel.send(currMsg);
currMsg = nextMsg;
}
else
currMsg += nextMsg;*/
}
//message.channel.send(currMsg);
});
}
});
// login with the bot
util.login_token('draft');