From 0f35533839622f5885d3a7bde8b77889c5704001 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 8 Apr 2021 17:26:13 -0400 Subject: [PATCH] Text Diff Command --- commands/analyze/text-diff.js | 39 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 commands/analyze/text-diff.js diff --git a/commands/analyze/text-diff.js b/commands/analyze/text-diff.js new file mode 100644 index 00000000..b2c08672 --- /dev/null +++ b/commands/analyze/text-diff.js @@ -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); + } +}; diff --git a/package.json b/package.json index beadc212..9317e1d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "134.11.0", + "version": "134.12.0", "description": "Your personal server companion.", "main": "Xiao.js", "private": true,