88 lines
3.1 KiB
JavaScript
88 lines
3.1 KiB
JavaScript
|
'use strict';
|
||
|
const { Participant } = require("./participant.js");
|
||
|
|
||
|
class Tournament {
|
||
|
/**
|
||
|
* Tournament object to track our event
|
||
|
* @param {string} title Event Title
|
||
|
* @param {number} unix_reg_end Timestamp for registration end
|
||
|
* @param {number} unix_checkin_start Timestamp for check in start
|
||
|
* @param {number} unix_checkin_end Timestamp for check in end
|
||
|
* @param {number} unix_start Timestamp for tournament start
|
||
|
* @param {string} rank_floor Player should have at least that rank to play
|
||
|
* @param {string} rank_roof Player shouldn't have higher rank, that that
|
||
|
* @param {boolean} international If everyone can join, not only CIS players
|
||
|
* @param {string} prize_pool Tells, what our players can win in this event
|
||
|
*/
|
||
|
constructor(title, unix_reg_end, unix_checkin_start, unix_checkin_end, unix_start, rank_floor, rank_roof, international, description, prize_pool){
|
||
|
this.messageID = null;
|
||
|
this.checkInMessageID = null;
|
||
|
this.channelID = null;
|
||
|
this.ts = Date.now()/1000;
|
||
|
this.title = title;
|
||
|
this.unix_reg_end = unix_reg_end;
|
||
|
this.unix_checkin_start = unix_checkin_start;
|
||
|
this.unix_checkin_end = unix_checkin_end;
|
||
|
this.unix_start = unix_start;
|
||
|
this.rank_floor = rank_floor;
|
||
|
this.rank_roof = rank_roof;
|
||
|
this.international = international;
|
||
|
this.description = description;
|
||
|
this.prize_pool = prize_pool;
|
||
|
this.participants = [];
|
||
|
this.checked_in = [];
|
||
|
this.status = 0; // 0 - registration opened; 1 - checkins opened; 2 - participants list is ready
|
||
|
this.participant_role = null;
|
||
|
this.checked_in_role = null;
|
||
|
}
|
||
|
|
||
|
static fromObject(obj){
|
||
|
return Object.assign(new Tournament(), obj);
|
||
|
}
|
||
|
|
||
|
setRoles(participant_role, checked_in_role){
|
||
|
this.participant_role = participant_role;
|
||
|
this.checked_in_role = checked_in_role;
|
||
|
}
|
||
|
|
||
|
setMessageID(messageID, channelID){
|
||
|
this.messageID = messageID;
|
||
|
this.channelID = channelID;
|
||
|
}
|
||
|
|
||
|
setCheckInMessageID(messageID){
|
||
|
this.checkInMessageID = messageID;
|
||
|
}
|
||
|
|
||
|
register(discordID, userData, tlData) {
|
||
|
if (this.participants.find((element) => element.id === userData.data._id)) return;
|
||
|
this.participants.push(new Participant(discordID, userData, tlData));
|
||
|
}
|
||
|
|
||
|
check_in(discordID) {
|
||
|
if (this.checked_in.find((element) => element.discordID === discordID)) return false;
|
||
|
const dude = this.participants.find((element) => element.discordID === discordID);
|
||
|
if (dude){
|
||
|
this.checked_in.push(dude);
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
removeParticipant(userID) {
|
||
|
if (!this.participants.find((element) => element.discordID === userID)) return;
|
||
|
let index = this.participants.findIndex((element) => element.discordID === userID);
|
||
|
this.participants.splice(index, 1);
|
||
|
}
|
||
|
|
||
|
removeChecked(userID) {
|
||
|
if (!this.checked_in.find((element) => element.discordID === userID)) return;
|
||
|
let index = this.checked_in.findIndex((element) => element.discordID === userID);
|
||
|
this.checked_in.splice(index, 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
Tournament
|
||
|
}
|