From e8d4cfb6a082d20bfbdb4560676564ff5c61c652 Mon Sep 17 00:00:00 2001 From: Dirain1700 <86363603+Dirain1700@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:10:00 +0000 Subject: [PATCH 1/6] User Hosted Tournaments: Check chalonge link properly --- src/client/client.ts | 90 +++++++++++++++++++++++++++++--------- src/commands/tournament.ts | 8 +++- src/rooms.ts | 22 ++++++++++ src/types/client.d.ts | 5 ++- src/types/tournaments.d.ts | 5 +++ 5 files changed, 107 insertions(+), 23 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index c404ef8a..b9535164 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 + ')')) + this.websocket.clearLastOutgoingMessage(now); } else if (lastOutgoingMessage.type === 'warn') { if (messageArguments.message.endsWith(' was warned by ' + Users.self.name + ". (" + lastOutgoingMessage.warnReason + ")")) { @@ -2163,11 +2168,11 @@ export class Client { // unlink unapproved Challonge tournaments if (room.unlinkChallongeLinks && lowerCaseMessage.includes('challonge.com/')) { - const links: string[] = []; + const links: { url: string, valid: boolean }[] = []; const possibleLinks = message.split(" "); for (const possibleLink of possibleLinks) { const link = Tools.getChallongeUrl(possibleLink); - if (link) links.push(link); + if (link) links.push({ url: link, valid: link === possibleLink }); } const database = Storage.getDatabase(room); @@ -2181,9 +2186,10 @@ export class Client { for (const link of links) { if (room.approvedUserHostedTournaments) { for (const i in room.approvedUserHostedTournaments) { - if (room.approvedUserHostedTournaments[i].urls.includes(link)) { + if (room.approvedUserHostedTournaments[i].urls.includes(link.url)) { 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; } @@ -2191,19 +2197,19 @@ export class Client { } if (authOrTHC) { - const bracketUrl = Tools.isChallongeBracketUrl(link); + const bracketUrl = Tools.isChallongeBracketUrl(link.url); if (!room.approvedUserHostedTournaments) room.approvedUserHostedTournaments = {}; - if (!(link in room.approvedUserHostedTournaments)) { + if (!(link.url in room.approvedUserHostedTournaments)) { let existingTournament = false; for (const i in room.approvedUserHostedTournaments) { - if (link === room.approvedUserHostedTournaments[i].bracketUrl || - link === room.approvedUserHostedTournaments[i].signupUrl) { - room.approvedUserHostedTournaments[link] = room.approvedUserHostedTournaments[i]; - room.approvedUserHostedTournaments[link].urls.push(link); + if (link.url === room.approvedUserHostedTournaments[i].bracketUrl || + link.url === room.approvedUserHostedTournaments[i].signupUrl) { + room.approvedUserHostedTournaments[link.url] = room.approvedUserHostedTournaments[i]; + room.approvedUserHostedTournaments[link.url].urls.push(link.url); if (bracketUrl) { - room.approvedUserHostedTournaments[link].bracketUrl = link; + room.approvedUserHostedTournaments[link.url].bracketUrl = link.url; } else { - room.approvedUserHostedTournaments[link].signupUrl = link; + room.approvedUserHostedTournaments[link.url].signupUrl = link.url; } existingTournament = true; @@ -2212,36 +2218,80 @@ export class Client { } if (!existingTournament) { - room.approvedUserHostedTournaments[link] = { + room.approvedUserHostedTournaments[link.url] = { approvalStatus: 'approved', - bracketUrl: bracketUrl ? link : "", + bracketUrl: bracketUrl ? link.url : "", + canWarn: { + changesRequested: false, + awaitingApproval: false, + approvalRequested: false, + }, hostName: user.name, hostId: user.id, reviewer: user.id, - signupUrl: bracketUrl ? "" : link, + signupUrl: bracketUrl ? "" : link.url, startTime: now, - urls: [link], + urls: [link.url], }; } } } else { for (const i in room.newUserHostedTournaments) { - if (room.newUserHostedTournaments[i].urls.includes(link)) { + if (room.newUserHostedTournaments[i].urls.includes(link.url)) { 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"); + 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 { - room.warn(user, "You must wait for a staff member to approve your tournament"); + 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"); + if (!room.newUserHostedTournaments) room.newUserHostedTournaments = {}; + // idk why eslint angries, can returns true and false + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if (room.newUserHostedTournaments[link.url] && room.newUserHostedTournaments[link.url].canWarn.approvalRequested) { + room.warn(user, "Your tournament must be approved by a staff member"); + room.hidetext(user.id, true, 1, ""); + } else { + const bracketUrl = Tools.isChallongeBracketUrl(link.url); + room.newUserHostedTournaments[link.url] = { + approvalStatus: '', + bracketUrl: bracketUrl ? link.url : "", + canWarn: { + changesRequested: false, + awaitingApproval: false, + approvalRequested: true, + }, + hostName: user.name, + hostId: user.id, + reviewer: user.id, + signupUrl: bracketUrl ? "" : link.url, + startTime: 0, + urls: [link.url], + }; + 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..ef4406c9 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: '', diff --git a/src/rooms.ts b/src/rooms.ts index ef707bd0..010d95f3 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 || !reason) 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; From e890e5a44a5e47eed3bfed532eb3e6903dfa48df Mon Sep 17 00:00:00 2001 From: Dirain1700 <86363603+Dirain1700@users.noreply.github.com> Date: Wed, 29 Mar 2023 15:18:19 +0000 Subject: [PATCH 2/6] Fix Client messagee --- src/client/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index b9535164..25b49f85 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -946,8 +946,8 @@ export class Client { } } else if (lastOutgoingMessage.type === 'hidetext') { if (messageArguments.message.endsWith(' messages were cleared from ' + room.title + - 'by' + Users.self.name + '. (' + - lastOutgoingMessage.hideReason + ')')) + '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 + ". (" + From 0a0e0ab9158a515e2bd47a75caf382feb5da2892 Mon Sep 17 00:00:00 2001 From: Dirain1700 <86363603+Dirain1700@users.noreply.github.com> Date: Thu, 30 Mar 2023 00:37:01 +0900 Subject: [PATCH 3/6] Fix typo --- src/client/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/client.ts b/src/client/client.ts index 25b49f85..c58b7346 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -947,7 +947,7 @@ export class Client { } else if (lastOutgoingMessage.type === 'hidetext') { if (messageArguments.message.endsWith(' messages were cleared from ' + room.title + 'by' + Users.self.name + '.' + (lastOutgoingMessage.hideReason ? ' (' + - lastOutgoingMessage.hideReason + ')' : ''))); + lastOutgoingMessage.hideReason + ')' : ''))) this.websocket.clearLastOutgoingMessage(now); } else if (lastOutgoingMessage.type === 'warn') { if (messageArguments.message.endsWith(' was warned by ' + Users.self.name + ". (" + From 322c941f11f50320690b41de928c6e4ee3a7d3cd Mon Sep 17 00:00:00 2001 From: Dirain1700 <86363603+Dirain1700@users.noreply.github.com> Date: Wed, 29 Mar 2023 16:41:42 +0000 Subject: [PATCH 4/6] Empty commit To rerun CI From 53fc696da7b8d067ae050a092a6d46f6a97a6086 Mon Sep 17 00:00:00 2001 From: Dirain1700 <86363603+Dirain1700@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:55:09 +0000 Subject: [PATCH 5/6] some stuff --- src/client/client.ts | 91 +++++++++++++++++++------------------- src/commands/tournament.ts | 5 ++- src/rooms.ts | 2 +- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index c58b7346..89019296 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -2168,12 +2168,12 @@ export class Client { // unlink unapproved Challonge tournaments if (room.unlinkChallongeLinks && lowerCaseMessage.includes('challonge.com/')) { - const links: { url: string, valid: boolean }[] = []; + const links: string[] = []; const possibleLinks = message.split(" "); for (const possibleLink of possibleLinks) { const link = Tools.getChallongeUrl(possibleLink); - if (link) links.push({ url: link, valid: link === possibleLink }); - } + if (link) links.push(link); + } const database = Storage.getDatabase(room); let rank: GroupName = 'voice'; @@ -2186,7 +2186,7 @@ export class Client { for (const link of links) { if (room.approvedUserHostedTournaments) { for (const i in room.approvedUserHostedTournaments) { - if (room.approvedUserHostedTournaments[i].urls.includes(link.url)) { + 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, ""); @@ -2197,19 +2197,19 @@ export class Client { } if (authOrTHC) { - const bracketUrl = Tools.isChallongeBracketUrl(link.url); + const bracketUrl = Tools.isChallongeBracketUrl(link); if (!room.approvedUserHostedTournaments) room.approvedUserHostedTournaments = {}; - if (!(link.url in room.approvedUserHostedTournaments)) { + if (!(link in room.approvedUserHostedTournaments)) { let existingTournament = false; for (const i in room.approvedUserHostedTournaments) { - if (link.url === room.approvedUserHostedTournaments[i].bracketUrl || - link.url === room.approvedUserHostedTournaments[i].signupUrl) { - room.approvedUserHostedTournaments[link.url] = room.approvedUserHostedTournaments[i]; - room.approvedUserHostedTournaments[link.url].urls.push(link.url); + if (link === room.approvedUserHostedTournaments[i].bracketUrl || + link === room.approvedUserHostedTournaments[i].signupUrl) { + room.approvedUserHostedTournaments[link] = room.approvedUserHostedTournaments[i]; + room.approvedUserHostedTournaments[link].urls.push(link); if (bracketUrl) { - room.approvedUserHostedTournaments[link.url].bracketUrl = link.url; + room.approvedUserHostedTournaments[link].bracketUrl = link; } else { - room.approvedUserHostedTournaments[link.url].signupUrl = link.url; + room.approvedUserHostedTournaments[link].signupUrl = link; } existingTournament = true; @@ -2218,9 +2218,9 @@ export class Client { } if (!existingTournament) { - room.approvedUserHostedTournaments[link.url] = { + room.approvedUserHostedTournaments[link] = { approvalStatus: 'approved', - bracketUrl: bracketUrl ? link.url : "", + bracketUrl: bracketUrl ? link : "", canWarn: { changesRequested: false, awaitingApproval: false, @@ -2229,15 +2229,15 @@ export class Client { hostName: user.name, hostId: user.id, reviewer: user.id, - signupUrl: bracketUrl ? "" : link.url, + signupUrl: bracketUrl ? "" : link, startTime: now, - urls: [link.url], + urls: [link], }; } } } else { for (const i in room.newUserHostedTournaments) { - if (room.newUserHostedTournaments[i].urls.includes(link.url)) { + 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, ""); @@ -2254,7 +2254,14 @@ export class Client { "for your tournament and you must wait for them to be approved"); room.newUserHostedTournaments[i].canWarn.changesRequested = true; } - } else { + } 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, ""); @@ -2267,33 +2274,27 @@ export class Client { } } if (!room.newUserHostedTournaments) room.newUserHostedTournaments = {}; - // idk why eslint angries, can returns true and false - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if (room.newUserHostedTournaments[link.url] && room.newUserHostedTournaments[link.url].canWarn.approvalRequested) { - room.warn(user, "Your tournament must be approved by a staff member"); - room.hidetext(user.id, true, 1, ""); - } else { - const bracketUrl = Tools.isChallongeBracketUrl(link.url); - room.newUserHostedTournaments[link.url] = { - approvalStatus: '', - bracketUrl: bracketUrl ? link.url : "", - canWarn: { - changesRequested: false, - awaitingApproval: false, - approvalRequested: true, - }, - hostName: user.name, - hostId: user.id, - reviewer: user.id, - signupUrl: bracketUrl ? "" : link.url, - startTime: 0, - urls: [link.url], - }; - 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).'); + + 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 ef4406c9..705b3c08 100644 --- a/src/commands/tournament.ts +++ b/src/commands/tournament.ts @@ -723,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 010d95f3..86323dce 100644 --- a/src/rooms.ts +++ b/src/rooms.ts @@ -585,7 +585,7 @@ export class Room { hidetext(user: string, clear: boolean, lineCount: number | null, reason: string, deleteAlts?: boolean): void { user = Tools.toId(user); - if (!user || !reason) return; + if (!user) return; if (deleteAlts) lineCount = null; let message: string; From 1058bbef4a1cc4a5754634196036523239405cb9 Mon Sep 17 00:00:00 2001 From: Dirain1700 <86363603+Dirain1700@users.noreply.github.com> Date: Tue, 4 Apr 2023 03:19:19 +0900 Subject: [PATCH 6/6] Fix traling spaces --- src/client/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/client.ts b/src/client/client.ts index 89019296..44b9e281 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -2173,7 +2173,7 @@ export class Client { for (const possibleLink of possibleLinks) { const link = Tools.getChallongeUrl(possibleLink); if (link) links.push(link); - } + } const database = Storage.getDatabase(room); let rank: GroupName = 'voice';