mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Text Diff Command
This commit is contained in:
@@ -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
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user