-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtournaments.js
70 lines (63 loc) · 1.39 KB
/
tournaments.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
/**
* Tournaments
* BotStuff - https://github.com/CheeseMuffin/BotStuff
*
* This file contains info about BotStuff joining Tournaments.
*
* @license MIT license
*/
'use strict';
class Tournament {
constructor(room) {
this.room = room;
this.curChallenges = null;
this.challengedBys = null;
this.started = false;
}
say(message) {
this.room.say(message);
}
handleMessage(splitMessage) {
console.log(splitMessage);
switch (splitMessage[0]) {
case 'create':
this.say("/tour join");
break;
case 'update':
let updateMes = JSON.parse(splitMessage[1]);
if (updateMes.challenges) {
this.curChallenges = updateMes.challenges;
}
if (updateMes.challengeBys) {
this.challengedBys = updateMes.challengeBys;
}
if (updateMes.challenged) {
let name = updateMes.challenged;
if (this.challengedBys && this.challengedBys.indexOf(name) !== -1) {
this.say("/tour acceptchallenge");
}
}
break;
case 'start':
if (this.curChallenges) {
this.say("/tour challenge " + this.challengedBys[0]);
}
}
}
}
class Tournaments {
constructor() {
this.tourns = {};
}
get(id) {
if (!(id in this.tourns)) return;
return this.tourns[id];
}
handleMessage(splitMessage, room) {
if (!(room in this.tourns)) {
this.tourns[room] = new Tournament(room);
}
this.tourns[room].handleMessage(splitMessage);
}
}
module.exports = new Tournaments();