language
stringclasses 6
values | original_string
stringlengths 25
887k
| text
stringlengths 25
887k
|
---|---|---|
JavaScript | async forceteamsize(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!message || ["2", "3", "4", "5", "6", "7", "8", "2v2", "3v3", "4v4", "5v5", "6v6", "7v7", "8v8"].indexOf(message.toLowerCase()) === -1) {
await Discord.queue(`Sorry, ${member}, but this command cannot be used by itself. To force a team size, use the \`!forceteamsize <size>\` command, for example, \`!forceteamsize 3\`.`, channel);
throw new Warning("Missing team size.");
}
try {
await challenge.setTeamSize(+message.charAt(0));
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async forceteamsize(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!message || ["2", "3", "4", "5", "6", "7", "8", "2v2", "3v3", "4v4", "5v5", "6v6", "7v7", "8v8"].indexOf(message.toLowerCase()) === -1) {
await Discord.queue(`Sorry, ${member}, but this command cannot be used by itself. To force a team size, use the \`!forceteamsize <size>\` command, for example, \`!forceteamsize 3\`.`, channel);
throw new Warning("Missing team size.");
}
try {
await challenge.setTeamSize(+message.charAt(0));
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async forcetype(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
const gameType = message.toUpperCase();
if (!gameType || ["TA", "CTF", "MB"].indexOf(gameType) === -1) {
await Discord.queue(`Sorry, ${member}, but this command cannot be used by itself. To force a game type, use the \`!forcetype <type>\` command, for example, \`!forcetype CTF\`.`, channel);
throw new Warning("Missing game type.");
}
try {
await challenge.setGameType(member, gameType);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async forcetype(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
const gameType = message.toUpperCase();
if (!gameType || ["TA", "CTF", "MB"].indexOf(gameType) === -1) {
await Discord.queue(`Sorry, ${member}, but this command cannot be used by itself. To force a game type, use the \`!forcetype <type>\` command, for example, \`!forcetype CTF\`.`, channel);
throw new Warning("Missing game type.");
}
try {
await challenge.setGameType(member, gameType);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async forcetime(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "To force a time, use `!forcetime` along with the date and time.", channel)) {
return false;
}
let date;
if (message.toLowerCase() === "now") {
date = new Date();
date = new Date(date.getTime() + (300000 - date.getTime() % 300000));
} else {
const tz = tc.TimeZone.zone(await member.getTimezone());
try {
date = new Date(new tc.DateTime(new Date(`${message} UTC`).toISOString(), tz).toIsoString());
} catch (_) {
try {
date = new Date(new tc.DateTime(new Date(`${new Date().toDateString()} ${message} UTC`).toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setDate(date.getDate() + 1);
}
} catch (err) {
console.log(err);
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
}
if (!date || isNaN(date.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
if (date.getFullYear() === 2001 && message.indexOf("2001") === -1) {
date = new Date(`${message} UTC`);
date.setFullYear(new Date().getFullYear());
date = new Date(new tc.DateTime(date.toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setFullYear(new Date().getFullYear() + 1);
}
}
if (date.getTime() - new Date().getTime() < -180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule a match that far into the past.`, channel);
throw new Warning("Date too far into the past.");
}
if (date.getTime() - new Date().getTime() > 180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule a match that far into the future.`, channel);
throw new Warning("Date too far into the future.");
}
}
try {
await challenge.setTime(member, date);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async forcetime(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "To force a time, use `!forcetime` along with the date and time.", channel)) {
return false;
}
let date;
if (message.toLowerCase() === "now") {
date = new Date();
date = new Date(date.getTime() + (300000 - date.getTime() % 300000));
} else {
const tz = tc.TimeZone.zone(await member.getTimezone());
try {
date = new Date(new tc.DateTime(new Date(`${message} UTC`).toISOString(), tz).toIsoString());
} catch (_) {
try {
date = new Date(new tc.DateTime(new Date(`${new Date().toDateString()} ${message} UTC`).toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setDate(date.getDate() + 1);
}
} catch (err) {
console.log(err);
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
}
if (!date || isNaN(date.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
if (date.getFullYear() === 2001 && message.indexOf("2001") === -1) {
date = new Date(`${message} UTC`);
date.setFullYear(new Date().getFullYear());
date = new Date(new tc.DateTime(date.toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setFullYear(new Date().getFullYear() + 1);
}
}
if (date.getTime() - new Date().getTime() < -180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule a match that far into the past.`, channel);
throw new Warning("Date too far into the past.");
}
if (date.getTime() - new Date().getTime() > 180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule a match that far into the future.`, channel);
throw new Warning("Date too far into the future.");
}
}
try {
await challenge.setTime(member, date);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async cleartime(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use `!cleartime` by itself to clear the match time.", channel)) {
return false;
}
try {
await challenge.clearTime(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async cleartime(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use `!cleartime` by itself to clear the match time.", channel)) {
return false;
}
try {
await challenge.clearTime(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async forcereport(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "To force a score, use `!forcereport` followed by the score of the challenging team, and then the score of the challenged team. Separate the scores with a space.", channel)) {
return false;
}
if (!scoreParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but to force report a completed match, enter the command followed by the score, using a space to separate the scores putting the challenging team first, for example \`!forcereport 49 27\`.`, channel);
throw new Warning("Invalid parameters.");
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeMapIsSet(challenge, member, channel);
await Commands.checkChallengeTeamSizeIsSet(challenge, member, channel);
await Commands.checkChallengeMatchTimeIsSet(challenge, member, channel);
const {groups: {scoreStr1, scoreStr2, gameId}} = scoreParse.exec(message),
score1 = +scoreStr1,
score2 = +scoreStr2;
if (gameId) {
await Discord.queue(`Sorry, ${member}, but to force report a completed match, enter the command followed by the score, using a space to separate the scores putting the challenging team first, for example \`!forcereport 49 27\`.`, channel);
return false;
}
try {
await challenge.setScore(score1, score2);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async forcereport(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "To force a score, use `!forcereport` followed by the score of the challenging team, and then the score of the challenged team. Separate the scores with a space.", channel)) {
return false;
}
if (!scoreParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but to force report a completed match, enter the command followed by the score, using a space to separate the scores putting the challenging team first, for example \`!forcereport 49 27\`.`, channel);
throw new Warning("Invalid parameters.");
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeMapIsSet(challenge, member, channel);
await Commands.checkChallengeTeamSizeIsSet(challenge, member, channel);
await Commands.checkChallengeMatchTimeIsSet(challenge, member, channel);
const {groups: {scoreStr1, scoreStr2, gameId}} = scoreParse.exec(message),
score1 = +scoreStr1,
score2 = +scoreStr2;
if (gameId) {
await Discord.queue(`Sorry, ${member}, but to force report a completed match, enter the command followed by the score, using a space to separate the scores putting the challenging team first, for example \`!forcereport 49 27\`.`, channel);
return false;
}
try {
await challenge.setScore(score1, score2);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async adjudicate(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!adjudicate` command followed by how you wish to adjudicate this match, either `cancel`, `extend`, or `penalize`. If you penalize a team, include the name of the team.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsNotConfirmed(challenge, member, channel);
if (!adjudicateParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!adjudicate\` command followed by how you wish to adjudicate this match, either \`cancel\`, \`extend\`, or \`penalize\`. If you penalize a team, include the name of the team.`, channel);
throw new Warning("Invalid parameters.");
}
await Commands.checkChallengeDetails(challenge, member, channel);
if (!challenge.details.matchTime && !challenge.details.dateClockDeadline) {
await Discord.queue(`Sorry, ${member}, but you cannot adjudicate an unscheduled match that's not on the clock.`, channel);
throw new Warning("Match unscheduled and not on the clock.");
}
if (challenge.details.matchTime && challenge.details.matchTime > new Date()) {
await Discord.queue(`Sorry, ${member}, but you cannot adjudicate a scheduled match when the scheduled time hasn't passed yet.`, channel);
throw new Warning("Match time not passed yet.");
}
if (challenge.details.dateClockDeadline && challenge.details.dateClockDeadline > new Date()) {
await Discord.queue(`Sorry, ${member}, but you cannot adjudicate a match that's on the clock when the deadline hasn't passed yet. The current clock deadline is ${challenge.details.dateClockDeadline.toLocaleString("en-US", {timeZone: await member.getTimezone(), month: "numeric", day: "numeric", year: "numeric", hour12: true, hour: "numeric", minute: "2-digit", timeZoneName: "short"})}.`, channel);
throw new Warning("Match clock deadline not passed yet.");
}
const {groups: {decision, teamTag}} = adjudicateParse.exec(message);
let teams;
if (decision === "penalize") {
if (teamTag === "both") {
teams = [challenge.challengingTeam, challenge.challengedTeam];
} else if (teamTag) {
const team = await Commands.checkTeamExists(teamTag, member, channel);
await Commands.checkTeamIsInChallenge(challenge, team, member, channel);
teams = [team];
} else {
await Discord.queue(`Sorry, ${member}, but you must specify a team to penalize.`, channel);
throw new Warning("Team to penalize not included.");
}
}
try {
await challenge.adjudicate(member, decision, teams);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async adjudicate(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!adjudicate` command followed by how you wish to adjudicate this match, either `cancel`, `extend`, or `penalize`. If you penalize a team, include the name of the team.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsNotConfirmed(challenge, member, channel);
if (!adjudicateParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!adjudicate\` command followed by how you wish to adjudicate this match, either \`cancel\`, \`extend\`, or \`penalize\`. If you penalize a team, include the name of the team.`, channel);
throw new Warning("Invalid parameters.");
}
await Commands.checkChallengeDetails(challenge, member, channel);
if (!challenge.details.matchTime && !challenge.details.dateClockDeadline) {
await Discord.queue(`Sorry, ${member}, but you cannot adjudicate an unscheduled match that's not on the clock.`, channel);
throw new Warning("Match unscheduled and not on the clock.");
}
if (challenge.details.matchTime && challenge.details.matchTime > new Date()) {
await Discord.queue(`Sorry, ${member}, but you cannot adjudicate a scheduled match when the scheduled time hasn't passed yet.`, channel);
throw new Warning("Match time not passed yet.");
}
if (challenge.details.dateClockDeadline && challenge.details.dateClockDeadline > new Date()) {
await Discord.queue(`Sorry, ${member}, but you cannot adjudicate a match that's on the clock when the deadline hasn't passed yet. The current clock deadline is ${challenge.details.dateClockDeadline.toLocaleString("en-US", {timeZone: await member.getTimezone(), month: "numeric", day: "numeric", year: "numeric", hour12: true, hour: "numeric", minute: "2-digit", timeZoneName: "short"})}.`, channel);
throw new Warning("Match clock deadline not passed yet.");
}
const {groups: {decision, teamTag}} = adjudicateParse.exec(message);
let teams;
if (decision === "penalize") {
if (teamTag === "both") {
teams = [challenge.challengingTeam, challenge.challengedTeam];
} else if (teamTag) {
const team = await Commands.checkTeamExists(teamTag, member, channel);
await Commands.checkTeamIsInChallenge(challenge, team, member, channel);
teams = [team];
} else {
await Discord.queue(`Sorry, ${member}, but you must specify a team to penalize.`, channel);
throw new Warning("Team to penalize not included.");
}
}
try {
await challenge.adjudicate(member, decision, teams);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async overtime(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!overtime` command followed by the number of overtime periods played in this match.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
if (!numberOrZeroParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use \`!overtime\` followed by the number of overtime periods played in this match.`, channel);
return false;
}
const overtimePeriods = +message;
try {
await challenge.setOvertimePeriods(overtimePeriods);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`The number of overtime periods for this match has been set to ${overtimePeriods}.`, channel);
return true;
} | async overtime(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!overtime` command followed by the number of overtime periods played in this match.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
if (!numberOrZeroParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use \`!overtime\` followed by the number of overtime periods played in this match.`, channel);
return false;
}
const overtimePeriods = +message;
try {
await challenge.setOvertimePeriods(overtimePeriods);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`The number of overtime periods for this match has been set to ${overtimePeriods}.`, channel);
return true;
} |
JavaScript | async addstat(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!addstat` command followed by the pilot you are recording the stat for, along with the team tag, kills, assists, and deaths.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
switch (challenge.details.gameType) {
case "TA": {
if (!statTAParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!addstat\` command followed by the pilot you are recording the stat for, along with the team tag, kills, assists, and deaths.`, channel);
throw new Warning("Invalid parameters.");
}
const {groups: {pilotName, teamName, kills, assists, deaths}} = statTAParse.exec(message),
pilot = await Commands.checkUserExists(pilotName, member, channel),
team = await Commands.checkTeamExists(teamName, member, channel);
await Commands.checkTeamIsInChallenge(challenge, team, member, channel);
await Commands.checkChallengeTeamStats(challenge, pilot, team, member, channel);
try {
await challenge.addStatTA(team, pilot, +kills, +assists, +deaths);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
break;
}
case "CTF": {
if (!statCTFParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!addstat\` command followed by the pilot you are recording the stat for, along with the team tag, flag captures, flag pickups, flag carrier kills, flag returns, kills, assists, and deaths.`, channel);
throw new Warning("Invalid parameters.");
}
const {groups: {pilotName, teamName, captures, pickups, carrierKills, returns, kills, assists, deaths}} = statCTFParse.exec(message),
pilot = await Commands.checkUserExists(pilotName, member, channel),
team = await Commands.checkTeamExists(teamName, member, channel);
await Commands.checkTeamIsInChallenge(challenge, team, member, channel);
await Commands.checkChallengeTeamStats(challenge, pilot, team, member, channel);
try {
await challenge.addStatCTF(team, pilot, +captures, +pickups, +carrierKills, +returns, +kills, +assists, +deaths);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
break;
}
}
return true;
} | async addstat(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!addstat` command followed by the pilot you are recording the stat for, along with the team tag, kills, assists, and deaths.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
switch (challenge.details.gameType) {
case "TA": {
if (!statTAParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!addstat\` command followed by the pilot you are recording the stat for, along with the team tag, kills, assists, and deaths.`, channel);
throw new Warning("Invalid parameters.");
}
const {groups: {pilotName, teamName, kills, assists, deaths}} = statTAParse.exec(message),
pilot = await Commands.checkUserExists(pilotName, member, channel),
team = await Commands.checkTeamExists(teamName, member, channel);
await Commands.checkTeamIsInChallenge(challenge, team, member, channel);
await Commands.checkChallengeTeamStats(challenge, pilot, team, member, channel);
try {
await challenge.addStatTA(team, pilot, +kills, +assists, +deaths);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
break;
}
case "CTF": {
if (!statCTFParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!addstat\` command followed by the pilot you are recording the stat for, along with the team tag, flag captures, flag pickups, flag carrier kills, flag returns, kills, assists, and deaths.`, channel);
throw new Warning("Invalid parameters.");
}
const {groups: {pilotName, teamName, captures, pickups, carrierKills, returns, kills, assists, deaths}} = statCTFParse.exec(message),
pilot = await Commands.checkUserExists(pilotName, member, channel),
team = await Commands.checkTeamExists(teamName, member, channel);
await Commands.checkTeamIsInChallenge(challenge, team, member, channel);
await Commands.checkChallengeTeamStats(challenge, pilot, team, member, channel);
try {
await challenge.addStatCTF(team, pilot, +captures, +pickups, +carrierKills, +returns, +kills, +assists, +deaths);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
break;
}
}
return true;
} |
JavaScript | async clearstats(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!clearstats` command by itself to clear all of the stats from a challenge.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
try {
await challenge.clearStats(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async clearstats(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!clearstats` command by itself to clear all of the stats from a challenge.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
try {
await challenge.clearStats(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async removestat(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!removestat` command followed by the pilot whose stat you are removing.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
const pilot = await Commands.checkUserExists(message, member, channel),
stats = {};
try {
stats.challengingTeamStats = await challenge.getStatsForTeam(challenge.challengingTeam);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
try {
stats.challengedTeamStats = await challenge.getStatsForTeam(challenge.challengedTeam);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
if (!stats.challengingTeamStats.find((s) => s.pilot.id === pilot.id) && !stats.challengedTeamStats.find((s) => s.pilot.id === pilot.id)) {
await Discord.queue(`Sorry, ${member}, but ${pilot} does not have a recorded stat for this match.`, channel);
throw new Warning("No stat for pilot.");
}
try {
await challenge.removeStat(pilot);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async removestat(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!removestat` command followed by the pilot whose stat you are removing.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
const pilot = await Commands.checkUserExists(message, member, channel),
stats = {};
try {
stats.challengingTeamStats = await challenge.getStatsForTeam(challenge.challengingTeam);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
try {
stats.challengedTeamStats = await challenge.getStatsForTeam(challenge.challengedTeam);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
if (!stats.challengingTeamStats.find((s) => s.pilot.id === pilot.id) && !stats.challengedTeamStats.find((s) => s.pilot.id === pilot.id)) {
await Discord.queue(`Sorry, ${member}, but ${pilot} does not have a recorded stat for this match.`, channel);
throw new Warning("No stat for pilot.");
}
try {
await challenge.removeStat(pilot);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async voidgame(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
let challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (challenge) {
if (!await Commands.checkNoParameters(message, member, "Use the `!voidgame` command by itself in a challenge channel to void the match.", channel)) {
return false;
}
try {
await challenge.void(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
} else {
if (!await Commands.checkHasParameters(message, member, "Use the `!voidgame` command with the team tags of the two teams for which you wish to look up a match to void.", channel)) {
return false;
}
if (twoTeamTagParse.test(message)) {
const {groups: {teamTag1, teamTag2}} = twoTeamTagParse.exec(message),
team1 = await Commands.checkTeamExists(teamTag1, member, channel),
team2 = await Commands.checkTeamExists(teamTag2, member, channel),
challenges = await Challenge.getAllByTeams(team1, team2),
results = [];
if (challenges.length === 0) {
await Discord.queue(`Sorry, ${member}, but no games have been scheduled between **${team1.name}** and **${team2.name}**.`, channel);
throw new Warning("No games played between specified teams.");
}
for (challenge of challenges) {
await Commands.checkChallengeDetails(challenge, member, channel);
if (challenge.details.dateConfirmed) {
results.push(`${challenge.id}) ${challenge.challengingTeam.tag} ${challenge.details.challengingTeamScore}, ${challenge.challengedTeam.tag} ${challenge.details.challengedTeamScore}, ${challenge.details.map}, ${challenge.details.matchTime.toLocaleString("en-US", {timeZone: await member.getTimezone(), month: "numeric", day: "numeric", year: "numeric", hour12: true, hour: "numeric", minute: "2-digit", timeZoneName: "short"})}`);
} else {
results.push(`${challenge.id}) ${challenge.challengingTeam.tag} vs ${challenge.challengedTeam.tag}, ${challenge.details.map || "Map not set"}, ${challenge.details.matchTime ? challenge.details.matchTime.toLocaleString("en-US", {timeZone: await member.getTimezone(), month: "numeric", day: "numeric", year: "numeric", hour12: true, hour: "numeric", minute: "2-digit", timeZoneName: "short"}) : "Time not set"}`);
}
}
await Discord.queue(`Use \`!voidgame\` along with the challenge ID from the list below to void a specific game.\n${results.join("\n")}`, member);
} else if (numberParse.test(message)) {
challenge = await Commands.checkChallengeIdExists(+message, member, channel);
try {
await challenge.void(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`${member}, the specified challenge has been voided.`, channel);
} else {
await Discord.queue(`Sorry, ${member}, but you must use the \`!voidgame\` command with the team tags of the two teams for which you wish to look up a match to void.`, channel);
throw new Warning("Invalid parameters.");
}
}
return true;
} | async voidgame(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
let challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (challenge) {
if (!await Commands.checkNoParameters(message, member, "Use the `!voidgame` command by itself in a challenge channel to void the match.", channel)) {
return false;
}
try {
await challenge.void(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
} else {
if (!await Commands.checkHasParameters(message, member, "Use the `!voidgame` command with the team tags of the two teams for which you wish to look up a match to void.", channel)) {
return false;
}
if (twoTeamTagParse.test(message)) {
const {groups: {teamTag1, teamTag2}} = twoTeamTagParse.exec(message),
team1 = await Commands.checkTeamExists(teamTag1, member, channel),
team2 = await Commands.checkTeamExists(teamTag2, member, channel),
challenges = await Challenge.getAllByTeams(team1, team2),
results = [];
if (challenges.length === 0) {
await Discord.queue(`Sorry, ${member}, but no games have been scheduled between **${team1.name}** and **${team2.name}**.`, channel);
throw new Warning("No games played between specified teams.");
}
for (challenge of challenges) {
await Commands.checkChallengeDetails(challenge, member, channel);
if (challenge.details.dateConfirmed) {
results.push(`${challenge.id}) ${challenge.challengingTeam.tag} ${challenge.details.challengingTeamScore}, ${challenge.challengedTeam.tag} ${challenge.details.challengedTeamScore}, ${challenge.details.map}, ${challenge.details.matchTime.toLocaleString("en-US", {timeZone: await member.getTimezone(), month: "numeric", day: "numeric", year: "numeric", hour12: true, hour: "numeric", minute: "2-digit", timeZoneName: "short"})}`);
} else {
results.push(`${challenge.id}) ${challenge.challengingTeam.tag} vs ${challenge.challengedTeam.tag}, ${challenge.details.map || "Map not set"}, ${challenge.details.matchTime ? challenge.details.matchTime.toLocaleString("en-US", {timeZone: await member.getTimezone(), month: "numeric", day: "numeric", year: "numeric", hour12: true, hour: "numeric", minute: "2-digit", timeZoneName: "short"}) : "Time not set"}`);
}
}
await Discord.queue(`Use \`!voidgame\` along with the challenge ID from the list below to void a specific game.\n${results.join("\n")}`, member);
} else if (numberParse.test(message)) {
challenge = await Commands.checkChallengeIdExists(+message, member, channel);
try {
await challenge.void(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`${member}, the specified challenge has been voided.`, channel);
} else {
await Discord.queue(`Sorry, ${member}, but you must use the \`!voidgame\` command with the team tags of the two teams for which you wish to look up a match to void.`, channel);
throw new Warning("Invalid parameters.");
}
}
return true;
} |
JavaScript | async unvoidgame(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!unvoidgame` command with the challenge ID of the challenge you wish to unvoid.", channel)) {
return false;
}
if (!numberParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!unvoidgame\` command with the challenge ID of the challenge you wish to unvoid.`, channel);
throw new Warning("Invalid parameters.");
}
const challenge = await Commands.checkChallengeIdExists(+message, member, channel);
await Commands.checkChallengeDetails(challenge, member, channel);
if (!challenge.details.dateConfirmed && !challenge.channel) {
await Discord.queue(`Sorry, ${member}, but this incomplete challenge no longer exists. Have the teams simply challenge each other again.`, channel);
throw new Warning("Challenge channel deleted already.");
}
try {
await challenge.unvoid(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`${member}, the specified challenge has been unvoided.`, channel);
return true;
} | async unvoidgame(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "Use the `!unvoidgame` command with the challenge ID of the challenge you wish to unvoid.", channel)) {
return false;
}
if (!numberParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but you must use the \`!unvoidgame\` command with the challenge ID of the challenge you wish to unvoid.`, channel);
throw new Warning("Invalid parameters.");
}
const challenge = await Commands.checkChallengeIdExists(+message, member, channel);
await Commands.checkChallengeDetails(challenge, member, channel);
if (!challenge.details.dateConfirmed && !challenge.channel) {
await Discord.queue(`Sorry, ${member}, but this incomplete challenge no longer exists. Have the teams simply challenge each other again.`, channel);
throw new Warning("Challenge channel deleted already.");
}
try {
await challenge.unvoid(member);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`${member}, the specified challenge has been unvoided.`, channel);
return true;
} |
JavaScript | async closegame(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!closegame` command by itself to close a channel where the match has been completed or voided.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
/** @type {ChallengeTypes.GamePlayerStatsByTeam} */
let stats;
if (!challenge.details.dateVoided) {
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
stats = await Commands.checkChallengeStatsComplete(challenge, member, channel);
}
try {
await challenge.close(member, stats);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async closegame(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!closegame` command by itself to close a channel where the match has been completed or voided.", channel)) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
/** @type {ChallengeTypes.GamePlayerStatsByTeam} */
let stats;
if (!challenge.details.dateVoided) {
await Commands.checkChallengeIsConfirmed(challenge, member, channel);
stats = await Commands.checkChallengeStatsComplete(challenge, member, channel);
}
try {
await challenge.close(member, stats);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async swapcolors(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!swapcolors` command by itself to swap the colors of the two teams that played.", channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
try {
await challenge.swapColors();
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`${member} has swapped the colors for this match. **${challenge.details.blueTeam.tag}** is now blue/team 1, and **${challenge.details.orangeTeam.tag}** is now orange/team 2.`, challenge.channel);
return true;
} | async swapcolors(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!swapcolors` command by itself to swap the colors of the two teams that played.", channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkChallengeDetails(challenge, member, channel);
await Commands.checkChallengeIsNotVoided(challenge, member, channel);
try {
await challenge.swapColors();
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
await Discord.queue(`${member} has swapped the colors for this match. **${challenge.details.blueTeam.tag}** is now blue/team 1, and **${challenge.details.orangeTeam.tag}** is now orange/team 2.`, challenge.channel);
return true;
} |
JavaScript | async title(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
try {
await challenge.title(message);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async title(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
try {
await challenge.title(message);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async postseason(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!postseason` command by itself to set this challenge as a postseason match.", channel)) {
return false;
}
try {
await challenge.setPostseason();
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
return true;
} | async postseason(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!postseason` command by itself to set this challenge as a postseason match.", channel)) {
return false;
}
try {
await challenge.setPostseason();
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
return true;
} |
JavaScript | async regularseason(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!regularseason` command by itself to set this challenge as a regular season match.", channel)) {
return false;
}
try {
await challenge.setRegularSeason();
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
return true;
} | async regularseason(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkNoParameters(message, member, "Use the `!regularseason` command by itself to set this challenge as a regular season match.", channel)) {
return false;
}
try {
await challenge.setRegularSeason();
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
return true;
} |
JavaScript | async addevent(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!eventParse.test(message)) {
return false;
}
const {groups: {title, dateStartStr, dateEndStr}} = eventParse.exec(message),
tz = tc.TimeZone.zone(await member.getTimezone());
let dateStart;
try {
dateStart = new Date(new tc.DateTime(new Date(`${dateStartStr} UTC`).toISOString(), tz).toIsoString());
} catch (err) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the start date and time.`, channel);
throw new Warning("Invalid start date.");
}
if (!dateStart || isNaN(dateStart.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the start date and time.`, channel);
throw new Warning("Invalid start date.");
}
let dateEnd;
try {
dateEnd = new Date(new tc.DateTime(new Date(`${dateEndStr} UTC`).toISOString(), tz).toIsoString());
} catch (err) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the end date and time.`, channel);
throw new Warning("Invalid end date.");
}
if (!dateEnd || isNaN(dateEnd.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the end date and time.`, channel);
throw new Warning("Invalid end date.");
}
if (dateStart.getTime() - new Date().getTime() < -180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the past.`, channel);
throw new Warning("Date too far into the past.");
}
if (dateEnd.getTime() - new Date().getTime() < -180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the past.`, channel);
throw new Warning("Date too far into the past.");
}
if (dateStart.getTime() - new Date().getTime() > 180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the future.`, channel);
throw new Warning("Date too far into the future.");
}
if (dateEnd.getTime() - new Date().getTime() > 180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the future.`, channel);
throw new Warning("Date too far into the future.");
}
try {
await Event.create(title, dateStart, dateEnd);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the event **${title}** has been added. Use the \`!next\` command to see upcoming events.`, channel);
return true;
} | async addevent(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!eventParse.test(message)) {
return false;
}
const {groups: {title, dateStartStr, dateEndStr}} = eventParse.exec(message),
tz = tc.TimeZone.zone(await member.getTimezone());
let dateStart;
try {
dateStart = new Date(new tc.DateTime(new Date(`${dateStartStr} UTC`).toISOString(), tz).toIsoString());
} catch (err) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the start date and time.`, channel);
throw new Warning("Invalid start date.");
}
if (!dateStart || isNaN(dateStart.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the start date and time.`, channel);
throw new Warning("Invalid start date.");
}
let dateEnd;
try {
dateEnd = new Date(new tc.DateTime(new Date(`${dateEndStr} UTC`).toISOString(), tz).toIsoString());
} catch (err) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the end date and time.`, channel);
throw new Warning("Invalid end date.");
}
if (!dateEnd || isNaN(dateEnd.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse the end date and time.`, channel);
throw new Warning("Invalid end date.");
}
if (dateStart.getTime() - new Date().getTime() < -180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the past.`, channel);
throw new Warning("Date too far into the past.");
}
if (dateEnd.getTime() - new Date().getTime() < -180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the past.`, channel);
throw new Warning("Date too far into the past.");
}
if (dateStart.getTime() - new Date().getTime() > 180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the future.`, channel);
throw new Warning("Date too far into the future.");
}
if (dateEnd.getTime() - new Date().getTime() > 180 * 24 * 60 * 60 * 1000) {
await Discord.queue(`Sorry, ${member}, but you cannot schedule an event that far into the future.`, channel);
throw new Warning("Date too far into the future.");
}
try {
await Event.create(title, dateStart, dateEnd);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the event **${title}** has been added. Use the \`!next\` command to see upcoming events.`, channel);
return true;
} |
JavaScript | async removeevent(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
try {
await Event.remove(message);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the event **${message}** has been removed. Use the \`!next\` command to see upcoming events.`, channel);
return true;
} | async removeevent(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
try {
await Event.remove(message);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the event **${message}** has been removed. Use the \`!next\` command to see upcoming events.`, channel);
return true;
} |
JavaScript | async lockteam(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the team you wish to lock the roster for with this command.", channel)) {
return false;
}
const team = await Commands.checkTeamExists(message, member, channel);
try {
await team.setLock(true);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the roster for **${team.name}** has been locked.`, channel);
return true;
} | async lockteam(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the team you wish to lock the roster for with this command.", channel)) {
return false;
}
const team = await Commands.checkTeamExists(message, member, channel);
try {
await team.setLock(true);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the roster for **${team.name}** has been locked.`, channel);
return true;
} |
JavaScript | async unlockteam(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the team you wish to unlock the roster for with this command.", channel)) {
return false;
}
const team = await Commands.checkTeamExists(message, member, channel);
try {
await team.setLock(false);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the roster for **${team.name}** has been unlocked.`, channel);
return true;
} | async unlockteam(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the team you wish to unlock the roster for with this command.", channel)) {
return false;
}
const team = await Commands.checkTeamExists(message, member, channel);
try {
await team.setLock(false);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the roster for **${team.name}** has been unlocked.`, channel);
return true;
} |
JavaScript | async addmap(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the map you wish to add with this command.", channel)) {
return false;
}
if (!addMapParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but in order to add a map, you must first specify the game type followed by the name of the map, for example \`!addmap TA Vault\`.`, channel);
throw new Warning("Invalid syntax.");
}
const {groups: {gameType, map}} = addMapParse.exec(message);
let mapData;
try {
mapData = await Map.validate(map, "TA");
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
if (mapData) {
await Discord.queue(`Sorry, ${member}, but ${mapData.map} is already allowed.`, channel);
throw new Warning("Map already allowed.");
}
try {
await Map.create(map, gameType);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the map **${map}** is now available for ${gameType} play.`, channel);
return true;
} | async addmap(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the map you wish to add with this command.", channel)) {
return false;
}
if (!addMapParse.test(message)) {
await Discord.queue(`Sorry, ${member}, but in order to add a map, you must first specify the game type followed by the name of the map, for example \`!addmap TA Vault\`.`, channel);
throw new Warning("Invalid syntax.");
}
const {groups: {gameType, map}} = addMapParse.exec(message);
let mapData;
try {
mapData = await Map.validate(map, "TA");
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
if (mapData) {
await Discord.queue(`Sorry, ${member}, but ${mapData.map} is already allowed.`, channel);
throw new Warning("Map already allowed.");
}
try {
await Map.create(map, gameType);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the map **${map}** is now available for ${gameType} play.`, channel);
return true;
} |
JavaScript | async removemap(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the map you wish to remove with this command.", channel)) {
return false;
}
let map;
try {
map = await Map.validate(message, "TA");
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
if (!map) {
await Discord.queue(`Sorry, ${member}, but ${message} is not currently allowed.`, channel);
throw new Warning("Map not currently allowed.");
}
if (map.stock) {
await Discord.queue(`Sorry, ${member}, but you can't remove a stock map.`, channel);
throw new Warning("Map is a stock map.");
}
try {
await Map.remove(map.map);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the map **${message}** is no longer available for play.`, channel);
return true;
} | async removemap(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
if (!await Commands.checkHasParameters(message, member, "You must specify the map you wish to remove with this command.", channel)) {
return false;
}
let map;
try {
map = await Map.validate(message, "TA");
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
if (!map) {
await Discord.queue(`Sorry, ${member}, but ${message} is not currently allowed.`, channel);
throw new Warning("Map not currently allowed.");
}
if (map.stock) {
await Discord.queue(`Sorry, ${member}, but you can't remove a stock map.`, channel);
throw new Warning("Map is a stock map.");
}
try {
await Map.remove(map.map);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error.`, channel);
throw err;
}
await Discord.queue(`${member}, the map **${message}** is no longer available for play.`, channel);
return true;
} |
JavaScript | async testing(member, channel, message) {
if (!await Commands.checkNoParameters(message, member, `Use \`!testing\` by itself to add yourself to the ${Discord.testersRole} role.`, channel)) {
return false;
}
if (member.roles.cache.find((r) => r.id === Discord.testersRole.id)) {
await Discord.queue(`Sorry, ${member}, but you are already a tester. Use \`!stoptesting\` to remove yourself from the testers role.`, channel);
throw new Warning("User is already a tester.");
}
await member.roles.add(Discord.testersRole);
await Discord.queue(`${member}, you have been added to the ${Discord.testersRole} role. Use \`!stoptesting\` to remove yourself from the ${Discord.testersRole} role.`, channel);
return true;
} | async testing(member, channel, message) {
if (!await Commands.checkNoParameters(message, member, `Use \`!testing\` by itself to add yourself to the ${Discord.testersRole} role.`, channel)) {
return false;
}
if (member.roles.cache.find((r) => r.id === Discord.testersRole.id)) {
await Discord.queue(`Sorry, ${member}, but you are already a tester. Use \`!stoptesting\` to remove yourself from the testers role.`, channel);
throw new Warning("User is already a tester.");
}
await member.roles.add(Discord.testersRole);
await Discord.queue(`${member}, you have been added to the ${Discord.testersRole} role. Use \`!stoptesting\` to remove yourself from the ${Discord.testersRole} role.`, channel);
return true;
} |
JavaScript | async stoptesting(member, channel, message) {
if (!await Commands.checkNoParameters(message, member, `Use \`!stoptesting\` by itself to remove yourself from the ${Discord.testersRole} role.`, channel)) {
return false;
}
if (!member.roles.cache.find((r) => r.id === Discord.testersRole.id)) {
await Discord.queue(`Sorry, ${member}, but you are not currently a tester. Use \`!testing\` to add yourself to the ${Discord.testersRole} role.`, channel);
throw new Warning("User is already a tester.");
}
await member.roles.remove(Discord.testersRole);
await Discord.queue(`${member}, you have been remove from the ${Discord.testersRole} role. Use \`!testing\` to add yourself back to this role.`, channel);
return true;
} | async stoptesting(member, channel, message) {
if (!await Commands.checkNoParameters(message, member, `Use \`!stoptesting\` by itself to remove yourself from the ${Discord.testersRole} role.`, channel)) {
return false;
}
if (!member.roles.cache.find((r) => r.id === Discord.testersRole.id)) {
await Discord.queue(`Sorry, ${member}, but you are not currently a tester. Use \`!testing\` to add yourself to the ${Discord.testersRole} role.`, channel);
throw new Warning("User is already a tester.");
}
await member.roles.remove(Discord.testersRole);
await Discord.queue(`${member}, you have been remove from the ${Discord.testersRole} role. Use \`!testing\` to add yourself back to this role.`, channel);
return true;
} |
JavaScript | async convert(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
if (!await Commands.checkHasParameters(message, member, "To convert a time, use `!convert` along with the date and time. If not set, time zone defaults to your team's selected time zone, or Pacific Time. Use the `!timezone` command to set your own time zone. Founders may use the `!teamtimezone` command to set the default time zone for their team.", channel)) {
return false;
}
message = message.replace(/-/g, "/");
let date;
if (message.toLowerCase() === "now") {
date = new Date();
date = new Date(date.getTime() + (300000 - date.getTime() % 300000));
} else {
const tz = tc.TimeZone.zone(await member.getTimezone());
try {
date = new Date(new tc.DateTime(new Date(`${message} UTC`).toISOString(), tz).toIsoString());
} catch (_) {
try {
date = new Date(new tc.DateTime(new Date(`${new Date().toDateString()} ${message} UTC`).toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setDate(date.getDate() + 1);
}
} catch (err) {
console.log(err);
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
}
if (!date || isNaN(date.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
if (date.getFullYear() === 2001 && message.indexOf("2001") === -1) {
date = new Date(`${message} UTC`);
date.setFullYear(new Date().getFullYear());
date = new Date(new tc.DateTime(date.toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setFullYear(new Date().getFullYear() + 1);
}
}
if (!date || isNaN(date.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
}
try {
const times = {};
for (const channelMember of channel.members.values()) {
const timezone = await channelMember.getTimezone(),
yearWithTimezone = date.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = date.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
for (const challengeTeam of [challenge.challengingTeam, challenge.challengedTeam]) {
const timezone = await challengeTeam.getTimezone(),
yearWithTimezone = date.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = date.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
const sortedTimes = Object.keys(times).map((tz) => ({timezone: tz, displayTime: times[tz], value: new Date(times[tz])})).sort((a, b) => {
if (a.value.getTime() !== b.value.getTime()) {
return b.value.getTime() - a.value.getTime();
}
return a.timezone.localeCompare(b.timezone);
});
await Discord.richQueue(Discord.messageEmbed({
description: "**Converted Times**",
fields: sortedTimes.map((t) => ({name: t.timezone, value: t.displayTime}))
}), channel);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} | async convert(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
if (!await Commands.checkHasParameters(message, member, "To convert a time, use `!convert` along with the date and time. If not set, time zone defaults to your team's selected time zone, or Pacific Time. Use the `!timezone` command to set your own time zone. Founders may use the `!teamtimezone` command to set the default time zone for their team.", channel)) {
return false;
}
message = message.replace(/-/g, "/");
let date;
if (message.toLowerCase() === "now") {
date = new Date();
date = new Date(date.getTime() + (300000 - date.getTime() % 300000));
} else {
const tz = tc.TimeZone.zone(await member.getTimezone());
try {
date = new Date(new tc.DateTime(new Date(`${message} UTC`).toISOString(), tz).toIsoString());
} catch (_) {
try {
date = new Date(new tc.DateTime(new Date(`${new Date().toDateString()} ${message} UTC`).toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setDate(date.getDate() + 1);
}
} catch (err) {
console.log(err);
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
}
if (!date || isNaN(date.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
if (date.getFullYear() === 2001 && message.indexOf("2001") === -1) {
date = new Date(`${message} UTC`);
date.setFullYear(new Date().getFullYear());
date = new Date(new tc.DateTime(date.toISOString(), tz).toIsoString());
if (date < new Date()) {
date.setFullYear(new Date().getFullYear() + 1);
}
}
if (!date || isNaN(date.valueOf())) {
await Discord.queue(`Sorry, ${member}, but I couldn't parse that date and time.`, channel);
throw new Warning("Invalid date.");
}
}
try {
const times = {};
for (const channelMember of channel.members.values()) {
const timezone = await channelMember.getTimezone(),
yearWithTimezone = date.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = date.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
for (const challengeTeam of [challenge.challengingTeam, challenge.challengedTeam]) {
const timezone = await challengeTeam.getTimezone(),
yearWithTimezone = date.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = date.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
const sortedTimes = Object.keys(times).map((tz) => ({timezone: tz, displayTime: times[tz], value: new Date(times[tz])})).sort((a, b) => {
if (a.value.getTime() !== b.value.getTime()) {
return b.value.getTime() - a.value.getTime();
}
return a.timezone.localeCompare(b.timezone);
});
await Discord.richQueue(Discord.messageEmbed({
description: "**Converted Times**",
fields: sortedTimes.map((t) => ({name: t.timezone, value: t.displayTime}))
}), channel);
} catch (err) {
await Discord.queue(`Sorry, ${member}, but there was a server error. An admin will be notified about this.`, channel);
throw err;
}
return true;
} |
JavaScript | async regen(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
if (!await Commands.checkNoParameters(message, member, "Use `!regen` by itself to regenerate the channel's pinned post.", channel)) {
return false;
}
await challenge.updatePinnedPost();
await Discord.queue("This challenge's pinned post has been updated.", channel);
return true;
} | async regen(member, channel, message) {
if (!Commands.checkChannelIsOnServer(channel)) {
return false;
}
await Commands.checkMemberIsOwner(member);
const challenge = await Commands.checkChannelIsChallengeRoom(channel, member);
if (!challenge) {
return false;
}
if (!await Commands.checkNoParameters(message, member, "Use `!regen` by itself to regenerate the channel's pinned post.", channel)) {
return false;
}
await challenge.updatePinnedPost();
await Discord.queue("This challenge's pinned post has been updated.", channel);
return true;
} |
JavaScript | static async login() {
/** @type {IoRedis.Redis} */
let client;
try {
const newClient = new IoRedis(settings);
client = newClient;
} catch (err) {
Log.exception("A Redis error occurred while logging in.", err);
client.removeAllListeners();
if (client) {
await client.quit();
}
client = void 0;
return void 0;
}
client.on("error", async (err) => {
Log.exception("A Redis error occurred.", err);
client.removeAllListeners();
if (client) {
await client.quit();
}
client = void 0;
});
return client;
} | static async login() {
/** @type {IoRedis.Redis} */
let client;
try {
const newClient = new IoRedis(settings);
client = newClient;
} catch (err) {
Log.exception("A Redis error occurred while logging in.", err);
client.removeAllListeners();
if (client) {
await client.quit();
}
client = void 0;
return void 0;
}
client.on("error", async (err) => {
Log.exception("A Redis error occurred.", err);
client.removeAllListeners();
if (client) {
await client.quit();
}
client = void 0;
});
return client;
} |
JavaScript | static async addStatCTF(challenge, team, pilot, captures, pickups, carrierKills, returns, kills, assists, deaths) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
MERGE tblStat s
USING (VALUES (@challengeId, @teamId, @captures, @pickups, @carrierKills, @returns, @kills, @assists, @deaths, @playerId)) AS v (ChallengeId, TeamId, Captures, Pickups, CarrierKills, Returns, Kills, Assists, Deaths, PlayerId)
ON s.ChallengeId = v.ChallengeId AND s.TeamId = v.TeamId AND s.PlayerId = v.PlayerId
WHEN MATCHED THEN
UPDATE SET
TeamId = v.TeamId,
Captures = v.Captures,
Pickups = v.Pickups,
CarrierKills = v.CarrierKills,
Returns = v.Returns,
Kills = v.Kills,
Assists = v.Assists,
Deaths = v.Deaths
WHEN NOT MATCHED THEN
INSERT (ChallengeId, TeamId, PlayerId, Captures, Pickups, CarrierKills, Returns, Kills, Assists, Deaths) VALUES (v.ChallengeId, v.TeamId, v.PlayerId, v.Captures, v.Pickups, v.CarrierKills, v.Returns, v.Kills, v.Assists, v.Deaths);
`, {
discordId: {type: Db.VARCHAR(24), value: pilot.id},
challengeId: {type: Db.INT, value: challenge.id},
teamId: {type: Db.INT, value: team.id},
captures: {type: Db.INT, value: captures},
pickups: {type: Db.INT, value: pickups},
carrierKills: {type: Db.INT, value: carrierKills},
returns: {type: Db.INT, value: returns},
kills: {type: Db.INT, value: kills},
assists: {type: Db.INT, value: assists},
deaths: {type: Db.INT, value: deaths}
});
} | static async addStatCTF(challenge, team, pilot, captures, pickups, carrierKills, returns, kills, assists, deaths) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
MERGE tblStat s
USING (VALUES (@challengeId, @teamId, @captures, @pickups, @carrierKills, @returns, @kills, @assists, @deaths, @playerId)) AS v (ChallengeId, TeamId, Captures, Pickups, CarrierKills, Returns, Kills, Assists, Deaths, PlayerId)
ON s.ChallengeId = v.ChallengeId AND s.TeamId = v.TeamId AND s.PlayerId = v.PlayerId
WHEN MATCHED THEN
UPDATE SET
TeamId = v.TeamId,
Captures = v.Captures,
Pickups = v.Pickups,
CarrierKills = v.CarrierKills,
Returns = v.Returns,
Kills = v.Kills,
Assists = v.Assists,
Deaths = v.Deaths
WHEN NOT MATCHED THEN
INSERT (ChallengeId, TeamId, PlayerId, Captures, Pickups, CarrierKills, Returns, Kills, Assists, Deaths) VALUES (v.ChallengeId, v.TeamId, v.PlayerId, v.Captures, v.Pickups, v.CarrierKills, v.Returns, v.Kills, v.Assists, v.Deaths);
`, {
discordId: {type: Db.VARCHAR(24), value: pilot.id},
challengeId: {type: Db.INT, value: challenge.id},
teamId: {type: Db.INT, value: team.id},
captures: {type: Db.INT, value: captures},
pickups: {type: Db.INT, value: pickups},
carrierKills: {type: Db.INT, value: carrierKills},
returns: {type: Db.INT, value: returns},
kills: {type: Db.INT, value: kills},
assists: {type: Db.INT, value: assists},
deaths: {type: Db.INT, value: deaths}
});
} |
JavaScript | static async addStatTA(challenge, team, pilot, kills, assists, deaths) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
MERGE tblStat s
USING (VALUES (@challengeId, @teamId, @kills, @assists, @deaths, @playerId)) AS v (ChallengeId, TeamId, Kills, Assists, Deaths, PlayerId)
ON s.ChallengeId = v.ChallengeId AND s.TeamId = v.TeamId AND s.PlayerId = v.PlayerId
WHEN MATCHED THEN
UPDATE SET
TeamId = v.TeamId,
Kills = v.Kills,
Assists = v.Assists,
Deaths = v.Deaths
WHEN NOT MATCHED THEN
INSERT (ChallengeId, TeamId, PlayerId, Kills, Assists, Deaths) VALUES (v.ChallengeId, v.TeamId, v.PlayerId, v.Kills, v.Assists, v.Deaths);
`, {
discordId: {type: Db.VARCHAR(24), value: pilot.id},
challengeId: {type: Db.INT, value: challenge.id},
teamId: {type: Db.INT, value: team.id},
kills: {type: Db.INT, value: kills},
assists: {type: Db.INT, value: assists},
deaths: {type: Db.INT, value: deaths}
});
} | static async addStatTA(challenge, team, pilot, kills, assists, deaths) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
MERGE tblStat s
USING (VALUES (@challengeId, @teamId, @kills, @assists, @deaths, @playerId)) AS v (ChallengeId, TeamId, Kills, Assists, Deaths, PlayerId)
ON s.ChallengeId = v.ChallengeId AND s.TeamId = v.TeamId AND s.PlayerId = v.PlayerId
WHEN MATCHED THEN
UPDATE SET
TeamId = v.TeamId,
Kills = v.Kills,
Assists = v.Assists,
Deaths = v.Deaths
WHEN NOT MATCHED THEN
INSERT (ChallengeId, TeamId, PlayerId, Kills, Assists, Deaths) VALUES (v.ChallengeId, v.TeamId, v.PlayerId, v.Kills, v.Assists, v.Deaths);
`, {
discordId: {type: Db.VARCHAR(24), value: pilot.id},
challengeId: {type: Db.INT, value: challenge.id},
teamId: {type: Db.INT, value: team.id},
kills: {type: Db.INT, value: kills},
assists: {type: Db.INT, value: assists},
deaths: {type: Db.INT, value: deaths}
});
} |
JavaScript | static async addStreamer(challenge, member) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
MERGE tblChallengeStreamer cs
USING (VALUES (@challengeId, @playerId)) AS v (ChallengeId, PlayerId)
ON cs.ChallengeId = v.ChallengeId AND cs.PlayerId = v.PlayerId
WHEN NOT MATCHED THEN
INSERT (ChallengeId, PlayerId) VALUES (v.ChallengeId, v.PlayerId);
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} | static async addStreamer(challenge, member) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
MERGE tblChallengeStreamer cs
USING (VALUES (@challengeId, @playerId)) AS v (ChallengeId, PlayerId)
ON cs.ChallengeId = v.ChallengeId AND cs.PlayerId = v.PlayerId
WHEN NOT MATCHED THEN
INSERT (ChallengeId, PlayerId) VALUES (v.ChallengeId, v.PlayerId);
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} |
JavaScript | static async clearStats(challenge) {
await db.query(/* sql */`
DELETE FROM tblStat WHERE ChallengeId = @id
DELETE FROM tblDamage WHERE ChallengeId = @id
`, {id: {type: Db.INT, value: challenge.id}});
} | static async clearStats(challenge) {
await db.query(/* sql */`
DELETE FROM tblStat WHERE ChallengeId = @id
DELETE FROM tblDamage WHERE ChallengeId = @id
`, {id: {type: Db.INT, value: challenge.id}});
} |
JavaScript | static async clock(team, challenge) {
/** @type {ChallengeDbTypes.ClockRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET DateClocked = GETUTCDATE(), DateClockDeadline = DATEADD(DAY, 28, GETUTCDATE()), ClockTeamId = @teamId, DateClockDeadlineNotified = NULL WHERE ChallengeId = @challengeId
SELECT DateClocked, DateClockDeadline FROM tblChallenge WHERE ChallengeId = @challengeId
`, {
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && {clocked: data.recordsets[0][0].DateClocked, clockDeadline: data.recordsets[0][0].DateClockDeadline} || void 0;
} | static async clock(team, challenge) {
/** @type {ChallengeDbTypes.ClockRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET DateClocked = GETUTCDATE(), DateClockDeadline = DATEADD(DAY, 28, GETUTCDATE()), ClockTeamId = @teamId, DateClockDeadlineNotified = NULL WHERE ChallengeId = @challengeId
SELECT DateClocked, DateClockDeadline FROM tblChallenge WHERE ChallengeId = @challengeId
`, {
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && {clocked: data.recordsets[0][0].DateClocked, clockDeadline: data.recordsets[0][0].DateClockDeadline} || void 0;
} |
JavaScript | static async close(challenge) {
/** @type {ChallengeDbTypes.CloseRecordsets} */
const data = await db.query(/* sql */`
DECLARE @challengingTeamId INT
DECLARE @challengedTeamId INT
SELECT @challengingTeamId = ChallengingTeamId FROM tblChallenge WHERE ChallengeId = @challengeId
SELECT @challengedTeamId = ChallengedTeamId FROM tblChallenge WHERE ChallengeId = @challengeId
UPDATE tblChallenge SET DateClosed = GETUTCDATE() WHERE ChallengeId = @challengeId
IF EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty WHERE TeamId = @challengingTeamId)
BEGIN
IF (
SELECT COUNT(ChallengeId)
FROM tblChallenge
WHERE (ChallengingTeamId = @challengingTeamId or ChallengedTeamId = @challengingTeamId)
AND DateClosed IS NOT NULL
AND DateConfirmed IS NOT NULL
AND DateVoided IS NULL
AND MatchTime > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengingTeamId)
AND DateConfirmed > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengingTeamId)
AND ChallengeId <> @challengeId
) >= 10
BEGIN
DELETE FROM tblTeamPenalty WHERE TeamId = @challengingTeamId
END
END
IF EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty WHERE TeamId = @challengedTeamId)
BEGIN
IF (
SELECT COUNT(ChallengeId)
FROM tblChallenge
WHERE (ChallengingTeamId = @challengedTeamId or ChallengedTeamId = @challengedTeamId)
AND DateClosed IS NOT NULL
AND DateConfirmed IS NOT NULL
AND DateVoided IS NULL
AND MatchTime > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengedTeamId)
AND DateConfirmed > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengedTeamId)
AND ChallengeId <> @challengeId
) >= 10
BEGIN
DELETE FROM tblTeamPenalty WHERE TeamId = @challengedTeamId
END
END
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0].length > 0) {
await Cache.invalidate(data.recordsets[0].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
} else {
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:closed`]);
}
} | static async close(challenge) {
/** @type {ChallengeDbTypes.CloseRecordsets} */
const data = await db.query(/* sql */`
DECLARE @challengingTeamId INT
DECLARE @challengedTeamId INT
SELECT @challengingTeamId = ChallengingTeamId FROM tblChallenge WHERE ChallengeId = @challengeId
SELECT @challengedTeamId = ChallengedTeamId FROM tblChallenge WHERE ChallengeId = @challengeId
UPDATE tblChallenge SET DateClosed = GETUTCDATE() WHERE ChallengeId = @challengeId
IF EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty WHERE TeamId = @challengingTeamId)
BEGIN
IF (
SELECT COUNT(ChallengeId)
FROM tblChallenge
WHERE (ChallengingTeamId = @challengingTeamId or ChallengedTeamId = @challengingTeamId)
AND DateClosed IS NOT NULL
AND DateConfirmed IS NOT NULL
AND DateVoided IS NULL
AND MatchTime > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengingTeamId)
AND DateConfirmed > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengingTeamId)
AND ChallengeId <> @challengeId
) >= 10
BEGIN
DELETE FROM tblTeamPenalty WHERE TeamId = @challengingTeamId
END
END
IF EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty WHERE TeamId = @challengedTeamId)
BEGIN
IF (
SELECT COUNT(ChallengeId)
FROM tblChallenge
WHERE (ChallengingTeamId = @challengedTeamId or ChallengedTeamId = @challengedTeamId)
AND DateClosed IS NOT NULL
AND DateConfirmed IS NOT NULL
AND DateVoided IS NULL
AND MatchTime > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengedTeamId)
AND DateConfirmed > (SELECT DatePenalized FROM tblTeamPenalty WHERE TeamId = @challengedTeamId)
AND ChallengeId <> @challengeId
) >= 10
BEGIN
DELETE FROM tblTeamPenalty WHERE TeamId = @challengedTeamId
END
END
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0].length > 0) {
await Cache.invalidate(data.recordsets[0].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
} else {
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:closed`]);
}
} |
JavaScript | static async confirmGameType(challenge) {
/** @type {ChallengeDbTypes.ConfirmGameTypeRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET GameType = SuggestedGameType, SuggestedGameType = NULL, SuggestedGameTypeTeamId = NULL WHERE ChallengeId = @challengeId
SELECT ch.Map
FROM tblChallengeHome ch
INNER JOIN tblChallenge c ON ch.ChallengeId = c.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END
WHERE ch.ChallengeId = @challengeId
ORDER BY ch.Map
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0].map((row) => row.Map) || [];
} | static async confirmGameType(challenge) {
/** @type {ChallengeDbTypes.ConfirmGameTypeRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET GameType = SuggestedGameType, SuggestedGameType = NULL, SuggestedGameTypeTeamId = NULL WHERE ChallengeId = @challengeId
SELECT ch.Map
FROM tblChallengeHome ch
INNER JOIN tblChallenge c ON ch.ChallengeId = c.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END
WHERE ch.ChallengeId = @challengeId
ORDER BY ch.Map
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0].map((row) => row.Map) || [];
} |
JavaScript | static async confirmMap(challenge) {
await db.query(/* sql */`
UPDATE tblChallenge SET Map = SuggestedMap, SuggestedMap = NULL, SuggestedMapTeamId = NULL, UsingHomeMapTeam = 0 WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
} | static async confirmMap(challenge) {
await db.query(/* sql */`
UPDATE tblChallenge SET Map = SuggestedMap, SuggestedMap = NULL, SuggestedMapTeamId = NULL, UsingHomeMapTeam = 0 WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
} |
JavaScript | static async confirmTeamSize(challenge) {
/** @type {ChallengeDbTypes.ConfirmTeamSizeRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET TeamSize = SuggestedTeamSize, SuggestedTeamSize = NULL, SuggestedTeamSizeTeamId = NULL WHERE ChallengeId = @challengeId
IF NOT EXISTS(
SELECT TOP 1 1
FROM tblChallengeHome ch
INNER JOIN tblChallenge c ON ch.ChallengeId = c.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END AND c.Map = ch.Map
)
BEGIN
UPDATE tblChallenge SET Map = NULL WHERE ChallengeId = @challengeId
END
SELECT ch.Map
FROM tblChallengeHome ch
INNER JOIN tblChallenge c ON ch.ChallengeId = c.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END
WHERE ch.ChallengeId = @challengeId
ORDER BY ch.Map
`, {
challengeId: {type: Db.INT, value: challenge.id},
map: {type: Db.VARCHAR(100), value: challenge.details.map}
});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0].map((row) => row.Map) || [];
} | static async confirmTeamSize(challenge) {
/** @type {ChallengeDbTypes.ConfirmTeamSizeRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET TeamSize = SuggestedTeamSize, SuggestedTeamSize = NULL, SuggestedTeamSizeTeamId = NULL WHERE ChallengeId = @challengeId
IF NOT EXISTS(
SELECT TOP 1 1
FROM tblChallengeHome ch
INNER JOIN tblChallenge c ON ch.ChallengeId = c.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END AND c.Map = ch.Map
)
BEGIN
UPDATE tblChallenge SET Map = NULL WHERE ChallengeId = @challengeId
END
SELECT ch.Map
FROM tblChallengeHome ch
INNER JOIN tblChallenge c ON ch.ChallengeId = c.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END
WHERE ch.ChallengeId = @challengeId
ORDER BY ch.Map
`, {
challengeId: {type: Db.INT, value: challenge.id},
map: {type: Db.VARCHAR(100), value: challenge.details.map}
});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0].map((row) => row.Map) || [];
} |
JavaScript | static async confirmTime(challenge) {
await db.query(/* sql */`
UPDATE tblChallenge SET MatchTime = SuggestedTime, SuggestedTime = NULL, SuggestedTimeTeamId = NULL, DateMatchTimeNotified = NULL, DateMatchTimePassedNotified = NULL WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
} | static async confirmTime(challenge) {
await db.query(/* sql */`
UPDATE tblChallenge SET MatchTime = SuggestedTime, SuggestedTime = NULL, SuggestedTimeTeamId = NULL, DateMatchTimeNotified = NULL, DateMatchTimePassedNotified = NULL WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
} |
JavaScript | static async extend(challenge) {
/** @type {ChallengeDbTypes.ExtendRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET
DateClockDeadline = CASE WHEN DateClockDeadline IS NULL THEN NULL ELSE DATEADD(DAY, 14, GETUTCDATE()) END,
MatchTime = NULL,
SuggestedTime = NULL,
SuggestedTimeTeamId = NULL,
DateMatchTimeNotified = NULL,
DateMatchTimePassedNotified = NULL,
DateClockDeadlineNotified = NULL
WHERE ChallengeId = @challengeId
SELECT DateClockDeadline FROM tblChallenge WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateClockDeadline || void 0;
} | static async extend(challenge) {
/** @type {ChallengeDbTypes.ExtendRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET
DateClockDeadline = CASE WHEN DateClockDeadline IS NULL THEN NULL ELSE DATEADD(DAY, 14, GETUTCDATE()) END,
MatchTime = NULL,
SuggestedTime = NULL,
SuggestedTimeTeamId = NULL,
DateMatchTimeNotified = NULL,
DateMatchTimePassedNotified = NULL,
DateClockDeadlineNotified = NULL
WHERE ChallengeId = @challengeId
SELECT DateClockDeadline FROM tblChallenge WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateClockDeadline || void 0;
} |
JavaScript | static async pickMap(challenge, number) {
/** @type {ChallengeDbTypes.PickMapRecordsets} */
const data = await db.query(/* sql */`
DECLARE @Homes TABLE (
Map VARCHAR(100) NOT NULL,
Number INT NOT NULL
)
INSERT INTO @Homes (Map, Number)
SELECT ch.Map, ROW_NUMBER() OVER (ORDER BY ch.Map)
FROM tblChallenge c
INNER JOIN tblChallengeHome ch ON c.ChallengeId = ch.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END
WHERE c.ChallengeId = @challengeId
UPDATE c
SET Map = h.Map,
UsingHomeMapTeam = 1
FROM tblChallenge c
CROSS JOIN @Homes h
WHERE c.ChallengeId = @challengeId
AND h.Number = @number
SELECT Map FROM tblChallenge WHERE ChallengeId = @challengeId
`, {
challengeId: {type: Db.INT, value: challenge.id},
number: {type: Db.INT, value: number}
});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].Map || void 0;
} | static async pickMap(challenge, number) {
/** @type {ChallengeDbTypes.PickMapRecordsets} */
const data = await db.query(/* sql */`
DECLARE @Homes TABLE (
Map VARCHAR(100) NOT NULL,
Number INT NOT NULL
)
INSERT INTO @Homes (Map, Number)
SELECT ch.Map, ROW_NUMBER() OVER (ORDER BY ch.Map)
FROM tblChallenge c
INNER JOIN tblChallengeHome ch ON c.ChallengeId = ch.ChallengeId AND ch.GameType = CASE WHEN c.GameType = 'CTF' THEN 'CTF' WHEN c.TeamSize = 2 THEN '2v2' WHEN c.TeamSize = 3 THEN '3v3' WHEN c.TeamSize >= 4 THEN '4v4+' ELSE '' END
WHERE c.ChallengeId = @challengeId
UPDATE c
SET Map = h.Map,
UsingHomeMapTeam = 1
FROM tblChallenge c
CROSS JOIN @Homes h
WHERE c.ChallengeId = @challengeId
AND h.Number = @number
SELECT Map FROM tblChallenge WHERE ChallengeId = @challengeId
`, {
challengeId: {type: Db.INT, value: challenge.id},
number: {type: Db.INT, value: number}
});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].Map || void 0;
} |
JavaScript | static async removeStat(challenge, pilot) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
DELETE FROM tblStat WHERE ChallengeId = @challengeId AND PlayerId = @playerId
`, {
discordId: {type: Db.VARCHAR(24), value: pilot.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} | static async removeStat(challenge, pilot) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
DELETE FROM tblStat WHERE ChallengeId = @challengeId AND PlayerId = @playerId
`, {
discordId: {type: Db.VARCHAR(24), value: pilot.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} |
JavaScript | static async removeStreamer(challenge, member) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
DELETE FROM tblChallengeStreamer
WHERE ChallengeId = @challengeId
AND PlayerId = @playerId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} | static async removeStreamer(challenge, member) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
DELETE FROM tblChallengeStreamer
WHERE ChallengeId = @challengeId
AND PlayerId = @playerId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} |
JavaScript | static async report(challenge, reportingTeam, challengingTeamScore, challengedTeamScore) {
/** @type {ChallengeDbTypes.ReportRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET
ReportingTeamId = @reportingTeamId,
ChallengingTeamScore = @challengingTeamScore,
ChallengedTeamScore = @challengedTeamScore,
DateReported = GETUTCDATE()
WHERE ChallengeId = @challengeId
SELECT DateReported FROM tblChallenge WHERE ChallengeId = @challengeId
`, {
reportingTeamId: {type: Db.INT, value: reportingTeam.id},
challengingTeamScore: {type: Db.INT, value: challengingTeamScore},
challengedTeamScore: {type: Db.INT, value: challengedTeamScore},
challengeId: {type: Db.INT, value: challenge.id}
});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateReported || void 0;
} | static async report(challenge, reportingTeam, challengingTeamScore, challengedTeamScore) {
/** @type {ChallengeDbTypes.ReportRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET
ReportingTeamId = @reportingTeamId,
ChallengingTeamScore = @challengingTeamScore,
ChallengedTeamScore = @challengedTeamScore,
DateReported = GETUTCDATE()
WHERE ChallengeId = @challengeId
SELECT DateReported FROM tblChallenge WHERE ChallengeId = @challengeId
`, {
reportingTeamId: {type: Db.INT, value: reportingTeam.id},
challengingTeamScore: {type: Db.INT, value: challengingTeamScore},
challengedTeamScore: {type: Db.INT, value: challengedTeamScore},
challengeId: {type: Db.INT, value: challenge.id}
});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateReported || void 0;
} |
JavaScript | static async requestRematch(challenge, team) {
await db.query(/* sql */`
UPDATE tblChallenge SET RematchTeamId = @teamId, DateRematchRequested = GETUTCDATE() WHERE ChallengeId = @challengeId
`, {
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} | static async requestRematch(challenge, team) {
await db.query(/* sql */`
UPDATE tblChallenge SET RematchTeamId = @teamId, DateRematchRequested = GETUTCDATE() WHERE ChallengeId = @challengeId
`, {
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} |
JavaScript | static async suggestGameType(challenge, team, gameType) {
await db.query(/* sql */`
UPDATE tblChallenge SET SuggestedGameType = @gameType, SuggestedGameTypeTeamId = @teamId WHERE ChallengeId = @challengeId
`, {
gameType: {type: Db.VARCHAR(5), value: gameType},
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} | static async suggestGameType(challenge, team, gameType) {
await db.query(/* sql */`
UPDATE tblChallenge SET SuggestedGameType = @gameType, SuggestedGameTypeTeamId = @teamId WHERE ChallengeId = @challengeId
`, {
gameType: {type: Db.VARCHAR(5), value: gameType},
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} |
JavaScript | static async suggestTeamSize(challenge, team, size) {
await db.query(/* sql */`
UPDATE tblChallenge SET SuggestedTeamSize = @size, SuggestedTeamSizeTeamId = @teamId WHERE ChallengeId = @challengeId
`, {
size: {type: Db.INT, value: size},
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} | static async suggestTeamSize(challenge, team, size) {
await db.query(/* sql */`
UPDATE tblChallenge SET SuggestedTeamSize = @size, SuggestedTeamSizeTeamId = @teamId WHERE ChallengeId = @challengeId
`, {
size: {type: Db.INT, value: size},
teamId: {type: Db.INT, value: team.id},
challengeId: {type: Db.INT, value: challenge.id}
});
} |
JavaScript | static async swapColors(challenge) {
await db.query(/* sql */`
UPDATE tblChallenge SET
BlueTeamId = OrangeTeamId,
OrangeTeamId = BlueTeamId
WHERE ChallengeId = @id
`, {id: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
} | static async swapColors(challenge) {
await db.query(/* sql */`
UPDATE tblChallenge SET
BlueTeamId = OrangeTeamId,
OrangeTeamId = BlueTeamId
WHERE ChallengeId = @id
`, {id: {type: Db.INT, value: challenge.id}});
await Cache.invalidate([`${settings.redisPrefix}:invalidate:challenge:updated`]);
} |
JavaScript | static async unvoid(challenge) {
/** @type {ChallengeDbTypes.UnvoidRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET DateVoided = NULL WHERE ChallengeId = @challengeId
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0].length > 0) {
await Cache.invalidate(data.recordsets[0].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
}
} | static async unvoid(challenge) {
/** @type {ChallengeDbTypes.UnvoidRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET DateVoided = NULL WHERE ChallengeId = @challengeId
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0].length > 0) {
await Cache.invalidate(data.recordsets[0].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
}
} |
JavaScript | static async void(challenge) {
/** @type {ChallengeDbTypes.VoidRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET DateVoided = GETUTCDATE() WHERE ChallengeId = @challengeId
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengingTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengingTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengingTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengedTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengedTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengedTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0].length > 0) {
await Cache.invalidate(data.recordsets[0].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
}
} | static async void(challenge) {
/** @type {ChallengeDbTypes.VoidRecordsets} */
const data = await db.query(/* sql */`
UPDATE tblChallenge SET DateVoided = GETUTCDATE() WHERE ChallengeId = @challengeId
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengingTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengingTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengingTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengedTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengedTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengedTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`, {challengeId: {type: Db.INT, value: challenge.id}});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0].length > 0) {
await Cache.invalidate(data.recordsets[0].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
}
} |
JavaScript | static async voidWithPenalties(challenge, teams) {
const params = {challengeId: {type: Db.INT, value: challenge.id}};
let sql = /* sql */`
UPDATE tblChallenge SET DateVoided = GETUTCDATE() WHERE ChallengeId = @challengeId
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengingTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengingTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengingTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengedTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengedTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengedTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
SELECT t.TeamId, CAST(CASE WHEN EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty tp WHERE tp.TeamId = t.TeamId) THEN 0 ELSE 1 END AS BIT) First
FROM tblTeam t
WHERE t.TeamId IN (${teams.map((t, index) => `@team${index}Id`).join(", ")})
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`;
teams.forEach((team, index) => {
params[`team${index}Id`] = {type: Db.INT, value: team.id};
sql = /* sql */`
${sql}
IF EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty WHERE TeamId = @team${index}Id)
BEGIN
UPDATE tblTeamPenalty
SET PenaltiesRemaining = PenaltiesRemaining + 3,
DatePenalized = GETUTCDATE()
WHERE TeamId = @team${index}Id
INSERT INTO tblLeadershipPenalty
(PlayerId, DatePenalized)
SELECT PlayerId, GETUTCDATE()
FROM tblRoster
WHERE TeamId = @team${index}Id
AND (Founder = 1 OR Captain = 1)
END
ELSE
BEGIN
INSERT INTO tblTeamPenalty
(TeamId, PenaltiesRemaining, DatePenalized)
VALUES (@team${index}Id, 3, GETUTCDATE())
END
`;
});
/** @type {ChallengeDbTypes.VoidWithPenaltiesRecordsets} */
const data = await db.query(sql, params);
if (data && data.recordsets && data.recordsets[1] && data.recordsets[1].length > 0) {
await Cache.invalidate(data.recordsets[1].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
}
return data && data.recordsets && data.recordsets[0] && data.recordsets[0].map((row) => ({teamId: row.TeamId, first: row.First})) || [];
} | static async voidWithPenalties(challenge, teams) {
const params = {challengeId: {type: Db.INT, value: challenge.id}};
let sql = /* sql */`
UPDATE tblChallenge SET DateVoided = GETUTCDATE() WHERE ChallengeId = @challengeId
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengingTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengingTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengingTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
IF EXISTS(SELECT TOP 1 1 FROM tblChallenge WHERE ChallengeId = @challengeId AND ChallengedTeamPenalized = 1)
BEGIN
UPDATE tblTeamPenalty SET PenaltiesRemaining = PenaltiesRemaining + 1 WHERE TeamId = (SELECT ChallengedTeamId FROM tblChallenge WHERE ChallengeId = @challengeId)
UPDATE tblChallenge SET ChallengedTeamPenalized = 0 WHERE ChallengeId = @challengeId
END
SELECT t.TeamId, CAST(CASE WHEN EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty tp WHERE tp.TeamId = t.TeamId) THEN 0 ELSE 1 END AS BIT) First
FROM tblTeam t
WHERE t.TeamId IN (${teams.map((t, index) => `@team${index}Id`).join(", ")})
SELECT PlayerId FROM tblStat WHERE ChallengeId = @challengeId
`;
teams.forEach((team, index) => {
params[`team${index}Id`] = {type: Db.INT, value: team.id};
sql = /* sql */`
${sql}
IF EXISTS(SELECT TOP 1 1 FROM tblTeamPenalty WHERE TeamId = @team${index}Id)
BEGIN
UPDATE tblTeamPenalty
SET PenaltiesRemaining = PenaltiesRemaining + 3,
DatePenalized = GETUTCDATE()
WHERE TeamId = @team${index}Id
INSERT INTO tblLeadershipPenalty
(PlayerId, DatePenalized)
SELECT PlayerId, GETUTCDATE()
FROM tblRoster
WHERE TeamId = @team${index}Id
AND (Founder = 1 OR Captain = 1)
END
ELSE
BEGIN
INSERT INTO tblTeamPenalty
(TeamId, PenaltiesRemaining, DatePenalized)
VALUES (@team${index}Id, 3, GETUTCDATE())
END
`;
});
/** @type {ChallengeDbTypes.VoidWithPenaltiesRecordsets} */
const data = await db.query(sql, params);
if (data && data.recordsets && data.recordsets[1] && data.recordsets[1].length > 0) {
await Cache.invalidate(data.recordsets[1].map((row) => `${settings.redisPrefix}:invalidate:player:${row.PlayerId}:updated`).concat(`${settings.redisPrefix}:invalidate:challenge:closed`));
}
return data && data.recordsets && data.recordsets[0] && data.recordsets[0].map((row) => ({teamId: row.TeamId, first: row.First})) || [];
} |
JavaScript | static async create(newTeam) {
let teamData;
try {
teamData = await Db.create(newTeam);
} catch (err) {
throw new Exception("There was a database error creating a team.", err);
}
const team = new Team(teamData);
try {
await team.setup(newTeam.member, false);
await newTeam.delete(`${newTeam.member.displayName} created the team ${newTeam.name}.`);
} catch (err) {
throw new Exception("There was a critical Discord error creating a team. Please resolve this manually as soon as possible.", err);
}
return team;
} | static async create(newTeam) {
let teamData;
try {
teamData = await Db.create(newTeam);
} catch (err) {
throw new Exception("There was a database error creating a team.", err);
}
const team = new Team(teamData);
try {
await team.setup(newTeam.member, false);
await newTeam.delete(`${newTeam.member.displayName} created the team ${newTeam.name}.`);
} catch (err) {
throw new Exception("There was a critical Discord error creating a team. Please resolve this manually as soon as possible.", err);
}
return team;
} |
JavaScript | async addCaptain(member, captain) {
try {
await Db.addCaptain(this, captain);
} catch (err) {
throw new Exception("There was a database error adding a captain.", err);
}
try {
const announcementsChannel = this.announcementsChannel;
if (!announcementsChannel) {
throw new Error("Announcement's channel does not exist for the team.");
}
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captain's voice channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await captain.roles.add(Discord.captainRole, `${member.displayName} added ${captain.displayName} as a captain of ${this.name}.`);
await captainsChannel.updateOverwrite(
captain,
{"VIEW_CHANNEL": true},
`${member.displayName} added ${captain.displayName} as a captain of ${this.name}.`
);
await captainsVoiceChannel.updateOverwrite(
captain,
{"VIEW_CHANNEL": true},
`${member.displayName} added ${captain.displayName} as a captain of ${this.name}.`
);
await this.updateChannels();
await Discord.queue(`${captain}, you have been added as a captain of **${this.name}**! You now have access to your team's captain's channel, ${captainsChannel}, and can post in the team's announcements channel, ${announcementsChannel}. Be sure to read the pinned messages in that channel for more information as to what you can do for your team as a captain.`, captain);
await Discord.queue(`Welcome **${captain}** as the newest team captain!`, captainsChannel);
await Discord.queue(`**${captain}** is now a team captain!`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Leadership Update",
color: this.role.color,
fields: [
{
name: "Captain Added",
value: `${captain}`
}
],
footer: {
text: `added by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error adding a captain. Please resolve this manually as soon as possible.", err);
}
} | async addCaptain(member, captain) {
try {
await Db.addCaptain(this, captain);
} catch (err) {
throw new Exception("There was a database error adding a captain.", err);
}
try {
const announcementsChannel = this.announcementsChannel;
if (!announcementsChannel) {
throw new Error("Announcement's channel does not exist for the team.");
}
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captain's voice channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await captain.roles.add(Discord.captainRole, `${member.displayName} added ${captain.displayName} as a captain of ${this.name}.`);
await captainsChannel.updateOverwrite(
captain,
{"VIEW_CHANNEL": true},
`${member.displayName} added ${captain.displayName} as a captain of ${this.name}.`
);
await captainsVoiceChannel.updateOverwrite(
captain,
{"VIEW_CHANNEL": true},
`${member.displayName} added ${captain.displayName} as a captain of ${this.name}.`
);
await this.updateChannels();
await Discord.queue(`${captain}, you have been added as a captain of **${this.name}**! You now have access to your team's captain's channel, ${captainsChannel}, and can post in the team's announcements channel, ${announcementsChannel}. Be sure to read the pinned messages in that channel for more information as to what you can do for your team as a captain.`, captain);
await Discord.queue(`Welcome **${captain}** as the newest team captain!`, captainsChannel);
await Discord.queue(`**${captain}** is now a team captain!`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Leadership Update",
color: this.role.color,
fields: [
{
name: "Captain Added",
value: `${captain}`
}
],
footer: {
text: `added by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error adding a captain. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async addNeutralMap(member, gameType, map) {
try {
await Db.addNeutralMap(this, gameType, map);
} catch (err) {
throw new Exception("There was a database error adding a neutral map.", err);
}
try {
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Guild channel does not exist for the team.");
}
await this.updateChannels();
await Discord.queue(`${member} has added ${gameType} neutral map **${map}**.`, teamChannel);
} catch (err) {
throw new Exception("There was a critical Discord error adding a neutral map. Please resolve this manually as soon as possible.", err);
}
} | async addNeutralMap(member, gameType, map) {
try {
await Db.addNeutralMap(this, gameType, map);
} catch (err) {
throw new Exception("There was a database error adding a neutral map.", err);
}
try {
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Guild channel does not exist for the team.");
}
await this.updateChannels();
await Discord.queue(`${member} has added ${gameType} neutral map **${map}**.`, teamChannel);
} catch (err) {
throw new Exception("There was a critical Discord error adding a neutral map. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async addPilot(member) {
try {
await Db.addPilot(member, this);
} catch (err) {
throw new Exception("There was a database error adding a pilot to a team.", err);
}
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await member.roles.add(this.role, `${member.displayName} accepted their invitation to ${this.name}.`);
await this.updateChannels();
await Discord.queue(`${member}, you are now a member of **${this.name}**! You now have access to your team's channel, ${teamChannel}.`, member);
await Discord.queue(`**${member}** has accepted your invitation to join the team!`, captainsChannel);
await Discord.queue(`**${member}** has joined the team!`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Pilot Added",
color: this.role.color,
fields: [
{
name: "Pilot Added",
value: `${member}`
}
],
footer: {
text: "added by accepted invitation"
}
}), Discord.rosterUpdatesChannel);
} catch (err) {
throw new Exception("There was a critical Discord error adding a pilot to a team. Please resolve this manually as soon as possible.", err);
}
} | async addPilot(member) {
try {
await Db.addPilot(member, this);
} catch (err) {
throw new Exception("There was a database error adding a pilot to a team.", err);
}
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await member.roles.add(this.role, `${member.displayName} accepted their invitation to ${this.name}.`);
await this.updateChannels();
await Discord.queue(`${member}, you are now a member of **${this.name}**! You now have access to your team's channel, ${teamChannel}.`, member);
await Discord.queue(`**${member}** has accepted your invitation to join the team!`, captainsChannel);
await Discord.queue(`**${member}** has joined the team!`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Pilot Added",
color: this.role.color,
fields: [
{
name: "Pilot Added",
value: `${member}`
}
],
footer: {
text: "added by accepted invitation"
}
}), Discord.rosterUpdatesChannel);
} catch (err) {
throw new Exception("There was a critical Discord error adding a pilot to a team. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async changeColor(member, color) {
try {
await this.role.setColor(color, `${member.displayName} updated the team color.`);
} catch (err) {
throw new Exception("There was a Discord error changing a team's color.", err);
}
} | async changeColor(member, color) {
try {
await this.role.setColor(color, `${member.displayName} updated the team color.`);
} catch (err) {
throw new Exception("There was a Discord error changing a team's color.", err);
}
} |
JavaScript | async disband(member) {
let challengeIds;
try {
challengeIds = await Db.disband(this);
} catch (err) {
throw new Exception("There was a database error disbanding a team.", err);
}
try {
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team channel does not exist.");
}
const announcementsChannel = this.announcementsChannel;
if (!announcementsChannel) {
throw new Error("Announcements channel does not exist.");
}
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain channel does not exist.");
}
const teamVoiceChannel = this.teamVoiceChannel;
if (!teamVoiceChannel) {
throw new Error("Team voice channel does not exist.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captains voice channel does not exist.");
}
const categoryChannel = this.categoryChannel;
if (!categoryChannel) {
throw new Error("Team category does not exist.");
}
await teamChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await announcementsChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await captainsChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await teamVoiceChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await captainsVoiceChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await categoryChannel.delete(`${member.displayName} disbanded ${this.name}.`);
const memberList = [];
for (const memberPair of this.role.members) {
const teamMember = memberPair[1];
memberList.push(`${teamMember}`);
if (Discord.captainRole.members.find((m) => m.id === teamMember.id)) {
await teamMember.roles.remove(Discord.captainRole, `${member.displayName} disbanded ${this.name}.`);
}
if (Discord.founderRole.members.find((m) => m.id === teamMember.id)) {
await teamMember.roles.remove(Discord.founderRole, `${member.displayName} disbanded ${this.name}.`);
}
await Discord.queue(`Your team **${this.name}** has been disbanded.`, teamMember);
}
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Team Disbanded",
color: this.role.color,
fields: memberList.length > 0 ? [
{
name: "Pilots Removed",
value: `${memberList.join(", ")}`
}
] : void 0,
footer: {
text: `disbanded by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
await this.role.delete(`${member.displayName} disbanded ${this.name}.`);
this.disbanded = true;
} catch (err) {
throw new Exception("There was a critical Discord error disbanding a team. Please resolve this manually as soon as possible.", err);
}
for (const challengeId of challengeIds) {
const challenge = await Challenge.getById(challengeId);
if (challenge) {
challenge.void(member, this);
}
}
} | async disband(member) {
let challengeIds;
try {
challengeIds = await Db.disband(this);
} catch (err) {
throw new Exception("There was a database error disbanding a team.", err);
}
try {
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team channel does not exist.");
}
const announcementsChannel = this.announcementsChannel;
if (!announcementsChannel) {
throw new Error("Announcements channel does not exist.");
}
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain channel does not exist.");
}
const teamVoiceChannel = this.teamVoiceChannel;
if (!teamVoiceChannel) {
throw new Error("Team voice channel does not exist.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captains voice channel does not exist.");
}
const categoryChannel = this.categoryChannel;
if (!categoryChannel) {
throw new Error("Team category does not exist.");
}
await teamChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await announcementsChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await captainsChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await teamVoiceChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await captainsVoiceChannel.delete(`${member.displayName} disbanded ${this.name}.`);
await categoryChannel.delete(`${member.displayName} disbanded ${this.name}.`);
const memberList = [];
for (const memberPair of this.role.members) {
const teamMember = memberPair[1];
memberList.push(`${teamMember}`);
if (Discord.captainRole.members.find((m) => m.id === teamMember.id)) {
await teamMember.roles.remove(Discord.captainRole, `${member.displayName} disbanded ${this.name}.`);
}
if (Discord.founderRole.members.find((m) => m.id === teamMember.id)) {
await teamMember.roles.remove(Discord.founderRole, `${member.displayName} disbanded ${this.name}.`);
}
await Discord.queue(`Your team **${this.name}** has been disbanded.`, teamMember);
}
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Team Disbanded",
color: this.role.color,
fields: memberList.length > 0 ? [
{
name: "Pilots Removed",
value: `${memberList.join(", ")}`
}
] : void 0,
footer: {
text: `disbanded by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
await this.role.delete(`${member.displayName} disbanded ${this.name}.`);
this.disbanded = true;
} catch (err) {
throw new Exception("There was a critical Discord error disbanding a team. Please resolve this manually as soon as possible.", err);
}
for (const challengeId of challengeIds) {
const challenge = await Challenge.getById(challengeId);
if (challenge) {
challenge.void(member, this);
}
}
} |
JavaScript | async hasClockedThisSeason(team) {
try {
return await Db.hasClockedTeamThisSeason(this, team);
} catch (err) {
throw new Exception("There was a database error getting whether a team has clocked another team this season.", err);
}
} | async hasClockedThisSeason(team) {
try {
return await Db.hasClockedTeamThisSeason(this, team);
} catch (err) {
throw new Exception("There was a database error getting whether a team has clocked another team this season.", err);
}
} |
JavaScript | async invitePilot(fromMember, toMember) {
try {
await Db.invitePilot(this, toMember);
} catch (err) {
throw new Exception("There was a database error inviting a pilot to a team.", err);
}
try {
await Discord.queue(`${toMember.displayName}, you have been invited to join **${this.name}** by ${fromMember.displayName}. You can accept this invitation by responding with \`!accept ${this.name}\`.`, toMember);
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error inviting a pilot to a team. Please resolve this manually as soon as possible.", err);
}
} | async invitePilot(fromMember, toMember) {
try {
await Db.invitePilot(this, toMember);
} catch (err) {
throw new Exception("There was a database error inviting a pilot to a team.", err);
}
try {
await Discord.queue(`${toMember.displayName}, you have been invited to join **${this.name}** by ${fromMember.displayName}. You can accept this invitation by responding with \`!accept ${this.name}\`.`, toMember);
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error inviting a pilot to a team. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async makeFounder(member, pilot) {
try {
await Db.makeFounder(this, pilot);
} catch (err) {
throw new Exception("There was a database error transfering a team founder to another pilot.", err);
}
try {
if (!this.role.members.find((m) => m.id === pilot.id)) {
throw new Error("Pilots are not on the same team.");
}
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await member.roles.remove(Discord.founderRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await member.roles.add(Discord.captainRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await pilot.roles.add(Discord.founderRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await pilot.roles.remove(Discord.captainRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await captainsChannel.updateOverwrite(
pilot,
{"VIEW_CHANNEL": true},
`${member.displayName} made ${pilot.displayName} the founder of ${this.name}.`
);
await this.updateChannels();
await Discord.queue(`${pilot}, you are now the founder of **${this.name}**!`, pilot);
await Discord.queue(`${pilot.displayName} is now the team founder!`, captainsChannel);
await Discord.queue(`${pilot.displayName} is now the team founder!`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Leadership Update",
color: this.role.color,
fields: [
{
name: "Old Founder",
value: `${member}`
},
{
name: "New Founder",
value: `${pilot}`
}
],
footer: {
text: `changed by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
} catch (err) {
throw new Exception("There was a critical Discord error transfering a team founder to another pilot. Please resolve this manually as soon as possible.", err);
}
} | async makeFounder(member, pilot) {
try {
await Db.makeFounder(this, pilot);
} catch (err) {
throw new Exception("There was a database error transfering a team founder to another pilot.", err);
}
try {
if (!this.role.members.find((m) => m.id === pilot.id)) {
throw new Error("Pilots are not on the same team.");
}
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await member.roles.remove(Discord.founderRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await member.roles.add(Discord.captainRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await pilot.roles.add(Discord.founderRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await pilot.roles.remove(Discord.captainRole, `${member.displayName} transferred founder of team ${this.name} to ${pilot.displayName}.`);
await captainsChannel.updateOverwrite(
pilot,
{"VIEW_CHANNEL": true},
`${member.displayName} made ${pilot.displayName} the founder of ${this.name}.`
);
await this.updateChannels();
await Discord.queue(`${pilot}, you are now the founder of **${this.name}**!`, pilot);
await Discord.queue(`${pilot.displayName} is now the team founder!`, captainsChannel);
await Discord.queue(`${pilot.displayName} is now the team founder!`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Leadership Update",
color: this.role.color,
fields: [
{
name: "Old Founder",
value: `${member}`
},
{
name: "New Founder",
value: `${pilot}`
}
],
footer: {
text: `changed by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
} catch (err) {
throw new Exception("There was a critical Discord error transfering a team founder to another pilot. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async pilotLeft(member) {
const team = await member.getTeam();
try {
await Db.removePilot(member, this);
} catch (err) {
throw new Exception("There was a database error removing a pilot from a team.", err);
}
try {
if (team) {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captain's voice channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
if (Discord.findGuildMemberById(member.id)) {
await member.roles.remove(Discord.captainRole, `${member.displayName} left the team.`);
await member.roles.remove(this.role, `${member.displayName} left the team.`);
let permissions = captainsChannel.permissionOverwrites.get(member.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} left the team.`);
}
permissions = captainsVoiceChannel.permissionOverwrites.get(member.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} left the team.`);
}
}
await Discord.queue(`${member.displayName} has left the team.`, captainsChannel);
await Discord.queue(`${member.displayName} has left the team.`, teamChannel);
const challenges = await Challenge.getAllByTeam(this);
for (const challenge of challenges) {
await challenge.updatePinnedPost();
}
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Pilot Left",
color: this.role.color,
fields: [
{
name: "Pilot Left",
value: `${member}`
}
],
footer: {
text: "pilot left team"
}
}), Discord.rosterUpdatesChannel);
}
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error removing a pilot from a team. Please resolve this manually as soon as possible.", err);
}
} | async pilotLeft(member) {
const team = await member.getTeam();
try {
await Db.removePilot(member, this);
} catch (err) {
throw new Exception("There was a database error removing a pilot from a team.", err);
}
try {
if (team) {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captain's voice channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
if (Discord.findGuildMemberById(member.id)) {
await member.roles.remove(Discord.captainRole, `${member.displayName} left the team.`);
await member.roles.remove(this.role, `${member.displayName} left the team.`);
let permissions = captainsChannel.permissionOverwrites.get(member.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} left the team.`);
}
permissions = captainsVoiceChannel.permissionOverwrites.get(member.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} left the team.`);
}
}
await Discord.queue(`${member.displayName} has left the team.`, captainsChannel);
await Discord.queue(`${member.displayName} has left the team.`, teamChannel);
const challenges = await Challenge.getAllByTeam(this);
for (const challenge of challenges) {
await challenge.updatePinnedPost();
}
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Pilot Left",
color: this.role.color,
fields: [
{
name: "Pilot Left",
value: `${member}`
}
],
footer: {
text: "pilot left team"
}
}), Discord.rosterUpdatesChannel);
}
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error removing a pilot from a team. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async reinstate(member) {
try {
await Db.reinstate(member, this);
} catch (err) {
throw new Exception("There was a database error reinstating a team.", err);
}
this.founder = member;
try {
await this.setup(member, true);
} catch (err) {
throw new Exception("There was a critical Discord error reinstating a team. Please resolve this manually as soon as possible.", err);
}
} | async reinstate(member) {
try {
await Db.reinstate(member, this);
} catch (err) {
throw new Exception("There was a database error reinstating a team.", err);
}
this.founder = member;
try {
await this.setup(member, true);
} catch (err) {
throw new Exception("There was a critical Discord error reinstating a team. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async removeCaptain(member, captain) {
try {
await Db.removeCaptain(this, captain);
} catch (err) {
throw new Exception("There was a database error removing a captain.", err);
}
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await captain.roles.remove(Discord.captainRole, `${member.displayName} removed ${captain.displayName} as a captain.`);
let permissions = captainsChannel.permissionOverwrites.get(captain.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} removed ${captain.displayName} as a captain.`);
}
permissions = captainsVoiceChannel.permissionOverwrites.get(captain.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} removed ${captain.displayName} as a captain.`);
}
await this.updateChannels();
await Discord.queue(`${captain}, you are no longer a captain of **${this.name}**.`, captain);
await Discord.queue(`${captain.displayName} is no longer a team captain.`, captainsChannel);
await Discord.queue(`${captain.displayName} is no longer a team captain.`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Leadership Update",
color: this.role.color,
fields: [
{
name: "Captain Removed",
value: `${captain}`
}
],
footer: {
text: `removed by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
} catch (err) {
throw new Exception("There was a critical Discord error removing a captain. Please resolve this manually as soon as possible.", err);
}
} | async removeCaptain(member, captain) {
try {
await Db.removeCaptain(this, captain);
} catch (err) {
throw new Exception("There was a database error removing a captain.", err);
}
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const captainsVoiceChannel = this.captainsVoiceChannel;
if (!captainsVoiceChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
await captain.roles.remove(Discord.captainRole, `${member.displayName} removed ${captain.displayName} as a captain.`);
let permissions = captainsChannel.permissionOverwrites.get(captain.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} removed ${captain.displayName} as a captain.`);
}
permissions = captainsVoiceChannel.permissionOverwrites.get(captain.id);
if (permissions && permissions.id) {
await permissions.delete(`${member.displayName} removed ${captain.displayName} as a captain.`);
}
await this.updateChannels();
await Discord.queue(`${captain}, you are no longer a captain of **${this.name}**.`, captain);
await Discord.queue(`${captain.displayName} is no longer a team captain.`, captainsChannel);
await Discord.queue(`${captain.displayName} is no longer a team captain.`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Leadership Update",
color: this.role.color,
fields: [
{
name: "Captain Removed",
value: `${captain}`
}
],
footer: {
text: `removed by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
} catch (err) {
throw new Exception("There was a critical Discord error removing a captain. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async removeNeutralMap(member, gameType, map) {
try {
await Db.removeNeutralMap(this, gameType, map);
} catch (err) {
throw new Exception("There was a database error removing a neutral map.", err);
}
try {
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Guild channel does not exist for the team.");
}
await this.updateChannels();
await Discord.queue(`${member} has removed ${gameType} neutral map **${map}**.`, teamChannel);
} catch (err) {
throw new Exception("There was a critical Discord error adding a neutral map. Please resolve this manually as soon as possible.", err);
}
} | async removeNeutralMap(member, gameType, map) {
try {
await Db.removeNeutralMap(this, gameType, map);
} catch (err) {
throw new Exception("There was a database error removing a neutral map.", err);
}
try {
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Guild channel does not exist for the team.");
}
await this.updateChannels();
await Discord.queue(`${member} has removed ${gameType} neutral map **${map}**.`, teamChannel);
} catch (err) {
throw new Exception("There was a critical Discord error adding a neutral map. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async removePilot(member, pilot) {
try {
await Db.removePilot(pilot, this);
} catch (err) {
throw new Exception("There was a database error removing a pilot from a team.", err);
}
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
if (this.role.members.find((m) => m.id === pilot.id)) {
await pilot.roles.remove(Discord.captainRole, `${member.displayName} removed ${pilot.displayName} from the team.`);
await Discord.queue(`${member.displayName} removed ${pilot.displayName} from the team.`, captainsChannel);
await Discord.queue(`${member.displayName} removed ${pilot.displayName} from the team.`, teamChannel);
await pilot.roles.remove(this.role, `${member.displayName} removed ${pilot.displayName} from the team.`);
await Discord.queue(`${pilot}, you have been removed from **${this.name}** by ${member.displayName}.`, pilot);
await Discord.queue(`${pilot.displayName} has been removed from the team by ${member.displayName}.`, captainsChannel);
await Discord.queue(`${pilot.displayName} has been removed from the team by ${member.displayName}.`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Pilot Removed",
color: this.role.color,
fields: [
{
name: "Pilot Removed",
value: `${pilot}`
}
],
footer: {
text: `removed by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
} else {
await Discord.queue(`${member.displayName} declined to invite ${pilot.displayName}.`, captainsChannel);
}
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error removing a pilot from a team. Please resolve this manually as soon as possible.", err);
}
} | async removePilot(member, pilot) {
try {
await Db.removePilot(pilot, this);
} catch (err) {
throw new Exception("There was a database error removing a pilot from a team.", err);
}
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
throw new Error("Captain's channel does not exist for the team.");
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
throw new Error("Team's channel does not exist.");
}
if (this.role.members.find((m) => m.id === pilot.id)) {
await pilot.roles.remove(Discord.captainRole, `${member.displayName} removed ${pilot.displayName} from the team.`);
await Discord.queue(`${member.displayName} removed ${pilot.displayName} from the team.`, captainsChannel);
await Discord.queue(`${member.displayName} removed ${pilot.displayName} from the team.`, teamChannel);
await pilot.roles.remove(this.role, `${member.displayName} removed ${pilot.displayName} from the team.`);
await Discord.queue(`${pilot}, you have been removed from **${this.name}** by ${member.displayName}.`, pilot);
await Discord.queue(`${pilot.displayName} has been removed from the team by ${member.displayName}.`, captainsChannel);
await Discord.queue(`${pilot.displayName} has been removed from the team by ${member.displayName}.`, teamChannel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.name} (${this.tag})`,
description: "Pilot Removed",
color: this.role.color,
fields: [
{
name: "Pilot Removed",
value: `${pilot}`
}
],
footer: {
text: `removed by ${member.displayName}`
}
}), Discord.rosterUpdatesChannel);
} else {
await Discord.queue(`${member.displayName} declined to invite ${pilot.displayName}.`, captainsChannel);
}
await this.updateChannels();
} catch (err) {
throw new Exception("There was a critical Discord error removing a pilot from a team. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async updateChannels() {
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
Log.exception(`Captain's channel does not exist. Please update ${this.name} manually.`);
return;
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
Log.exception(`Team's channel does not exist. Please update ${this.name} manually.`);
return;
}
const timezone = await this.getTimezone();
let teamInfo;
try {
teamInfo = await Db.getInfo(this);
} catch (err) {
Log.exception(`There was a database error retrieving team information. Please update ${this.name} manually.`, err);
return;
}
let topic = `${this.name}\nhttps://otl.gg/team/${this.tag}\n\nRoster:`;
teamInfo.members.forEach((member) => {
topic += `\n${member.name}`;
if (member.role) {
topic += ` - ${member.role}`;
}
});
let channelTopic = topic,
captainsChannelTopic = topic;
if (teamInfo.homes) {
const ta2v2Homes = teamInfo.homes.filter((h) => h.gameType === "2v2"),
ta3v3Homes = teamInfo.homes.filter((h) => h.gameType === "3v3"),
ta4v4Homes = teamInfo.homes.filter((h) => h.gameType === "4v4+"),
ctfHomes = teamInfo.homes.filter((h) => h.gameType === "CTF");
if (ta2v2Homes && ta2v2Homes.length > 0) {
channelTopic += "\n\nHome Team Anarchy 2v2 Maps:";
ta2v2Homes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
if (ta3v3Homes && ta3v3Homes.length > 0) {
channelTopic += "\n\nHome Team Anarchy 3v3 Maps:";
ta3v3Homes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
if (ta4v4Homes && ta4v4Homes.length > 0) {
channelTopic += "\n\nHome Team Anarchy 4v4+ Maps:";
ta4v4Homes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
if (ctfHomes && ctfHomes.length > 0) {
channelTopic += "\n\nHome Capture the Flag Maps:";
ctfHomes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
}
if (typeof teamInfo.penaltiesRemaining === "number") {
channelTopic += `\n\nTeam has been penalized. Penalized games remaining: ${teamInfo.penaltiesRemaining}`;
}
if (teamInfo.requests && teamInfo.requests.length > 0) {
captainsChannelTopic += "\n\nRequests:";
teamInfo.requests.forEach((request) => {
captainsChannelTopic += `\n${request.name} - ${request.date.toLocaleTimeString("en-us", {timeZone: timezone, hour12: true, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", timeZoneName: "short"})}`;
});
}
if (teamInfo.invites && teamInfo.invites.length > 0) {
captainsChannelTopic += "\n\nInvites:";
teamInfo.invites.forEach((invite) => {
captainsChannelTopic += `\n${invite.name} - ${invite.date.toLocaleTimeString("en-us", {timeZone: timezone, hour12: true, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", timeZoneName: "short"})}`;
});
}
teamChannel.setTopic(channelTopic, "Team topic update requested.").catch((err) => {
Log.exception(`There was an error updating the topic in ${this.teamChannelName}.`, err);
});
captainsChannel.setTopic(captainsChannelTopic, "Team topic update requested.").catch((err) => {
Log.exception(`There was an error updating the topic in ${this.captainsChannelName}.`, err);
});
} catch (err) {
Log.exception(`There was an error updating team information for ${this.name}. Please update ${this.name} manually.`, err);
}
} | async updateChannels() {
try {
const captainsChannel = this.captainsChannel;
if (!captainsChannel) {
Log.exception(`Captain's channel does not exist. Please update ${this.name} manually.`);
return;
}
const teamChannel = this.teamChannel;
if (!teamChannel) {
Log.exception(`Team's channel does not exist. Please update ${this.name} manually.`);
return;
}
const timezone = await this.getTimezone();
let teamInfo;
try {
teamInfo = await Db.getInfo(this);
} catch (err) {
Log.exception(`There was a database error retrieving team information. Please update ${this.name} manually.`, err);
return;
}
let topic = `${this.name}\nhttps://otl.gg/team/${this.tag}\n\nRoster:`;
teamInfo.members.forEach((member) => {
topic += `\n${member.name}`;
if (member.role) {
topic += ` - ${member.role}`;
}
});
let channelTopic = topic,
captainsChannelTopic = topic;
if (teamInfo.homes) {
const ta2v2Homes = teamInfo.homes.filter((h) => h.gameType === "2v2"),
ta3v3Homes = teamInfo.homes.filter((h) => h.gameType === "3v3"),
ta4v4Homes = teamInfo.homes.filter((h) => h.gameType === "4v4+"),
ctfHomes = teamInfo.homes.filter((h) => h.gameType === "CTF");
if (ta2v2Homes && ta2v2Homes.length > 0) {
channelTopic += "\n\nHome Team Anarchy 2v2 Maps:";
ta2v2Homes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
if (ta3v3Homes && ta3v3Homes.length > 0) {
channelTopic += "\n\nHome Team Anarchy 3v3 Maps:";
ta3v3Homes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
if (ta4v4Homes && ta4v4Homes.length > 0) {
channelTopic += "\n\nHome Team Anarchy 4v4+ Maps:";
ta4v4Homes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
if (ctfHomes && ctfHomes.length > 0) {
channelTopic += "\n\nHome Capture the Flag Maps:";
ctfHomes.forEach((home) => {
channelTopic += `\n${home.map}`;
});
}
}
if (typeof teamInfo.penaltiesRemaining === "number") {
channelTopic += `\n\nTeam has been penalized. Penalized games remaining: ${teamInfo.penaltiesRemaining}`;
}
if (teamInfo.requests && teamInfo.requests.length > 0) {
captainsChannelTopic += "\n\nRequests:";
teamInfo.requests.forEach((request) => {
captainsChannelTopic += `\n${request.name} - ${request.date.toLocaleTimeString("en-us", {timeZone: timezone, hour12: true, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", timeZoneName: "short"})}`;
});
}
if (teamInfo.invites && teamInfo.invites.length > 0) {
captainsChannelTopic += "\n\nInvites:";
teamInfo.invites.forEach((invite) => {
captainsChannelTopic += `\n${invite.name} - ${invite.date.toLocaleTimeString("en-us", {timeZone: timezone, hour12: true, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", timeZoneName: "short"})}`;
});
}
teamChannel.setTopic(channelTopic, "Team topic update requested.").catch((err) => {
Log.exception(`There was an error updating the topic in ${this.teamChannelName}.`, err);
});
captainsChannel.setTopic(captainsChannelTopic, "Team topic update requested.").catch((err) => {
Log.exception(`There was an error updating the topic in ${this.captainsChannelName}.`, err);
});
} catch (err) {
Log.exception(`There was an error updating team information for ${this.name}. Please update ${this.name} manually.`, err);
}
} |
JavaScript | static async updateRatingsForSeasonFromChallenge(challenge) {
let data;
try {
data = await MatchDb.getSeasonDataFromChallenge(challenge);
} catch (err) {
throw new Exception("There was a database error getting the season's matches.", err);
}
if (!data) {
return;
}
/** @type {Object<number, number>} */
const ratings = {};
/** @type {ChallengeTypes.GamesByChallengeId} */
const challengeRatings = {};
data.matches.forEach((match) => {
const fx = match.gameType === "CTF" && match.season >= 3 ? Elo.actualCTF : Elo.actualTA;
if (!ratings[match.challengingTeamId]) {
ratings[match.challengingTeamId] = 1500;
}
if (!ratings[match.challengedTeamId]) {
ratings[match.challengedTeamId] = 1500;
}
const challengingTeamNewRating = Elo.update(Elo.expected(ratings[match.challengingTeamId], ratings[match.challengedTeamId]), fx(match.challengingTeamScore, match.challengedTeamScore), ratings[match.challengingTeamId], data.k),
challengedTeamNewRating = Elo.update(Elo.expected(ratings[match.challengedTeamId], ratings[match.challengingTeamId]), fx(match.challengedTeamScore, match.challengingTeamScore), ratings[match.challengedTeamId], data.k);
challengeRatings[match.id] = {
challengingTeamRating: challengingTeamNewRating,
challengedTeamRating: challengedTeamNewRating,
change: challengingTeamNewRating - ratings[match.challengingTeamId]
};
ratings[match.challengingTeamId] = challengingTeamNewRating;
ratings[match.challengedTeamId] = challengedTeamNewRating;
});
try {
await Db.updateRatingsForSeasonFromChallenge(challenge, ratings, challengeRatings);
} catch (err) {
throw new Exception("There was a database error updating season ratings.", err);
}
} | static async updateRatingsForSeasonFromChallenge(challenge) {
let data;
try {
data = await MatchDb.getSeasonDataFromChallenge(challenge);
} catch (err) {
throw new Exception("There was a database error getting the season's matches.", err);
}
if (!data) {
return;
}
/** @type {Object<number, number>} */
const ratings = {};
/** @type {ChallengeTypes.GamesByChallengeId} */
const challengeRatings = {};
data.matches.forEach((match) => {
const fx = match.gameType === "CTF" && match.season >= 3 ? Elo.actualCTF : Elo.actualTA;
if (!ratings[match.challengingTeamId]) {
ratings[match.challengingTeamId] = 1500;
}
if (!ratings[match.challengedTeamId]) {
ratings[match.challengedTeamId] = 1500;
}
const challengingTeamNewRating = Elo.update(Elo.expected(ratings[match.challengingTeamId], ratings[match.challengedTeamId]), fx(match.challengingTeamScore, match.challengedTeamScore), ratings[match.challengingTeamId], data.k),
challengedTeamNewRating = Elo.update(Elo.expected(ratings[match.challengedTeamId], ratings[match.challengingTeamId]), fx(match.challengedTeamScore, match.challengingTeamScore), ratings[match.challengedTeamId], data.k);
challengeRatings[match.id] = {
challengingTeamRating: challengingTeamNewRating,
challengedTeamRating: challengedTeamNewRating,
change: challengingTeamNewRating - ratings[match.challengingTeamId]
};
ratings[match.challengingTeamId] = challengingTeamNewRating;
ratings[match.challengedTeamId] = challengedTeamNewRating;
});
try {
await Db.updateRatingsForSeasonFromChallenge(challenge, ratings, challengeRatings);
} catch (err) {
throw new Exception("There was a database error updating season ratings.", err);
}
} |
JavaScript | static async remove(title) {
await db.query(/* sql */`
DELETE FROM tblEvent WHERE Title = @title
`, {
title: {type: Db.VARCHAR(200), value: title}
});
} | static async remove(title) {
await db.query(/* sql */`
DELETE FROM tblEvent WHERE Title = @title
`, {
title: {type: Db.VARCHAR(200), value: title}
});
} |
JavaScript | static async remove(map) {
await db.query(/* sql */`
DELETE FROM tblAllowedMap WHERE Map = @map
`, {map: {type: Db.VARCHAR(100), value: map}});
} | static async remove(map) {
await db.query(/* sql */`
DELETE FROM tblAllowedMap WHERE Map = @map
`, {map: {type: Db.VARCHAR(100), value: map}});
} |
JavaScript | static async remove(title) {
try {
await Db.remove(title);
} catch (err) {
throw new Exception("There was a database error removing an event.", err);
}
} | static async remove(title) {
try {
await Db.remove(title);
} catch (err) {
throw new Exception("There was a database error removing an event.", err);
}
} |
JavaScript | static async bannedFromTeamUntil(member, team) {
/** @type {PlayerDbTypes.BannedFromTeamUntilRecordsets} */
const data = await db.query(/* sql */`
SELECT tb.DateExpires
FROM tblTeamBan tb
INNER JOIN tblPlayer p ON tb.PlayerId = p.PlayerId
WHERE tb.TeamId = @teamId
AND p.DiscordId = @discordId
`, {
teamId: {type: Db.INT, value: team.id},
discordId: {type: Db.VARCHAR(24), value: member.id}
});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateExpires && data.recordsets[0][0].DateExpires > new Date() && data.recordsets[0][0].DateExpires || void 0;
} | static async bannedFromTeamUntil(member, team) {
/** @type {PlayerDbTypes.BannedFromTeamUntilRecordsets} */
const data = await db.query(/* sql */`
SELECT tb.DateExpires
FROM tblTeamBan tb
INNER JOIN tblPlayer p ON tb.PlayerId = p.PlayerId
WHERE tb.TeamId = @teamId
AND p.DiscordId = @discordId
`, {
teamId: {type: Db.INT, value: team.id},
discordId: {type: Db.VARCHAR(24), value: member.id}
});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateExpires && data.recordsets[0][0].DateExpires > new Date() && data.recordsets[0][0].DateExpires || void 0;
} |
JavaScript | static async canBeCaptain(member) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
SELECT TOP 1 1
FROM tblLeadershipPenalty lp
INNER JOIN tblPlayer p ON lp.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}});
return !(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} | static async canBeCaptain(member) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
SELECT TOP 1 1
FROM tblLeadershipPenalty lp
INNER JOIN tblPlayer p ON lp.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}});
return !(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} |
JavaScript | static async canRemovePilot(member, pilot) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
DECLARE @playerId INT
DECLARE @pilotPlayerId INT
DECLARE @teamId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
SELECT @pilotPlayerId = PlayerId FROM tblPlayer WHERE DiscordId = @pilotId
SELECT @teamId = TeamId FROM tblRoster WHERE PlayerId = @playerId
SELECT TOP 1 1
FROM (
SELECT RosterId FROM tblRoster WHERE TeamId = @teamId AND PlayerId = @pilotPlayerId
UNION SELECT RequestId FROM tblRequest WHERE TeamId = @teamId AND PlayerId = @pilotPlayerId
UNION SELECT InviteId FROM tblInvite WHERE TeamId = @teamId AND PlayerId = @pilotPlayerId
) a
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
pilotId: {type: Db.VARCHAR(24), value: pilot.id}
});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} | static async canRemovePilot(member, pilot) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
DECLARE @playerId INT
DECLARE @pilotPlayerId INT
DECLARE @teamId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
SELECT @pilotPlayerId = PlayerId FROM tblPlayer WHERE DiscordId = @pilotId
SELECT @teamId = TeamId FROM tblRoster WHERE PlayerId = @playerId
SELECT TOP 1 1
FROM (
SELECT RosterId FROM tblRoster WHERE TeamId = @teamId AND PlayerId = @pilotPlayerId
UNION SELECT RequestId FROM tblRequest WHERE TeamId = @teamId AND PlayerId = @pilotPlayerId
UNION SELECT InviteId FROM tblInvite WHERE TeamId = @teamId AND PlayerId = @pilotPlayerId
) a
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
pilotId: {type: Db.VARCHAR(24), value: pilot.id}
});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} |
JavaScript | static async clearTimezone(member) {
/** @type {PlayerDbTypes.ClearTimezoneRecordsets} */
const data = await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
IF @playerId IS NULL
BEGIN
INSERT INTO tblPlayer (DiscordId, Name)
VALUES (@discordId, @name)
SET @playerId = SCOPE_IDENTITY()
END
UPDATE tblPlayer SET Timezone = null WHERE PlayerId = @playerId
SELECT @playerId PlayerId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
name: {type: Db.VARCHAR(24), value: member.displayName}
});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].PlayerId) {
await Cache.invalidate([`${settings.redisPrefix}:invalidate:player:freeagents`, `${settings.redisPrefix}:invalidate:player:${data.recordsets[0][0].PlayerId}:updated`]);
} else {
await Cache.invalidate([`${settings.redisPrefix}:invalidate:player:freeagents`]);
}
} | static async clearTimezone(member) {
/** @type {PlayerDbTypes.ClearTimezoneRecordsets} */
const data = await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
IF @playerId IS NULL
BEGIN
INSERT INTO tblPlayer (DiscordId, Name)
VALUES (@discordId, @name)
SET @playerId = SCOPE_IDENTITY()
END
UPDATE tblPlayer SET Timezone = null WHERE PlayerId = @playerId
SELECT @playerId PlayerId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
name: {type: Db.VARCHAR(24), value: member.displayName}
});
if (data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].PlayerId) {
await Cache.invalidate([`${settings.redisPrefix}:invalidate:player:freeagents`, `${settings.redisPrefix}:invalidate:player:${data.recordsets[0][0].PlayerId}:updated`]);
} else {
await Cache.invalidate([`${settings.redisPrefix}:invalidate:player:freeagents`]);
}
} |
JavaScript | static async hasBeenInvitedToTeam(member, team) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
SELECT TOP 1 1
FROM tblInvite i
INNER JOIN tblPlayer p ON i.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
AND i.TeamId = @teamId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
teamId: {type: Db.INT, value: team.id}
});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} | static async hasBeenInvitedToTeam(member, team) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
SELECT TOP 1 1
FROM tblInvite i
INNER JOIN tblPlayer p ON i.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
AND i.TeamId = @teamId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
teamId: {type: Db.INT, value: team.id}
});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} |
JavaScript | static async hasRequestedTeam(member, team) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
SELECT TOP 1 1
FROM tblRequest r
INNER JOIN tblPlayer p ON r.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
AND r.TeamId = @teamId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
teamId: {type: Db.INT, value: team.id}
});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} | static async hasRequestedTeam(member, team) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
SELECT TOP 1 1
FROM tblRequest r
INNER JOIN tblPlayer p ON r.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
AND r.TeamId = @teamId
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
teamId: {type: Db.INT, value: team.id}
});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} |
JavaScript | static async joinTeamDeniedUntil(member) {
/** @type {PlayerDbTypes.JoinTeamDeniedUntilRecordsets} */
const data = await db.query(/* sql */`
SELECT jb.DateExpires
FROM tblJoinBan jb
INNER JOIN tblPlayer p ON jb.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateExpires && data.recordsets[0][0].DateExpires > new Date() && data.recordsets[0][0].DateExpires || void 0;
} | static async joinTeamDeniedUntil(member) {
/** @type {PlayerDbTypes.JoinTeamDeniedUntilRecordsets} */
const data = await db.query(/* sql */`
SELECT jb.DateExpires
FROM tblJoinBan jb
INNER JOIN tblPlayer p ON jb.PlayerId = p.PlayerId
WHERE p.DiscordId = @discordId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}});
return data && data.recordsets && data.recordsets[0] && data.recordsets[0][0] && data.recordsets[0][0].DateExpires && data.recordsets[0][0].DateExpires > new Date() && data.recordsets[0][0].DateExpires || void 0;
} |
JavaScript | static async requestTeam(member, team) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
IF @playerId IS NULL
BEGIN
INSERT INTO tblPlayer (DiscordId, Name)
VALUES (@discordId, @name)
SET @playerId = SCOPE_IDENTITY()
END
INSERT INTO tblRequest (TeamId, PlayerId)
VALUES (@teamId, @playerId)
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
name: {type: Db.VARCHAR(64), value: member.displayName},
teamId: {type: Db.INT, value: team.id}
});
} | static async requestTeam(member, team) {
await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
IF @playerId IS NULL
BEGIN
INSERT INTO tblPlayer (DiscordId, Name)
VALUES (@discordId, @name)
SET @playerId = SCOPE_IDENTITY()
END
INSERT INTO tblRequest (TeamId, PlayerId)
VALUES (@teamId, @playerId)
`, {
discordId: {type: Db.VARCHAR(24), value: member.id},
name: {type: Db.VARCHAR(64), value: member.displayName},
teamId: {type: Db.INT, value: team.id}
});
} |
JavaScript | static async unsetTwitchName(member) {
await db.query(/* sql */`
UPDATE tblPlayer SET TwitchName = NULL WHERE DiscordId = @discordId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}});
} | static async unsetTwitchName(member) {
await db.query(/* sql */`
UPDATE tblPlayer SET TwitchName = NULL WHERE DiscordId = @discordId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}});
} |
JavaScript | static async wasPreviousCaptainOrFounderOfTeam(member, team) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
SELECT TOP 1 1
FROM tblCaptainHistory
WHERE PlayerId = @playerId
AND TeamId = @teamId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}, teamId: {type: Db.INT, value: team.id}});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} | static async wasPreviousCaptainOrFounderOfTeam(member, team) {
/** @type {DbTypes.EmptyRecordsets} */
const data = await db.query(/* sql */`
DECLARE @playerId INT
SELECT @playerId = PlayerId FROM tblPlayer WHERE DiscordId = @discordId
SELECT TOP 1 1
FROM tblCaptainHistory
WHERE PlayerId = @playerId
AND TeamId = @teamId
`, {discordId: {type: Db.VARCHAR(24), value: member.id}, teamId: {type: Db.INT, value: team.id}});
return !!(data && data.recordsets && data.recordsets[0] && data.recordsets[0][0]);
} |
JavaScript | static async create(member) {
let data;
try {
data = await Db.create(member);
} catch (err) {
throw new Exception("There was a database error starting to create a team.", err);
}
const newTeam = new NewTeam(data);
try {
const currentTeam = await Team.getByPilot(member);
if (currentTeam) {
throw new Error("Pilot is already on a team.");
}
if (newTeam.channel) {
throw new Error("Channel already exists.");
}
await Discord.createChannel(newTeam.channelName, "text", [
{
id: Discord.id,
deny: ["VIEW_CHANNEL"]
}, {
id: member.id,
allow: ["VIEW_CHANNEL"]
}
], `${member.displayName} has started the process of creating a team.`);
await newTeam.channel.setTopic("New Team Creation - View the pinned post for the current status of the new team.");
await newTeam.updateChannel();
return newTeam;
} catch (err) {
throw new Exception("There was a critical Discord error starting a new team for the pilot. Please resolve this manually as soon as possible.", err);
}
} | static async create(member) {
let data;
try {
data = await Db.create(member);
} catch (err) {
throw new Exception("There was a database error starting to create a team.", err);
}
const newTeam = new NewTeam(data);
try {
const currentTeam = await Team.getByPilot(member);
if (currentTeam) {
throw new Error("Pilot is already on a team.");
}
if (newTeam.channel) {
throw new Error("Channel already exists.");
}
await Discord.createChannel(newTeam.channelName, "text", [
{
id: Discord.id,
deny: ["VIEW_CHANNEL"]
}, {
id: member.id,
allow: ["VIEW_CHANNEL"]
}
], `${member.displayName} has started the process of creating a team.`);
await newTeam.channel.setTopic("New Team Creation - View the pinned post for the current status of the new team.");
await newTeam.updateChannel();
return newTeam;
} catch (err) {
throw new Exception("There was a critical Discord error starting a new team for the pilot. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async delete(reason) {
try {
await Db.delete(this);
} catch (err) {
throw new Exception("There was a database error removing a new team creation record.", err);
}
try {
await this.channel.delete(reason);
} catch (err) {
throw new Exception("There was a critical Discord error removing a new team creation channel. Please resolve this manually as soon as possible.", err);
}
} | async delete(reason) {
try {
await Db.delete(this);
} catch (err) {
throw new Exception("There was a database error removing a new team creation record.", err);
}
try {
await this.channel.delete(reason);
} catch (err) {
throw new Exception("There was a critical Discord error removing a new team creation channel. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async updateChannel() {
const embed = Discord.messageEmbed({
title: "New Team Creation",
fields: [
{
name: "Team Name:",
value: this.name || "(unset)",
inline: true
},
{
name: "Team Tag:",
value: this.tag || "(unset)",
inline: true
}
]
});
const commands = [];
commands.push("`!name <name>` - Set your team's name. Required before you complete team creation.");
commands.push("`!tag <tag>` - Sets your tame tag, which is up to five letters or numbers that is considered to be a short form of your team name. Required before you complete team creation.");
commands.push("`!cancel` - Cancels team creation.");
commands.push("`!complete` - Completes the team creation process and creates your team on the OTL.");
embed.addField("Commands", commands.join("\n"));
const pinned = await this.channel.messages.fetchPinned(false);
if (pinned.size === 1) {
Discord.richEdit(pinned.first(), embed);
} else {
for (const message of pinned) {
await message[1].unpin();
}
const message = await Discord.richQueue(embed, this.channel);
await message.pin();
}
} | async updateChannel() {
const embed = Discord.messageEmbed({
title: "New Team Creation",
fields: [
{
name: "Team Name:",
value: this.name || "(unset)",
inline: true
},
{
name: "Team Tag:",
value: this.tag || "(unset)",
inline: true
}
]
});
const commands = [];
commands.push("`!name <name>` - Set your team's name. Required before you complete team creation.");
commands.push("`!tag <tag>` - Sets your tame tag, which is up to five letters or numbers that is considered to be a short form of your team name. Required before you complete team creation.");
commands.push("`!cancel` - Cancels team creation.");
commands.push("`!complete` - Completes the team creation process and creates your team on the OTL.");
embed.addField("Commands", commands.join("\n"));
const pinned = await this.channel.messages.fetchPinned(false);
if (pinned.size === 1) {
Discord.richEdit(pinned.first(), embed);
} else {
for (const message of pinned) {
await message[1].unpin();
}
const message = await Discord.richQueue(embed, this.channel);
await message.pin();
}
} |
JavaScript | static async create(challengingTeam, challengedTeam, options) {
const {adminCreated, teamSize, startNow} = options;
let {blueTeam, gameType, number} = options;
if (!gameType) {
gameType = "TA";
}
if (!number) {
number = 1;
}
let firstChallenge;
for (let count = 0; count < number; count++) {
let data;
try {
data = await Db.create(challengingTeam, challengedTeam, gameType, !!adminCreated, adminCreated ? challengingTeam : void 0, teamSize, startNow, blueTeam);
} catch (err) {
throw new Exception("There was a database error creating a challenge.", err);
}
const challenge = new Challenge({id: data.id, challengingTeam, challengedTeam});
try {
if (challenge.channel) {
throw new Error("Channel already exists.");
}
await Discord.createChannel(challenge.channelName, "text", [
{
id: Discord.id,
deny: ["VIEW_CHANNEL"]
}, {
id: challengingTeam.role.id,
allow: ["VIEW_CHANNEL"]
}, {
id: challengedTeam.role.id,
allow: ["VIEW_CHANNEL"]
}
], `${challengingTeam.name} challenged ${challengedTeam.name}.`);
if (Discord.challengesCategory.children.size >= 40) {
const oldPosition = Discord.challengesCategory.position;
await Discord.challengesCategory.setName("Old Challenges", "Exceeded 40 challenges.");
Discord.challengesCategory = /** @type {DiscordJs.CategoryChannel} */ (await Discord.createChannel("Challenges", "category", [], "Exceeded 40 challenges.")); // eslint-disable-line no-extra-parens
await Discord.challengesCategory.setPosition(oldPosition + 1);
}
await challenge.channel.setParent(Discord.challengesCategory, {lockPermissions: false});
await challenge.channel.setTopic(`${challengingTeam.name} vs ${challengedTeam.name} - View the pinned post for challenge information.`);
await challenge.updatePinnedPost();
let description;
if (gameType === "TA" && !teamSize) {
description = `**${data.homeMapTeam.tag}** is the home map team, so **${(data.homeMapTeam.tag === challengingTeam.tag ? challengedTeam : challengingTeam).tag}** must choose one of from one of **${data.homeMapTeam.tag}**'s home maps. To view the home maps, you must first agree to a team size.`;
} else {
description = `**${data.homeMapTeam.tag}** is the home map team, so **${(data.homeMapTeam.tag === challengingTeam.tag ? challengedTeam : challengingTeam).tag}** must choose from one of the following home maps:\n\n${(await data.homeMapTeam.getHomeMaps(Challenge.getGameTypeForHomes(gameType, teamSize))).map((map, index) => `${String.fromCharCode(97 + index)}) ${map}`).join("\n")}`;
}
await Discord.richQueue(Discord.messageEmbed({
title: "Challenge commands - Map",
description,
color: data.homeMapTeam.role.color,
fields: []
}), challenge.channel);
if (data.team1Penalized && data.team2Penalized) {
await Discord.queue("Penalties have been applied to both teams for this match. Neutral map selection is disabled.", challenge.channel);
} else if (data.team1Penalized) {
await Discord.queue(`A penalty has been applied to **${challengingTeam.tag}** for this match. Neutral map selection is disabled.`, challenge.channel);
} else if (data.team2Penalized) {
await Discord.queue(`A penalty has been applied to **${challengedTeam.tag}** for this match. Neutral map selection is disabled.`, challenge.channel);
} else if (!adminCreated) {
const matches = await Db.getMatchingNeutralsForChallenge(challenge);
if (matches && matches.length > 0) {
await Discord.queue(`Both teams have ${matches.length === 1 ? "a matching preferred neutral map!" : "matching preferred neutral maps!"}\n\n${matches.map((m) => `**${m}**`).join("\n")}`, challenge.channel);
}
}
} catch (err) {
throw new Exception("There was a critical Discord error creating a challenge. Please resolve this manually as soon as possible.", err);
}
if (!firstChallenge) {
firstChallenge = challenge;
}
if (!blueTeam) {
if (!challenge.details) {
await challenge.loadDetails();
}
blueTeam = challenge.details.blueTeam;
}
[challengingTeam, challengedTeam] = [challengedTeam, challengingTeam];
}
return firstChallenge;
} | static async create(challengingTeam, challengedTeam, options) {
const {adminCreated, teamSize, startNow} = options;
let {blueTeam, gameType, number} = options;
if (!gameType) {
gameType = "TA";
}
if (!number) {
number = 1;
}
let firstChallenge;
for (let count = 0; count < number; count++) {
let data;
try {
data = await Db.create(challengingTeam, challengedTeam, gameType, !!adminCreated, adminCreated ? challengingTeam : void 0, teamSize, startNow, blueTeam);
} catch (err) {
throw new Exception("There was a database error creating a challenge.", err);
}
const challenge = new Challenge({id: data.id, challengingTeam, challengedTeam});
try {
if (challenge.channel) {
throw new Error("Channel already exists.");
}
await Discord.createChannel(challenge.channelName, "text", [
{
id: Discord.id,
deny: ["VIEW_CHANNEL"]
}, {
id: challengingTeam.role.id,
allow: ["VIEW_CHANNEL"]
}, {
id: challengedTeam.role.id,
allow: ["VIEW_CHANNEL"]
}
], `${challengingTeam.name} challenged ${challengedTeam.name}.`);
if (Discord.challengesCategory.children.size >= 40) {
const oldPosition = Discord.challengesCategory.position;
await Discord.challengesCategory.setName("Old Challenges", "Exceeded 40 challenges.");
Discord.challengesCategory = /** @type {DiscordJs.CategoryChannel} */ (await Discord.createChannel("Challenges", "category", [], "Exceeded 40 challenges.")); // eslint-disable-line no-extra-parens
await Discord.challengesCategory.setPosition(oldPosition + 1);
}
await challenge.channel.setParent(Discord.challengesCategory, {lockPermissions: false});
await challenge.channel.setTopic(`${challengingTeam.name} vs ${challengedTeam.name} - View the pinned post for challenge information.`);
await challenge.updatePinnedPost();
let description;
if (gameType === "TA" && !teamSize) {
description = `**${data.homeMapTeam.tag}** is the home map team, so **${(data.homeMapTeam.tag === challengingTeam.tag ? challengedTeam : challengingTeam).tag}** must choose one of from one of **${data.homeMapTeam.tag}**'s home maps. To view the home maps, you must first agree to a team size.`;
} else {
description = `**${data.homeMapTeam.tag}** is the home map team, so **${(data.homeMapTeam.tag === challengingTeam.tag ? challengedTeam : challengingTeam).tag}** must choose from one of the following home maps:\n\n${(await data.homeMapTeam.getHomeMaps(Challenge.getGameTypeForHomes(gameType, teamSize))).map((map, index) => `${String.fromCharCode(97 + index)}) ${map}`).join("\n")}`;
}
await Discord.richQueue(Discord.messageEmbed({
title: "Challenge commands - Map",
description,
color: data.homeMapTeam.role.color,
fields: []
}), challenge.channel);
if (data.team1Penalized && data.team2Penalized) {
await Discord.queue("Penalties have been applied to both teams for this match. Neutral map selection is disabled.", challenge.channel);
} else if (data.team1Penalized) {
await Discord.queue(`A penalty has been applied to **${challengingTeam.tag}** for this match. Neutral map selection is disabled.`, challenge.channel);
} else if (data.team2Penalized) {
await Discord.queue(`A penalty has been applied to **${challengedTeam.tag}** for this match. Neutral map selection is disabled.`, challenge.channel);
} else if (!adminCreated) {
const matches = await Db.getMatchingNeutralsForChallenge(challenge);
if (matches && matches.length > 0) {
await Discord.queue(`Both teams have ${matches.length === 1 ? "a matching preferred neutral map!" : "matching preferred neutral maps!"}\n\n${matches.map((m) => `**${m}**`).join("\n")}`, challenge.channel);
}
}
} catch (err) {
throw new Exception("There was a critical Discord error creating a challenge. Please resolve this manually as soon as possible.", err);
}
if (!firstChallenge) {
firstChallenge = challenge;
}
if (!blueTeam) {
if (!challenge.details) {
await challenge.loadDetails();
}
blueTeam = challenge.details.blueTeam;
}
[challengingTeam, challengedTeam] = [challengedTeam, challengingTeam];
}
return firstChallenge;
} |
JavaScript | async addStatCTF(team, pilot, captures, pickups, carrierKills, returns, kills, assists, deaths) {
try {
await Db.addStatCTF(this, team, pilot, captures, pickups, carrierKills, returns, kills, assists, deaths);
} catch (err) {
throw new Exception("There was a database error adding a stat to a CTF challenge.", err);
}
await Discord.queue(`Added stats for ${pilot}: ${captures} C/${pickups} P, ${carrierKills} CK, ${returns} R, ${((kills + assists) / Math.max(deaths, 1)).toFixed(3)} KDA (${kills} K, ${assists} A, ${deaths} D)`, this.channel);
await this.updatePinnedPost();
} | async addStatCTF(team, pilot, captures, pickups, carrierKills, returns, kills, assists, deaths) {
try {
await Db.addStatCTF(this, team, pilot, captures, pickups, carrierKills, returns, kills, assists, deaths);
} catch (err) {
throw new Exception("There was a database error adding a stat to a CTF challenge.", err);
}
await Discord.queue(`Added stats for ${pilot}: ${captures} C/${pickups} P, ${carrierKills} CK, ${returns} R, ${((kills + assists) / Math.max(deaths, 1)).toFixed(3)} KDA (${kills} K, ${assists} A, ${deaths} D)`, this.channel);
await this.updatePinnedPost();
} |
JavaScript | async addStatTA(team, pilot, kills, assists, deaths) {
try {
await Db.addStatTA(this, team, pilot, kills, assists, deaths);
} catch (err) {
throw new Exception("There was a database error adding a stat to a TA challenge.", err);
}
await Discord.queue(`Added stats for ${pilot}: ${((kills + assists) / Math.max(deaths, 1)).toFixed(3)} KDA (${kills} K, ${assists} A, ${deaths} D)`, this.channel);
await this.updatePinnedPost();
} | async addStatTA(team, pilot, kills, assists, deaths) {
try {
await Db.addStatTA(this, team, pilot, kills, assists, deaths);
} catch (err) {
throw new Exception("There was a database error adding a stat to a TA challenge.", err);
}
await Discord.queue(`Added stats for ${pilot}: ${((kills + assists) / Math.max(deaths, 1)).toFixed(3)} KDA (${kills} K, ${assists} A, ${deaths} D)`, this.channel);
await this.updatePinnedPost();
} |
JavaScript | async addStreamer(member, twitchName) {
try {
await Db.addStreamer(this, member);
} catch (err) {
throw new Exception("There was a database error adding a pilot as a streamer for a challenge.", err);
}
try {
await Discord.queue(`${member} has been setup to stream this match at https://twitch.tv/${twitchName}.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error adding a pilot as a streamer for a challenge. Please resolve this manually as soon as possible.", err);
}
} | async addStreamer(member, twitchName) {
try {
await Db.addStreamer(this, member);
} catch (err) {
throw new Exception("There was a database error adding a pilot as a streamer for a challenge.", err);
}
try {
await Discord.queue(`${member} has been setup to stream this match at https://twitch.tv/${twitchName}.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error adding a pilot as a streamer for a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async clearStats(member) {
try {
await Db.clearStats(this);
} catch (err) {
throw new Exception("There was a database error clearing the stats for a challenge.", err);
}
await Discord.queue(`${member}, all stats have been cleared for this match.`, this.channel);
} | async clearStats(member) {
try {
await Db.clearStats(this);
} catch (err) {
throw new Exception("There was a database error clearing the stats for a challenge.", err);
}
await Discord.queue(`${member}, all stats have been cleared for this match.`, this.channel);
} |
JavaScript | async clearTime(member) {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.setTime(this);
} catch (err) {
throw new Exception("There was a database error setting the time for a challenge.", err);
}
this.details.matchTime = void 0;
this.details.suggestedTime = void 0;
this.details.suggestedTimeTeam = void 0;
this.setNotifyMatchMissed();
this.setNotifyMatchStarting();
try {
await Discord.queue(`${member} has cleared the match time for this match.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error setting the time for a challenge. Please resolve this manually as soon as possible.", err);
}
} | async clearTime(member) {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.setTime(this);
} catch (err) {
throw new Exception("There was a database error setting the time for a challenge.", err);
}
this.details.matchTime = void 0;
this.details.suggestedTime = void 0;
this.details.suggestedTimeTeam = void 0;
this.setNotifyMatchMissed();
this.setNotifyMatchStarting();
try {
await Discord.queue(`${member} has cleared the match time for this match.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error setting the time for a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async clock(team) {
if (!this.details) {
await this.loadDetails();
}
let dates;
try {
dates = await Db.clock(team, this);
} catch (err) {
throw new Exception("There was a database error clocking a challenge.", err);
}
this.details.clockTeam = team;
this.details.dateClocked = dates.clocked;
this.details.dateClockDeadline = dates.clockDeadline;
this.setNotifyClockExpired(dates.clockDeadline);
try {
await Discord.queue(`**${team.name}** has put this challenge on the clock! Both teams have 28 days to get this match scheduled. If the match is not scheduled within that time, this match will be adjudicated by an admin to determine if penalties need to be assessed.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error clocking a challenge. Please resolve this manually as soon as possible.", err);
}
} | async clock(team) {
if (!this.details) {
await this.loadDetails();
}
let dates;
try {
dates = await Db.clock(team, this);
} catch (err) {
throw new Exception("There was a database error clocking a challenge.", err);
}
this.details.clockTeam = team;
this.details.dateClocked = dates.clocked;
this.details.dateClockDeadline = dates.clockDeadline;
this.setNotifyClockExpired(dates.clockDeadline);
try {
await Discord.queue(`**${team.name}** has put this challenge on the clock! Both teams have 28 days to get this match scheduled. If the match is not scheduled within that time, this match will be adjudicated by an admin to determine if penalties need to be assessed.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error clocking a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async confirmGameType() {
if (!this.details) {
await this.loadDetails();
}
let homes;
try {
homes = await Db.confirmGameType(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested game type for a challenge.", err);
}
this.details.gameType = this.details.suggestedGameType;
this.details.suggestedGameType = void 0;
this.details.suggestedGameTypeTeam = void 0;
try {
if (homes.length === 0) {
await Discord.queue(`The game for this match has been set to **${Challenge.getGameTypeName(this.details.gameType)}**, so **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengedTeam : this.challengingTeam).tag}** must choose from one of **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengingTeam : this.challengedTeam).tag}**'s home maps. To view the home maps, you must first agree to a team size.`, this.channel);
} else {
await Discord.queue(`The game for this match has been set to **${Challenge.getGameTypeName(this.details.gameType)}**, so **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengedTeam : this.challengingTeam).tag}** must choose from one of the following home maps:\n\n${homes.map((map, index) => `${String.fromCharCode(97 + index)}) ${map}`).join("\n")}`, this.channel);
}
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested game type for a challenge. Please resolve this manually as soon as possible.", err);
}
} | async confirmGameType() {
if (!this.details) {
await this.loadDetails();
}
let homes;
try {
homes = await Db.confirmGameType(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested game type for a challenge.", err);
}
this.details.gameType = this.details.suggestedGameType;
this.details.suggestedGameType = void 0;
this.details.suggestedGameTypeTeam = void 0;
try {
if (homes.length === 0) {
await Discord.queue(`The game for this match has been set to **${Challenge.getGameTypeName(this.details.gameType)}**, so **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengedTeam : this.challengingTeam).tag}** must choose from one of **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengingTeam : this.challengedTeam).tag}**'s home maps. To view the home maps, you must first agree to a team size.`, this.channel);
} else {
await Discord.queue(`The game for this match has been set to **${Challenge.getGameTypeName(this.details.gameType)}**, so **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengedTeam : this.challengingTeam).tag}** must choose from one of the following home maps:\n\n${homes.map((map, index) => `${String.fromCharCode(97 + index)}) ${map}`).join("\n")}`, this.channel);
}
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested game type for a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async confirmMap() {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.confirmMap(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested neutral map for a challenge.", err);
}
this.details.map = this.details.suggestedMap;
this.details.usingHomeMapTeam = false;
this.details.suggestedMap = void 0;
this.details.suggestedMapTeam = void 0;
try {
await Discord.queue(`The map for this match has been set to the neutral map of **${this.details.map}**.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested neutral map for a challenge. Please resolve this manually as soon as possible.", err);
}
} | async confirmMap() {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.confirmMap(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested neutral map for a challenge.", err);
}
this.details.map = this.details.suggestedMap;
this.details.usingHomeMapTeam = false;
this.details.suggestedMap = void 0;
this.details.suggestedMapTeam = void 0;
try {
await Discord.queue(`The map for this match has been set to the neutral map of **${this.details.map}**.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested neutral map for a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async confirmMatch() {
if (!this.details) {
await this.loadDetails();
}
try {
this.details.dateConfirmed = await Db.setConfirmed(this);
} catch (err) {
throw new Exception("There was a database error confirming a reported match.", err);
}
this.setNotifyClockExpired();
this.setNotifyMatchMissed();
this.setNotifyMatchStarting();
try {
const embed = Discord.messageEmbed({
title: "Match Confirmed",
fields: [
{
name: "Post the game stats",
value: "Remember, OTL matches are only official with pilot statistics from the tracker at https://tracker.otl.gg or from the .ssl file for the game from the server."
},
{
name: "This channel is now closed",
value: "No further match-related commands will be accepted. If you need to adjust anything in this match, please notify an admin immediately. This channel will be removed once the stats have been posted."
}
]
});
const winningScore = Math.max(this.details.challengingTeamScore, this.details.challengedTeamScore),
losingScore = Math.min(this.details.challengingTeamScore, this.details.challengedTeamScore),
winningTeam = winningScore === this.details.challengingTeamScore ? this.challengingTeam : this.challengedTeam;
if (winningScore === losingScore) {
embed.setDescription(`This match has been confirmed as a **tie**, **${winningScore}** to **${losingScore}**. Interested in playing another right now? Use the \`!rematch\` command!`);
} else {
embed.setDescription(`This match has been confirmed as a win for **${winningTeam.name}** by the score of **${winningScore}** to **${losingScore}**. Interested in playing another right now? Use the \`!rematch\` command!`);
embed.setColor(winningTeam.role.color);
}
await Discord.richQueue(embed, this.channel);
await Discord.queue(`The match at ${this.channel} has been confirmed. Please add stats and close the channel.`, Discord.alertsChannel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a reported match. Please resolve this manually as soon as possible.", err);
}
} | async confirmMatch() {
if (!this.details) {
await this.loadDetails();
}
try {
this.details.dateConfirmed = await Db.setConfirmed(this);
} catch (err) {
throw new Exception("There was a database error confirming a reported match.", err);
}
this.setNotifyClockExpired();
this.setNotifyMatchMissed();
this.setNotifyMatchStarting();
try {
const embed = Discord.messageEmbed({
title: "Match Confirmed",
fields: [
{
name: "Post the game stats",
value: "Remember, OTL matches are only official with pilot statistics from the tracker at https://tracker.otl.gg or from the .ssl file for the game from the server."
},
{
name: "This channel is now closed",
value: "No further match-related commands will be accepted. If you need to adjust anything in this match, please notify an admin immediately. This channel will be removed once the stats have been posted."
}
]
});
const winningScore = Math.max(this.details.challengingTeamScore, this.details.challengedTeamScore),
losingScore = Math.min(this.details.challengingTeamScore, this.details.challengedTeamScore),
winningTeam = winningScore === this.details.challengingTeamScore ? this.challengingTeam : this.challengedTeam;
if (winningScore === losingScore) {
embed.setDescription(`This match has been confirmed as a **tie**, **${winningScore}** to **${losingScore}**. Interested in playing another right now? Use the \`!rematch\` command!`);
} else {
embed.setDescription(`This match has been confirmed as a win for **${winningTeam.name}** by the score of **${winningScore}** to **${losingScore}**. Interested in playing another right now? Use the \`!rematch\` command!`);
embed.setColor(winningTeam.role.color);
}
await Discord.richQueue(embed, this.channel);
await Discord.queue(`The match at ${this.channel} has been confirmed. Please add stats and close the channel.`, Discord.alertsChannel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a reported match. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async confirmTeamSize() {
if (!this.details) {
await this.loadDetails();
}
let homes;
try {
homes = await Db.confirmTeamSize(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested team size for a challenge.", err);
}
this.details.teamSize = this.details.suggestedTeamSize;
this.details.suggestedTeamSize = void 0;
this.details.suggestedTeamSizeTeam = void 0;
try {
if (this.details.gameType === "TA" && (!this.details.map || homes.indexOf(this.details.map) === -1)) {
await Discord.queue(`The team size for this match has been set to **${this.details.teamSize}v${this.details.teamSize}**. Either team may suggest changing this at any time with the \`!suggestteamsize\` command. **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengedTeam : this.challengingTeam).tag}** must now choose from one of the following home maps:\n\n${homes.map((map, index) => `${String.fromCharCode(97 + index)}) ${map}`).join("\n")}`, this.channel);
} else {
await Discord.queue(`The team size for this match has been set to **${this.details.teamSize}v${this.details.teamSize}**. Either team may suggest changing this at any time with the \`!suggestteamsize\` command.`, this.channel);
}
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested team size for a challenge. Please resolve this manually as soon as possible.", err);
}
} | async confirmTeamSize() {
if (!this.details) {
await this.loadDetails();
}
let homes;
try {
homes = await Db.confirmTeamSize(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested team size for a challenge.", err);
}
this.details.teamSize = this.details.suggestedTeamSize;
this.details.suggestedTeamSize = void 0;
this.details.suggestedTeamSizeTeam = void 0;
try {
if (this.details.gameType === "TA" && (!this.details.map || homes.indexOf(this.details.map) === -1)) {
await Discord.queue(`The team size for this match has been set to **${this.details.teamSize}v${this.details.teamSize}**. Either team may suggest changing this at any time with the \`!suggestteamsize\` command. **${(this.details.homeMapTeam.tag === this.challengingTeam.tag ? this.challengedTeam : this.challengingTeam).tag}** must now choose from one of the following home maps:\n\n${homes.map((map, index) => `${String.fromCharCode(97 + index)}) ${map}`).join("\n")}`, this.channel);
} else {
await Discord.queue(`The team size for this match has been set to **${this.details.teamSize}v${this.details.teamSize}**. Either team may suggest changing this at any time with the \`!suggestteamsize\` command.`, this.channel);
}
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested team size for a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async confirmTime() {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.confirmTime(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested time for a challenge.", err);
}
this.details.matchTime = this.details.suggestedTime;
this.details.suggestedTime = void 0;
this.details.suggestedTimeTeam = void 0;
this.setNotifyMatchMissed(new Date(this.details.matchTime.getTime() + 3600000));
this.setNotifyMatchStarting(new Date(this.details.matchTime.getTime() - 1800000));
try {
const times = {};
for (const member of this.channel.members.values()) {
const timezone = await member.getTimezone(),
yearWithTimezone = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
for (const team of [this.challengingTeam, this.challengedTeam]) {
const timezone = await team.getTimezone(),
yearWithTimezone = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
const sortedTimes = Object.keys(times).map((tz) => ({timezone: tz, displayTime: times[tz], value: new Date(times[tz])})).sort((a, b) => {
if (a.value.getTime() !== b.value.getTime()) {
return b.value.getTime() - a.value.getTime();
}
return a.timezone.localeCompare(b.timezone);
});
await Discord.richQueue(Discord.messageEmbed({
description: "The time for this match has been set.",
fields: sortedTimes.map((t) => ({name: t.timezone, value: t.displayTime}))
}), this.channel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.challengingTeam.name} vs ${this.challengedTeam.name}`,
description: `This match is scheduled for ${this.details.matchTime.toLocaleString("en-US", {timeZone: settings.defaultTimezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", timeZoneName: "short"})}`,
fields: [
{
name: "Match Time",
value: `Use \`!matchtime ${this.id}\` to get the time of this match in your own time zone, or \`!countdown ${this.id}\` to get the amount of time remaining until the start of the match.`
}, {
name: "Casting",
value: `Use \`!cast ${this.id}\` if you wish to cast this match.`
}
]
}), Discord.scheduledMatchesChannel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested time for a challenge. Please resolve this manually as soon as possible.", err);
}
} | async confirmTime() {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.confirmTime(this);
} catch (err) {
throw new Exception("There was a database error confirming a suggested time for a challenge.", err);
}
this.details.matchTime = this.details.suggestedTime;
this.details.suggestedTime = void 0;
this.details.suggestedTimeTeam = void 0;
this.setNotifyMatchMissed(new Date(this.details.matchTime.getTime() + 3600000));
this.setNotifyMatchStarting(new Date(this.details.matchTime.getTime() - 1800000));
try {
const times = {};
for (const member of this.channel.members.values()) {
const timezone = await member.getTimezone(),
yearWithTimezone = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
for (const team of [this.challengingTeam, this.challengedTeam]) {
const timezone = await team.getTimezone(),
yearWithTimezone = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, year: "numeric", timeZoneName: "long"});
if (timezoneParse.test(yearWithTimezone)) {
const {groups: {timezoneName}} = timezoneParse.exec(yearWithTimezone);
if (timezoneName) {
times[timezoneName] = this.details.matchTime.toLocaleString("en-US", {timeZone: timezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"});
}
}
}
const sortedTimes = Object.keys(times).map((tz) => ({timezone: tz, displayTime: times[tz], value: new Date(times[tz])})).sort((a, b) => {
if (a.value.getTime() !== b.value.getTime()) {
return b.value.getTime() - a.value.getTime();
}
return a.timezone.localeCompare(b.timezone);
});
await Discord.richQueue(Discord.messageEmbed({
description: "The time for this match has been set.",
fields: sortedTimes.map((t) => ({name: t.timezone, value: t.displayTime}))
}), this.channel);
await Discord.richQueue(Discord.messageEmbed({
title: `${this.challengingTeam.name} vs ${this.challengedTeam.name}`,
description: `This match is scheduled for ${this.details.matchTime.toLocaleString("en-US", {timeZone: settings.defaultTimezone, weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", timeZoneName: "short"})}`,
fields: [
{
name: "Match Time",
value: `Use \`!matchtime ${this.id}\` to get the time of this match in your own time zone, or \`!countdown ${this.id}\` to get the amount of time remaining until the start of the match.`
}, {
name: "Casting",
value: `Use \`!cast ${this.id}\` if you wish to cast this match.`
}
]
}), Discord.scheduledMatchesChannel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error confirming a suggested time for a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | async createRematch(team) {
try {
await Db.setRematched(this);
} catch (err) {
throw new Exception("There was a database error marking a challenge as rematched.", err);
}
const challenge = await Challenge.create(
team.id === this.challengingTeam.id ? this.challengedTeam : this.challengingTeam,
team,
{
gameType: this.details.gameType,
adminCreated: false,
teamSize: this.details.teamSize,
startNow: true,
blueTeam: this.details.blueTeam
}
);
challenge.setNotifyMatchMissed(new Date(new Date().getTime() + 3600000));
challenge.setNotifyMatchStarting(new Date(new Date().getTime() + 5000));
await Discord.queue(`The rematch has been created! Visit ${challenge.channel} to get started.`, this.channel);
} | async createRematch(team) {
try {
await Db.setRematched(this);
} catch (err) {
throw new Exception("There was a database error marking a challenge as rematched.", err);
}
const challenge = await Challenge.create(
team.id === this.challengingTeam.id ? this.challengedTeam : this.challengingTeam,
team,
{
gameType: this.details.gameType,
adminCreated: false,
teamSize: this.details.teamSize,
startNow: true,
blueTeam: this.details.blueTeam
}
);
challenge.setNotifyMatchMissed(new Date(new Date().getTime() + 3600000));
challenge.setNotifyMatchStarting(new Date(new Date().getTime() + 5000));
await Discord.queue(`The rematch has been created! Visit ${challenge.channel} to get started.`, this.channel);
} |
JavaScript | async isDuplicateCommand(member, message) {
if (lastCommand[this.channelName] === message) {
await Discord.queue(`Sorry, ${member}, but this command is a duplicate of the last command issued in this channel.`, this.channel);
return true;
}
lastCommand[this.channelName] = message;
return false;
} | async isDuplicateCommand(member, message) {
if (lastCommand[this.channelName] === message) {
await Discord.queue(`Sorry, ${member}, but this command is a duplicate of the last command issued in this channel.`, this.channel);
return true;
}
lastCommand[this.channelName] = message;
return false;
} |
JavaScript | async loadDetails() {
let details;
try {
details = await Db.getDetails(this);
} catch (err) {
throw new Exception("There was a database error loading details for a challenge.", err);
}
this.details = {
title: details.title,
orangeTeam: details.orangeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam,
blueTeam: details.blueTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam,
map: details.map,
teamSize: details.teamSize,
matchTime: details.matchTime,
postseason: details.postseason,
homeMapTeam: details.homeMapTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam,
adminCreated: details.adminCreated,
usingHomeMapTeam: details.usingHomeMapTeam,
challengingTeamPenalized: details.challengingTeamPenalized,
challengedTeamPenalized: details.challengedTeamPenalized,
suggestedMap: details.suggestedMap,
suggestedMapTeam: details.suggestedMapTeamId ? details.suggestedMapTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
suggestedTeamSize: details.suggestedTeamSize,
suggestedTeamSizeTeam: details.suggestedTeamSizeTeamId ? details.suggestedTeamSizeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
suggestedTime: details.suggestedTime,
suggestedTimeTeam: details.suggestedTimeTeamId ? details.suggestedTimeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
reportingTeam: details.reportingTeamId ? details.reportingTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
challengingTeamScore: details.challengingTeamScore,
challengedTeamScore: details.challengedTeamScore,
caster: Discord.findGuildMemberById(details.casterDiscordId),
dateAdded: details.dateAdded,
dateClocked: details.dateClocked,
clockTeam: details.clockTeamId ? details.clockTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
dateClockDeadline: details.dateClockDeadline,
dateClockDeadlineNotified: details.dateClockDeadlineNotified,
dateReported: details.dateReported,
dateConfirmed: details.dateConfirmed,
dateClosed: details.dateClosed,
dateRematchRequested: details.dateRematchRequested,
rematchTeam: details.rematchTeamId ? details.rematchTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
dateRematched: details.dateRematched,
dateVoided: details.dateVoided,
overtimePeriods: details.overtimePeriods,
homeMaps: details.homeMaps,
vod: details.vod,
ratingChange: details.ratingChange,
challengingTeamRating: details.challengingTeamRating,
challengedTeamRating: details.challengedTeamRating,
gameType: details.gameType,
suggestedGameType: details.suggestedGameType,
suggestedGameTypeTeam: details.suggestedGameTypeTeamId ? details.suggestedGameTypeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0
};
} | async loadDetails() {
let details;
try {
details = await Db.getDetails(this);
} catch (err) {
throw new Exception("There was a database error loading details for a challenge.", err);
}
this.details = {
title: details.title,
orangeTeam: details.orangeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam,
blueTeam: details.blueTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam,
map: details.map,
teamSize: details.teamSize,
matchTime: details.matchTime,
postseason: details.postseason,
homeMapTeam: details.homeMapTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam,
adminCreated: details.adminCreated,
usingHomeMapTeam: details.usingHomeMapTeam,
challengingTeamPenalized: details.challengingTeamPenalized,
challengedTeamPenalized: details.challengedTeamPenalized,
suggestedMap: details.suggestedMap,
suggestedMapTeam: details.suggestedMapTeamId ? details.suggestedMapTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
suggestedTeamSize: details.suggestedTeamSize,
suggestedTeamSizeTeam: details.suggestedTeamSizeTeamId ? details.suggestedTeamSizeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
suggestedTime: details.suggestedTime,
suggestedTimeTeam: details.suggestedTimeTeamId ? details.suggestedTimeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
reportingTeam: details.reportingTeamId ? details.reportingTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
challengingTeamScore: details.challengingTeamScore,
challengedTeamScore: details.challengedTeamScore,
caster: Discord.findGuildMemberById(details.casterDiscordId),
dateAdded: details.dateAdded,
dateClocked: details.dateClocked,
clockTeam: details.clockTeamId ? details.clockTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
dateClockDeadline: details.dateClockDeadline,
dateClockDeadlineNotified: details.dateClockDeadlineNotified,
dateReported: details.dateReported,
dateConfirmed: details.dateConfirmed,
dateClosed: details.dateClosed,
dateRematchRequested: details.dateRematchRequested,
rematchTeam: details.rematchTeamId ? details.rematchTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0,
dateRematched: details.dateRematched,
dateVoided: details.dateVoided,
overtimePeriods: details.overtimePeriods,
homeMaps: details.homeMaps,
vod: details.vod,
ratingChange: details.ratingChange,
challengingTeamRating: details.challengingTeamRating,
challengedTeamRating: details.challengedTeamRating,
gameType: details.gameType,
suggestedGameType: details.suggestedGameType,
suggestedGameTypeTeam: details.suggestedGameTypeTeamId ? details.suggestedGameTypeTeamId === this.challengingTeam.id ? this.challengingTeam : this.challengedTeam : void 0
};
} |
JavaScript | async lock(member) {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.setLock(this, true);
} catch (err) {
throw new Exception("There was a database error locking a challenge.", err);
}
this.details.adminCreated = true;
try {
await Discord.queue(`This challenge has been locked by ${member}. Match parameters can no longer be set.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error locking a challenge. Please resolve this manually as soon as possible.", err);
}
} | async lock(member) {
if (!this.details) {
await this.loadDetails();
}
try {
await Db.setLock(this, true);
} catch (err) {
throw new Exception("There was a database error locking a challenge.", err);
}
this.details.adminCreated = true;
try {
await Discord.queue(`This challenge has been locked by ${member}. Match parameters can no longer be set.`, this.channel);
await this.updatePinnedPost();
} catch (err) {
throw new Exception("There was a critical Discord error locking a challenge. Please resolve this manually as soon as possible.", err);
}
} |
JavaScript | static async notify() {
let notifications;
try {
notifications = await Db.getNotifications();
} catch (err) {
Log.exception("There was an error getting challenge notifications.", err);
return;
}
try {
for (const challengeData of notifications.expiredClocks) {
clockExpiredJobs[challengeData.challengeId] = schedule.scheduleJob(new Date(Math.max(challengeData.dateClockDeadline.getTime(), new Date().getTime() + 5000)), Challenge.notifyClockExpired.bind(null, challengeData.challengeId));
}
for (const challengeData of notifications.startingMatches) {
upcomingMatchJobs[challengeData.challengeId] = schedule.scheduleJob(new Date(Math.max(challengeData.matchTime.getTime() - 1800000, new Date().getTime() + 5000)), Challenge.notifyMatchStarting.bind(null, challengeData.challengeId));
}
for (const challengeData of notifications.missedMatches) {
missedMatchJobs[challengeData.challengeId] = schedule.scheduleJob(new Date(Math.max(challengeData.matchTime.getTime() + 3600000, new Date().getTime() + 5000)), Challenge.notifyMatchMissed.bind(null, challengeData.challengeId));
}
} catch (err) {
Log.exception("There was an error issuing challenge notifications.", err);
}
} | static async notify() {
let notifications;
try {
notifications = await Db.getNotifications();
} catch (err) {
Log.exception("There was an error getting challenge notifications.", err);
return;
}
try {
for (const challengeData of notifications.expiredClocks) {
clockExpiredJobs[challengeData.challengeId] = schedule.scheduleJob(new Date(Math.max(challengeData.dateClockDeadline.getTime(), new Date().getTime() + 5000)), Challenge.notifyClockExpired.bind(null, challengeData.challengeId));
}
for (const challengeData of notifications.startingMatches) {
upcomingMatchJobs[challengeData.challengeId] = schedule.scheduleJob(new Date(Math.max(challengeData.matchTime.getTime() - 1800000, new Date().getTime() + 5000)), Challenge.notifyMatchStarting.bind(null, challengeData.challengeId));
}
for (const challengeData of notifications.missedMatches) {
missedMatchJobs[challengeData.challengeId] = schedule.scheduleJob(new Date(Math.max(challengeData.matchTime.getTime() + 3600000, new Date().getTime() + 5000)), Challenge.notifyMatchMissed.bind(null, challengeData.challengeId));
}
} catch (err) {
Log.exception("There was an error issuing challenge notifications.", err);
}
} |
JavaScript | static async notifyClockExpired(challengeId) {
let challenge;
try {
challenge = await Challenge.getById(challengeId);
} catch (err) {
throw new Exception("There was an error notifying that a challenge clock expired.", err);
}
try {
await Db.setNotifyClockExpired(challenge);
} catch (err) {
throw new Exception("There was a database error notifying a clock expired for a challenge.", err);
}
try {
await Discord.queue(`The clock deadline has been passed in ${challenge.channel}.`, Discord.alertsChannel);
} catch (err) {
throw new Exception("There was a critical Discord error notifying a clock expired for a challenge. Please resolve this manually as soon as possible.", err);
}
challenge.setNotifyClockExpired();
} | static async notifyClockExpired(challengeId) {
let challenge;
try {
challenge = await Challenge.getById(challengeId);
} catch (err) {
throw new Exception("There was an error notifying that a challenge clock expired.", err);
}
try {
await Db.setNotifyClockExpired(challenge);
} catch (err) {
throw new Exception("There was a database error notifying a clock expired for a challenge.", err);
}
try {
await Discord.queue(`The clock deadline has been passed in ${challenge.channel}.`, Discord.alertsChannel);
} catch (err) {
throw new Exception("There was a critical Discord error notifying a clock expired for a challenge. Please resolve this manually as soon as possible.", err);
}
challenge.setNotifyClockExpired();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.