From f332bbdcd05d38e137f7490a2780328d28bbcbf4 Mon Sep 17 00:00:00 2001 From: Tom Hummel Date: Sun, 2 Oct 2022 12:06:34 -0700 Subject: [PATCH 1/4] Add WhatsApp and Slack (failing) tests --- static/tools/enhance/enrich-emoji.test.js | 41 +++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/static/tools/enhance/enrich-emoji.test.js b/static/tools/enhance/enrich-emoji.test.js index a57aac8e..fbeafc25 100644 --- a/static/tools/enhance/enrich-emoji.test.js +++ b/static/tools/enhance/enrich-emoji.test.js @@ -13,7 +13,7 @@ Wordle 234 5/6* 🟩🟩🟩🟩🟩 ` const output = lib(wordle) - console.log(output) + // console.log(output) assert.equal(output.puzzleNum, 234) assert.equal(output.puzzleScore, 27) @@ -31,14 +31,49 @@ Wordle 466 4/6* 🟩🟩🟩🟩🟩 ` const output = lib(wordle) - console.log(output) + // console.log(output) assert.equal(output.puzzleNum, 466) assert.equal(output.isHardMode, true) assert.equal(output.puzzleScore, 23) assert.equal(output.puzzleDate, '2022-09-28') assert.equal(output.guessCount, 4) - } + }, + function copyFromWhatsApp () { + const wordle = ` +Wordle 449 4/6* + +⬛️⬛️⬛️⬛️⬛️ +🟩⬛️🟨🟩⬛️ +🟩🟨⬛️🟩⬛️ +🟩🟩🟩🟩🟩 +` + const output = lib(wordle) + // console.log(output) + + assert.equal(output.puzzleNum, 449) + assert.equal(output.isHardMode, true) + assert.equal(output.puzzleScore, 20) + assert.equal(output.puzzleDate, '2022-09-11') + assert.equal(output.guessCount, 4) + }, + function copyFromWhatsApp () { + const wordle = ` +Wordle 467 4/6* +:black_large_square::black_large_square::black_large_square::black_large_square::black_large_square: +:black_large_square::black_large_square::large_green_square::black_large_square::large_yellow_square: +:large_yellow_square::large_yellow_square::large_green_square::large_yellow_square::black_large_square: +:large_green_square::large_green_square::large_green_square::large_green_square::large_green_square: +` + const output = lib(wordle) + console.log(output) + + assert.equal(output.puzzleNum, 467) + assert.equal(output.isHardMode, true) + assert.equal(output.puzzleScore, 22) + assert.equal(output.puzzleDate, '2022-09-29') + assert.equal(output.guessCount, 4) + }, ] tests.forEach((t) => t()) \ No newline at end of file From bbc8dbc7e4d7dc57fd15e8f739c1aab65bf388d6 Mon Sep 17 00:00:00 2001 From: Tom Hummel Date: Sun, 2 Oct 2022 13:07:29 -0700 Subject: [PATCH 2/4] Add identification and handling for emoji shares pasted from slack --- static/tools/enhance/enrich-emoji.js | 64 ++++++++++++++++------- static/tools/enhance/enrich-emoji.test.js | 2 +- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/static/tools/enhance/enrich-emoji.js b/static/tools/enhance/enrich-emoji.js index 3c5b6826..e624fe1c 100644 --- a/static/tools/enhance/enrich-emoji.js +++ b/static/tools/enhance/enrich-emoji.js @@ -1,13 +1,13 @@ var epoch = new Date("2021-06-19T00:00:00") var solutionCount = 2309 -function getPuzzleDate (num) { +function getPuzzleDate(num) { var startDate = new Date(epoch) var puzzleDate = startDate.setHours(0, 0, 0, 0) + (num * 864e5) - return (new Date(puzzleDate)).toISOString().substr(0,10) + return (new Date(puzzleDate)).toISOString().substr(0, 10) } -function analyzeEmoji (input) { +function analyzeEmoji(input) { var title = input.match(/Wordle [0-9]* [1-6]{1}\/6\*?/) var titlePieces = title[0].split(' ') var puzzleNum = parseInt(titlePieces[1], 10) @@ -15,21 +15,45 @@ function analyzeEmoji (input) { var guessPieces = titlePieces[2].split("") var [guessCount, slash, allowed, modeStr] = guessPieces - var results = input.match(/[🟩🟨⬛️]*/g) - .filter(r => r !== '') - .map((line) => { - return [...line] - .filter(a => /[^\ufe0f]/.test(a)) - .map((char) => { - if (char === '🟩') { - return 'correct' - } else if (char === '🟨') { - return 'present' - } else { - return 'absent' - } - }) - }) + var nytSharePattern = /[🟩🟨⬛️]*/g + var slackSharePattern = /(\:(large_green_square|black_large_square|large_yellow_square)\:){5}/g + var results = [] + + if (input.match(nytSharePattern)) { + results = input.match(nytSharePattern) + .filter(r => r !== '') + .map((line) => { + return [...line] + .filter(a => /[^\ufe0f]/.test(a)) + .map((char) => { + if (char === '🟩') { + return 'correct' + } else if (char === '🟨') { + return 'present' + } else { + return 'absent' + } + }) + }) + } + + if (input.match(slackSharePattern)) { + var slackTilePattern = /\:(large_green_square|black_large_square|large_yellow_square)\:/g + results = input.match(slackSharePattern) + .filter(r => r !== '') + .map((line) => { + return line.match(slackTilePattern) + .map((char) => { + if (char === ':large_green_square:') { + return 'correct' + } else if (char === ':large_yellow_square:') { + return 'present' + } else if (char === ':black_large_square:') { + return 'absent' + } + }) + }) + } var enrichedResults = results.map((lineStatuses) => { var lineEmoji = lineStatuses.map((status) => { @@ -58,8 +82,8 @@ function analyzeEmoji (input) { } }) - var puzzleScore = enrichedResults.reduce((memo, result) => { - return memo + result.lineScore + var puzzleScore = enrichedResults.reduce((memo, result) => { + return memo + result.lineScore }, 0) return { diff --git a/static/tools/enhance/enrich-emoji.test.js b/static/tools/enhance/enrich-emoji.test.js index fbeafc25..80d82e7f 100644 --- a/static/tools/enhance/enrich-emoji.test.js +++ b/static/tools/enhance/enrich-emoji.test.js @@ -57,7 +57,7 @@ Wordle 449 4/6* assert.equal(output.puzzleDate, '2022-09-11') assert.equal(output.guessCount, 4) }, - function copyFromWhatsApp () { + function copyFromSlack () { const wordle = ` Wordle 467 4/6* :black_large_square::black_large_square::black_large_square::black_large_square::black_large_square: From 24f65c46161f782413de7ac48af1b729764c7004 Mon Sep 17 00:00:00 2001 From: Tom Hummel Date: Sun, 2 Oct 2022 13:08:52 -0700 Subject: [PATCH 3/4] Update enhance/index with new slack functionality --- static/tools/enhance/index.html | 65 ++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/static/tools/enhance/index.html b/static/tools/enhance/index.html index 6eff665a..f0b1d901 100644 --- a/static/tools/enhance/index.html +++ b/static/tools/enhance/index.html @@ -8,15 +8,14 @@