diff --git a/src/client/client.ts b/src/client/client.ts index c404ef8a..44b9e281 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -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 + ")")) { @@ -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; } @@ -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, @@ -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; } } diff --git a/src/commands/tournament.ts b/src/commands/tournament.ts index d9957dee..705b3c08 100644 --- a/src/commands/tournament.ts +++ b/src/commands/tournament.ts @@ -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."); } } @@ -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: '', @@ -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 " + diff --git a/src/rooms.ts b/src/rooms.ts index ef707bd0..86323dce 100644 --- a/src/rooms.ts +++ b/src/rooms.ts @@ -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; diff --git a/src/types/client.d.ts b/src/types/client.d.ts index 94f3dc64..27f91967 100644 --- a/src/types/client.d.ts +++ b/src/types/client.d.ts @@ -23,8 +23,8 @@ export interface IParsedIncomingMessage { 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' | @@ -36,6 +36,7 @@ export interface IOutgoingMessageAttributes { deauthedUserid?: string; disqualifiedUserid?: string; format?: string; + hideReason?: string; html?: string; measure?: boolean; modchatLevel?: string; diff --git a/src/types/tournaments.d.ts b/src/types/tournaments.d.ts index c5c6f7fa..567a0311 100644 --- a/src/types/tournaments.d.ts +++ b/src/types/tournaments.d.ts @@ -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;