From 2c32677f3072953522aba2d54da2ffb9c16ad957 Mon Sep 17 00:00:00 2001 From: "Meijer,L. (Lucas)" Date: Wed, 10 Jul 2024 11:00:38 +0200 Subject: [PATCH 1/2] Scav and Mafia changes --- server/chat-plugins/mafia.ts | 18 +++++++-- server/chat-plugins/scavengers.ts | 66 ++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/server/chat-plugins/mafia.ts b/server/chat-plugins/mafia.ts index a3c137bf5cc3..3eb4018fac4b 100644 --- a/server/chat-plugins/mafia.ts +++ b/server/chat-plugins/mafia.ts @@ -4000,6 +4000,13 @@ export const commands: Chat.ChatCommands = { async listdata(target, room, user, connection, cmd, message) { if (!this.runBroadcast()) return false; + // Fix errors + // Fix searching on roles + // Fix random (do not pick empty) + + // Future: tags + // Future: or + // Determine non-search targets first, afterwards searching is done with the remainder let targets = target.split(',').map(x => x.trim()); @@ -4055,6 +4062,8 @@ export const commands: Chat.ChatCommands = { } let search = function (entries: any[], searchTarget) { + if(typeof(entries) == 'undefined') return entries; //Hotpatch + if (searchTarget.length == 0) return entries; const negation = searchTarget[0] == '!'; @@ -4064,7 +4073,7 @@ export const commands: Chat.ChatCommands = { if (searchType == `themes` && searchTarget.includes(`players`)) { const inequalities = ['<=', '>=', '=', '<', '>']; const inequality = inequalities.find(x => searchTarget.includes(x)); - if (!inequality) return this.errorReply(`Please provide a valid inequality for the players.`); + if (!inequality) return entries; // this.errorReply(`Please provide a valid inequality for the players.`); const players = searchTarget.split(inequality)[1].trim(); if (((players != null) && @@ -4074,7 +4083,7 @@ export const commands: Chat.ChatCommands = { else if (inequality == '<' || inequality == '<=') entries = entries.filter(([key, data]) => ([...Array(+players + (inequality == '<=' ? +1 : +0)).keys()]).some(playerCount => playerCount in (MafiaData[searchType][key]))); else if (inequality == '>' || inequality == '>=') entries = entries.filter(([key, data]) => ([...Array(30 - players).keys()].map(num => +num + +players + (inequality == '>=' ? +0 : +1))).some(playerCount => playerCount in (MafiaData[searchType][key]))); } else { - return this.errorReply(`Please ensure the amount of players is numeric.`); + return entries; // this.errorReply(`Please ensure the amount of players is numeric.`); } } else if ((searchType == `roles`) && toID(searchTarget) in MafiaData[`themes`]) { @@ -4136,9 +4145,12 @@ export const commands: Chat.ChatCommands = { if (!hidden) entries = entries.filter(([key, data]) => !MafiaData[searchType][key][`tags`].includes(`hidden`)); for (let i = 0; i < targets.length; i++) { - entries = targets[i].split('|').map(x => x.trim()).map(searchTerm => search(entries.slice(), searchTerm)).reduce((aggregate, result) => [...new Set([...aggregate, ...result])]); + entries = targets[i].split('|').map(x => x.trim()).map(searchTerm => search.call(this, entries.slice(), searchTerm)).reduce((aggregate, result) => [...new Set([...aggregate, ...result])]); } + console.log(typeof(entries)); + if(typeof(entries) == 'undefined') return; //Hotpatch + if (random) entries = shuffle(entries); if (number > 0) entries = entries.slice(0, number) diff --git a/server/chat-plugins/scavengers.ts b/server/chat-plugins/scavengers.ts index ece8db2d7861..d90fd55c77fe 100644 --- a/server/chat-plugins/scavengers.ts +++ b/server/chat-plugins/scavengers.ts @@ -17,6 +17,7 @@ type GameTypes = 'official' | 'regular' | 'mini' | 'unrated' | 'practice' | 'rec export interface QueuedHunt { hosts: {id: string, name: string, noUpdate?: boolean}[]; questions: (string | string[])[]; + isHTML: boolean; staffHostId: string; staffHostName: string; gameType: GameTypes; @@ -226,7 +227,7 @@ function formatQueue(queue: QueuedHunt[] | undefined, viewer: User, room: Room, return Utils.html`[${q.join(' / ')}]
`; } else { q = q as string; - return Utils.escapeHTML(q); + return item.isHTML ? q : Utils.escapeHTML(q); } } ).join(" "); @@ -327,6 +328,7 @@ export class ScavengerHunt extends Rooms.RoomGame { completed: AnyObject[]; leftHunt: {[userid: string]: 1 | undefined}; hosts: FakeUser[]; + isHTML: boolean; modsList: string[]; mods: {[k: string]: ModEvent[]}; staffHostId: string; @@ -344,6 +346,7 @@ export class ScavengerHunt extends Rooms.RoomGame { hosts: FakeUser[], gameType: GameTypes, questions: (string | string[])[], + isHTML? : boolean, mod?: string | string[] ) { super(room); @@ -362,6 +365,8 @@ export class ScavengerHunt extends Rooms.RoomGame { this.hosts = hosts; + this.isHTML = isHTML ? isHTML : false; + this.modsList = []; this.mods = {}; @@ -443,8 +448,8 @@ export class ScavengerHunt extends Rooms.RoomGame { const huntType = `${article} ${newHunt ? 'new ' : ''}${this.gameType}`; return `|raw|
${huntType} scavenger hunt by ${hosts} has been started${staffHost}.` + - `
` + - `Hint #1: ${Chat.formatText(this.questions[0].hint)}` + + `
` + + `Hint #1: ${this.isHTML ? this.questions[0].hint : Chat.formatText(this.questions[0].hint)}` + `
` + `(To answer, use /scavenge ANSWER)
`; } @@ -617,7 +622,7 @@ export class ScavengerHunt extends Rooms.RoomGame { return `|raw|
` + `` + ``; } - let template = `
${finalHint}Hint #${current.number}:${ - Chat.formatText(current.question.hint) + + this.isHTML ? current.question.hint : Chat.formatText(current.question.hint) + (showHints && current.question.spoilers.length ? `
Extra Hints:${ current.question.spoilers.map(p => `- ${p}`).join('
') @@ -660,7 +665,7 @@ export class ScavengerHunt extends Rooms.RoomGame { `
${ i + 1 }${ - Chat.formatText(q.hint) + + this.isHTML ? q.hint : Chat.formatText(q.hint) + (q.spoilers.length ? `
Extra Hints:${ q.spoilers.map(s => `- ${s}`).join('
') @@ -711,7 +716,7 @@ export class ScavengerHunt extends Rooms.RoomGame { `${this.completed.slice(0, sliceIndex).map((p, i) => `${Utils.formatOrder(i + 1)} place: ${Utils.escapeHTML(p.name)} [${p.time}].
`).join("")}` + `${this.completed.length > sliceIndex ? `Consolation Prize: ${this.completed.slice(sliceIndex).map(e => `${Utils.escapeHTML(e.name)} [${e.time}]`).join(', ')}
` : ''}
` + `
Solution:
` + - `${this.questions.map((q, i) => `${i + 1}) ${Chat.formatText(q.hint)} [${Utils.escapeHTML(q.answer.join(' / '))}]`).join("
")}` + + `${this.questions.map((q, i) => `${i + 1}) ${this.isHTML ? q.hint : Chat.formatText(q.hint)} [${Utils.escapeHTML(q.answer.join(' / '))}]`).join("
")}` + `
` ); } @@ -1016,7 +1021,7 @@ export class ScavengerHuntPlayer extends Rooms.RoomGamePlayer { onNotifyChange(num: number) { this.game.runEvent('NotifyChange', this, num); if (num === this.currentQuestion) { - this.sendRoom(`|raw|The hint has been changed to: ${Chat.formatText(this.game.questions[num].hint)}`); + this.sendRoom(`|raw|The hint has been changed to: ${this.game.isHTML ? this.game.questions[num].hint : Chat.formatText(this.game.questions[num].hint)}`); } } @@ -1339,6 +1344,20 @@ const ScavengerCommands: Chat.ChatCommands = { forcecreate: 'create', forcecreateunrated: 'create', createrecycled: 'create', + + createhtmltwist: 'create', + createhtmltwistofficial: 'create', + createhtmltwistmini: 'create', + createhtmltwistpractice: 'create', + createhtmltwistunrated: 'create', + createhtmlpractice: 'create', + createhtmlofficial: 'create', + createhtmlunrated: 'create', + createhtmlmini: 'create', + forcecreatehtml: 'create', + forcecreatehtmlunrated: 'create', + createhtmlrecycled: 'create', + createhtml: 'create', create(target, room, user, connection, cmd) { room = this.requireRoom(); if (!getScavsRoom(room)) { @@ -1359,6 +1378,8 @@ const ScavengerCommands: Chat.ChatCommands = { gameType = 'recycled'; } + let isHTML = cmd.includes('html'); + let mod; let questions = target; @@ -1410,7 +1431,7 @@ const ScavengerCommands: Chat.ChatCommands = { const res = ScavengerHunt.parseQuestions(params); if (res.err) return this.errorReply(res.err); - room.game = new ScavengerHunt(room, user, hosts, gameType, res.result, mod); + room.game = new ScavengerHunt(room, user, hosts, gameType, res.result, isHTML, mod); this.privateModAction(`A new scavenger hunt was created by ${user.name}.`); this.modlog('SCAV NEW', null, `${gameType.toUpperCase()}: creators - ${hosts.map(h => h.id)}`); @@ -1526,6 +1547,7 @@ const ScavengerCommands: Chat.ChatCommands = { const hunt: QueuedHunt = { hosts: game.hosts, questions: [], + isHTML: game.isHTML, staffHostId: game.staffHostId, staffHostName: game.StaffHostName, gameType: game.gameType, @@ -1699,6 +1721,10 @@ const ScavengerCommands: Chat.ChatCommands = { queueunrated: 'queue', queuerated: 'queue', queuerecycled: 'queue', + queuehtmlunrated: 'queue', + queuehtmlrated: 'queue', + queuehtmlrecycled: 'queue', + queuehtml: 'queue', queue(target, room, user) { room = this.requireRoom(); if (!getScavsRoom(room)) { @@ -1714,6 +1740,8 @@ const ScavengerCommands: Chat.ChatCommands = { return this.parse('/scavhelp staff'); } + let isHTML = this.cmd.includes('html'); + this.checkCan('mute', null, room); if (this.cmd === 'queuerecycled') { @@ -1736,6 +1764,7 @@ const ScavengerCommands: Chat.ChatCommands = { room.settings.scavQueue.push({ hosts: next.hosts, questions: correctlyFormattedQuestions, + isHTML: this.cmd.includes('html'), staffHostId: 'scavengermanager', staffHostName: 'Scavenger Manager', gameType: 'unrated', @@ -1755,6 +1784,7 @@ const ScavengerCommands: Chat.ChatCommands = { room.settings.scavQueue.push({ hosts: hosts, questions: results.result, + isHTML: isHTML, staffHostId: user.id, staffHostName: user.name, gameType: (this.cmd.includes('unrated') ? 'unrated' : 'regular'), @@ -1815,7 +1845,8 @@ const ScavengerCommands: Chat.ChatCommands = { {id: next.staffHostId, name: next.staffHostName}, next.hosts, next.gameType, - next.questions + next.questions, + next.isHTML ); if (huntId) this.sendReply(`|uhtmlchange|scav-queue|${formatQueue(room.settings.scavQueue, user, room)}`); @@ -2515,6 +2546,23 @@ export const commands: Chat.ChatCommands = { forcestartunrated: 'starthunt', forcestartpractice: 'starthunt', + starthtmlpracticehunt: 'starthunt', + starthtmlofficialhunt: 'starthunt', + starthtmlminihunt: 'starthunt', + starthtmlunratedhunt: 'starthunt', + starthtmlrecycledhunt: 'starthunt', + starthtmltwisthunt: 'starthunt', + starthtmltwistofficial: 'starthunt', + starthtmltwistpractice: 'starthunt', + starthtmltwistmini: 'starthunt', + starthtmltwistunrated: 'starthunt', + + forcehtmlstarthunt: 'starthunt', + forcehtmlstartunrated: 'starthunt', + forcehtmlstartpractice: 'starthunt', + + starthtmlhunt: 'starthunt', + starthunt: ScavengerCommands.create, joinhunt: ScavengerCommands.join, leavehunt: ScavengerCommands.leave, From e0ea6f161f2382104165a4065243116bcb3acaaa Mon Sep 17 00:00:00 2001 From: "Meijer,L. (Lucas)" Date: Thu, 11 Jul 2024 20:20:35 +0200 Subject: [PATCH 2/2] Scavengers fix image scroll --- server/chat-plugins/scavengers.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/chat-plugins/scavengers.ts b/server/chat-plugins/scavengers.ts index d90fd55c77fe..51c9541b766b 100644 --- a/server/chat-plugins/scavengers.ts +++ b/server/chat-plugins/scavengers.ts @@ -239,7 +239,7 @@ function formatQueue(queue: QueuedHunt[] | undefined, viewer: User, room: Room, } else { buffer = `
The scavenger queue is currently empty.
${showStaff ? buffer : buffer.replace(/.+?<\/button>/gi, '')}
ByQuestions
`; + let template = `
${showStaff ? buffer : buffer.replace(/.+?<\/button>/gi, '')}
ByQuestions
`; if (showStaff) { template += `
Auto Timer Duration: ${timerDuration} minutesAuto Dequeue: