Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Hosted Tournaments: Check chalonge link properly #78

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ export class Client {
const demoted = messageArguments.message.substr(6).split(" was demoted to Room regular user by")[0];
if (Tools.toId(demoted) === lastOutgoingMessage.deauthedUserid) this.websocket.clearLastOutgoingMessage(now);
}
} else if (lastOutgoingMessage.type === 'hidetext') {
if (messageArguments.message.endsWith(' messages were cleared from ' + room.title +
'by' + Users.self.name + '.' + (lastOutgoingMessage.hideReason ? ' (' +
lastOutgoingMessage.hideReason + ')' : '')))
this.websocket.clearLastOutgoingMessage(now);
} else if (lastOutgoingMessage.type === 'warn') {
if (messageArguments.message.endsWith(' was warned by ' + Users.self.name + ". (" +
lastOutgoingMessage.warnReason + ")")) {
Expand Down Expand Up @@ -2184,6 +2189,7 @@ export class Client {
if (room.approvedUserHostedTournaments[i].urls.includes(link)) {
if (!authOrTHC && room.approvedUserHostedTournaments[i].hostId !== user.id) {
room.warn(user, "Please do not post links to other hosts' tournaments");
room.hidetext(user.id, true, 1, "");
}
break outer;
}
Expand Down Expand Up @@ -2215,6 +2221,11 @@ export class Client {
room.approvedUserHostedTournaments[link] = {
approvalStatus: 'approved',
bracketUrl: bracketUrl ? link : "",
canWarn: {
changesRequested: false,
awaitingApproval: false,
approvalRequested: false,
},
hostName: user.name,
hostId: user.id,
reviewer: user.id,
Expand All @@ -2229,21 +2240,61 @@ export class Client {
if (room.newUserHostedTournaments[i].urls.includes(link)) {
if (room.newUserHostedTournaments[i].hostId !== user.id) {
room.warn(user, "Please do not post links to other hosts' tournaments");
room.hidetext(user.id, true, 1, "");
} else if (room.newUserHostedTournaments[i].approvalStatus === 'changes-requested') {
let name = room.newUserHostedTournaments[i].reviewer;
const reviewer = Users.get(name);
if (reviewer) name = reviewer.name;
room.warn(user, name + " has requested changes for your tournament and you " +
"must wait for them to be approved");
} else {
room.warn(user, "You must wait for a staff member to approve your tournament");
if (room.newUserHostedTournaments[i].canWarn.changesRequested) {
room.warn(user, name + " has requested changes for your tournament and you " +
"must wait for them to be approved");
room.hidetext(user.id, true, 1, "");
} else {
room.hidetext(user.id, true, 1, name + " has requested changes " +
"for your tournament and you must wait for them to be approved");
room.newUserHostedTournaments[i].canWarn.changesRequested = true;
}
} else if (room.newUserHostedTournaments[link].canWarn.approvalRequested) {
room.warn(user, "Your tournament must be approved by a staff member");
room.hidetext(user.id, true, 1, "");
user.say("Your tournament must be approved by a staff member");
user.say('Use the command ``' + Config.commandCharacter + 'gettourapproval ' + room.id +
', __bracket link__, __signup link__`` to get your' +
'tournament approved (insert your actual links).');
} else {
if (room.newUserHostedTournaments[i].canWarn.awaitingApproval) {
room.warn(user, "You must wait for a staff member to approve your tournament");
room.hidetext(user.id, true, 1, "");
} else {
room.hidetext(user.id, true, 1, "You must wait for a staff member to approve your tournament");
room.newUserHostedTournaments[i].canWarn.awaitingApproval = true;
}
}
break outer;
}
}
room.warn(user, "Your tournament must be approved by a staff member");
user.say('Use the command ``' + Config.commandCharacter + 'gettourapproval ' + room.id + ', __bracket link__, ' +
'__signup link__`` to get your tournament approved (insert your actual links).');
if (!room.newUserHostedTournaments) room.newUserHostedTournaments = {};

const bracketUrl = Tools.isChallongeBracketUrl(link);
room.newUserHostedTournaments[link] = {
approvalStatus: '',
bracketUrl: bracketUrl ? link : "",
canWarn: {
changesRequested: false,
awaitingApproval: false,
approvalRequested: true,
},
hostName: user.name,
hostId: user.id,
reviewer: user.id,
signupUrl: bracketUrl ? "" : link,
startTime: 0,
urls: [link],
};
room.hidetext(user.id, true, 1, "Your tournament must be approved by a staff member");
user.say("Your tournament must be approved by a staff member");
user.say('Use the command ``' + Config.commandCharacter + 'gettourapproval ' + room.id + ', __bracket link__, ' +
'__signup link__`` to get your tournament approved (insert your actual links).');
break;
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/commands/tournament.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ export const commands: BaseCommandDefinitions = {

if (targetRoom.newUserHostedTournaments) {
for (const i in targetRoom.newUserHostedTournaments) {
if (user.id === targetRoom.newUserHostedTournaments[i].hostId) {
if (user.id === targetRoom.newUserHostedTournaments[i].hostId &&
targetRoom.newUserHostedTournaments[i].startTime !== 0) {
return this.say("You are already on the waiting list for staff review.");
}
}
Expand All @@ -613,6 +614,11 @@ export const commands: BaseCommandDefinitions = {
const userHostedTournament: IUserHostedTournament = {
approvalStatus: '',
bracketUrl,
canWarn: {
changesRequested: false,
awaitingApproval: false,
approvalRequested: false,
},
hostName: user.name,
hostId: user.id,
reviewer: '',
Expand Down Expand Up @@ -717,7 +723,10 @@ export const commands: BaseCommandDefinitions = {

this.say("You have approved " + targetRoom.approvedUserHostedTournaments[link].hostName + "'s tournament.");
const host = Users.get(targetRoom.approvedUserHostedTournaments[link].hostName);
if (host) host.say(user.name + " has approved your tournament! You may now advertise in " + targetRoom.title + ".");
if (host) {
host.say(user.name + " has approved your tournament! You may now advertise in " + targetRoom.title + ".");
host.say("Please use this link: ``" + link + "``");
}
} else {
if (targetRoom.newUserHostedTournaments[link].approvalStatus === 'changes-requested') {
return this.say("Changes have already been requested for " +
Expand Down
22 changes: 22 additions & 0 deletions src/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,28 @@ export class Room {
});
}

hidetext(user: string, clear: boolean, lineCount: number | null, reason: string, deleteAlts?: boolean): void {
user = Tools.toId(user);
if (!user) return;
if (deleteAlts) lineCount = null;

let message: string;
if (clear) {
if (lineCount) message = "/clearlines " + user + "," + lineCount + "," + reason;
else if (deleteAlts) message = "/clearaltstext " + user + "," + reason;
else message = "/cleartext " + user + "," + reason;
} else {
if (lineCount) message = "/hidelines " + user + "," + lineCount + "," + reason;
else if (deleteAlts) message = "/hidealtstext " + user + "," + reason;
else message = "/hidetext " + user + "," + reason;
}

this.say(message, {
type: 'hidetext',
hideReason: reason,
});
}

warn(userOrPlayer: User | Player, reason: string): void {
const user = this.getTargetUser(userOrPlayer);
if (!user) return;
Expand Down
5 changes: 3 additions & 2 deletions src/types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface IParsedIncomingMessage<T = IClientMessageTypes> {

export type IOutgoingMessageTypes = 'command' | 'chat' | 'chat-html' | 'chat-uhtml' | 'chat-uhtml-change' | 'private-html' |
'private-uhtml' | 'private-uhtml-change' | 'pm' | 'pm-html' | 'pm-uhtml' | 'pm-uhtml-change' | 'code' | 'join-room' | 'leave-room' |
'modchat' | 'filters-view' | 'banword-list' | 'room-voice' | 'room-deauth' | 'warn' | 'hangman-start' | 'hangman-end' | 'htmlpage' |
'htmlpageselector' | 'closehtmlpage' | 'highlight-htmlpage' | 'announce' | 'notifyrank' | 'notifyoffrank' | 'modnote' |
'modchat' | 'filters-view' | 'banword-list' | 'room-voice' | 'room-deauth' | 'warn' | 'hidetext' | 'hangman-start' | 'hangman-end' |
'htmlpage' | 'htmlpageselector' | 'closehtmlpage' | 'highlight-htmlpage' | 'announce' | 'notifyrank' | 'notifyoffrank' | 'modnote' |
'tournament-create' | 'tournament-start' | 'tournament-end' | 'tournament-name' | 'tournament-autostart' | 'tournament-autodq' |
'tournament-runautodq' | 'tournament-cap' | 'tournament-rules' | 'tournament-forcepublic' | 'tournament-forcetimer' |
'tournament-scouting' | 'tournament-modjoin' | 'tournament-disqualify' | 'notifyuser' | 'notifyoffuser' | 'query-userdetails' |
Expand All @@ -36,6 +36,7 @@ export interface IOutgoingMessageAttributes {
deauthedUserid?: string;
disqualifiedUserid?: string;
format?: string;
hideReason?: string;
html?: string;
measure?: boolean;
modchatLevel?: string;
Expand Down
5 changes: 5 additions & 0 deletions src/types/tournaments.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export interface IClientTournamentData {
export interface IUserHostedTournament {
approvalStatus: 'changes-requested' | 'approved' | '';
bracketUrl: string;
canWarn: {
changesRequested: boolean;
awaitingApproval: boolean;
approvalRequested: boolean;
}
hostId: string;
hostName: string;
reviewer: string;
Expand Down