mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add textdiff to typing-test
This commit is contained in:
@@ -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)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "129.0.1",
|
||||
"version": "129.0.2",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user