Text Diff Command

This commit is contained in:
Dragon Fire
2021-04-08 17:26:13 -04:00
parent 2ad527248f
commit 0f35533839
2 changed files with 40 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
const Command = require('../../structures/Command');
const Diff = require('text-diff');
module.exports = class TextDiffCommand extends Command {
constructor(client) {
super(client, {
name: 'text-diff',
aliases: ['diff'],
group: 'analyze',
memberName: 'text-diff',
description: 'Compares two different bits of text.',
args: [
{
key: 'text1',
prompt: 'What is the first text you would like to compare?',
type: 'string'
},
{
key: 'text2',
prompt: 'What is the second text you would like to compare?',
type: 'string'
}
]
});
}
run(msg, { text1, text2 }) {
const diff = new Diff();
const textDiff = diff.main(text1, text2);
diff.cleanupSemantic(textDiff);
const formatted = textDiff.map(change => {
if (change[0] === 1) return `**${change[1]}**`;
if (change[0] === 0) return change[1];
if (change[0] === -1) return `~~${change[1]}~~`;
return '';
}).join('');
return msg.reply(formatted);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "134.11.0", "version": "134.12.0",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"private": true, "private": true,