diff --git a/README.md b/README.md index 4ada851b..3b71b267 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 587 +Total: 588 ### Utility: @@ -828,6 +828,7 @@ Total: 587 * **pirate:** Converts text to pirate. * **repeat:** Repeat text over and over and over and over (etc). * **reverse:** Reverses text. +* **romaji:** Converts Japanese text to Romaji. * **say:** Make me say what you want, master. * **sha-1:** Creates a hash of text with the SHA-1 algorithm. * **sha-256:** Creates a hash of text with the SHA-256 algorithm. diff --git a/commands/edit-text/romaji.js b/commands/edit-text/romaji.js new file mode 100644 index 00000000..4e348e75 --- /dev/null +++ b/commands/edit-text/romaji.js @@ -0,0 +1,36 @@ +const Command = require('../../structures/Command'); +const Kuroshiro = require('kuroshiro'); +const KuromojiAnalyzer = require('kuroshiro-analyzer-kuromoji'); + +module.exports = class RomajiCommand extends Command { + constructor(client) { + super(client, { + name: 'romaji', + aliases: ['romajify', 'hepburn'], + group: 'edit-text', + memberName: 'romaji', + description: 'Converts Japanese text to Romaji.', + args: [ + { + key: 'text', + prompt: 'What text would you like to convert to romaji?', + type: 'string', + max: 500, + validate: text => Kuroshiro.Util.hasJapanese(text) + } + ] + }); + + this.analyzer = new Kuroshiro(); + this.inited = false; + } + + async run(msg, { text }) { + if (!this.inited) { + await this.analyzer.init(new KuromojiAnalyzer()); + this.inited = true; + } + const result = await this.analyzer.convert(text, { to: 'romaji' }); + return msg.say(result); + } +}; diff --git a/package.json b/package.json index f41f98ac..17c267b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "126.14.2", + "version": "126.15.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { @@ -55,6 +55,8 @@ "ioredis": "^4.19.4", "js-beautify": "^1.13.4", "js-chess-engine": "^0.6.0", + "kuroshiro": "^1.1.2", + "kuroshiro-analyzer-kuromoji": "^1.1.0", "mathjs": "^9.0.0", "moment": "^2.29.1", "moment-duration-format": "^2.3.2",