diff --git a/commands/games-sp/typing-test.js b/commands/games-sp/typing-test.js index fb15ccab..9f2f2f8e 100644 --- a/commands/games-sp/typing-test.js +++ b/commands/games-sp/typing-test.js @@ -2,7 +2,7 @@ const Command = require('../../structures/Command'); const { createCanvas, registerFont } = require('canvas'); const { stripIndents } = require('common-tags'); const path = require('path'); -const { fetchHSUserDisplay } = require('../../util/Util'); +const { textDiff, fetchHSUserDisplay } = require('../../util/Util'); const words = require('../../assets/json/word-list'); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' }); @@ -38,7 +38,12 @@ module.exports = class TypingTestCommand extends Command { await this.client.redis.set('typing-test-user', msg.author.id); } if (!msgs.size) return msg.reply('Sorry! You lose!'); - if (msgs.first().content.toLowerCase() !== sentence) return msg.reply('Sorry! You made a typo, so you lose!'); + if (msgs.first().content.toLowerCase() !== sentence) { + return msg.reply(stripIndents` + Sorry! You made a typo, so you lose! + ${textDiff(msgs.first().content.toLowerCase(), sentence)} + `); + } const wpm = (sentence.length / 5) / ((newScore / 1000) / 60); return msg.reply(stripIndents` Nice job! 10/10! You deserve some cake! (Took ${newScore / 1000} seconds, ${Math.round(wpm)} WPM) diff --git a/package.json b/package.json index 6b3dae74..d01c149c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "129.0.1", + "version": "129.0.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/util/Util.js b/util/Util.js index 519c985f..bebeabbd 100644 --- a/util/Util.js +++ b/util/Util.js @@ -181,6 +181,19 @@ module.exports = class Util { return ((r << 16) | (g << 8) | b).toString(16); } + static textDiff(oldText, newText) { + const changed = []; + return oldText.split('').map((char, i) => { + if (char === newText.charAt(i)) { + const chars = changed.length ? `**${changed.join('')}**${char}` : char; + if (changed.length) changed = []; + return chars; + } + changed.push(newText.charAt(i)); + return ''; + }).join(''); + } + static magikToBuffer(magik) { return new Promise((res, rej) => { magik.toBuffer((err, buffer) => {