From f2931ba372589b583d8571de9fd77a9b457a5df3 Mon Sep 17 00:00:00 2001 From: "." <26331505+ed789d0@users.noreply.github.com> Date: Sat, 1 Jun 2024 16:28:11 -0400 Subject: [PATCH] initial korean implementation --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e55a135..181037c 100644 --- a/index.js +++ b/index.js @@ -214,7 +214,9 @@ process.on("uncaughtException", async (err) => { const splchecker = new SpellChecker(new SpellCfg({ ignoreCase: false, languages: ['en-us'] })); splchecker.addDictionaryPhrase('Quotobot'); splchecker.addDictionaryPhrase('quotobot'); +const splchecker_ko = new SpellChecker(new SpellCfg({ ignoreCase: false, languages: ['ko'] })); splchecker.addProviderByConfig({ name: 'hunspell' }); +splchecker_ko.addProviderByConfig({ name: 'hunspell' }); bot.login(token); bot.on("warn", m => console.warn(chalk`{yellow Warning: ${m}}`)); bot.on("error", m => console.error(chalk`{redBright Error: ${m}}`)); @@ -559,15 +561,17 @@ bot.on("message", message => { setTimeout(() => { usedSpellingRecently.delete(message.author.id); }, timeout); - let { items } = await splchecker.checkText(args.join(" ")); + const spellcheckLanguage = message.content.match(/[\u3131-\uD79D]/) ? "ko" : "en-us"; + let { items } = await (spellcheckLanguage == "ko" ? splchecker_ko : splchecker).checkText(args.join(" ")); if (!items || items.length < 1) return message.reply(new Discord.MessageEmbed().setTitle("No errors found.").setColor(6765239)); items = uniqBy(items, "fragment"); let desc = ""; const mbed = new Discord.MessageEmbed() .setColor(6765239) .setTitle("Spell Check"); + const strikethrough = spellcheckLanguage == "ko" ? "" : "~~"; // don't strikethrough Korean items.some(({ fragment, suggestions }) => { - let addition = `~~${fragment}~~ → **${suggestions.join("**, **") || "No suggestions"} **\n`; + let addition = `${strikethrough + fragment + strikethrough} → **${suggestions.join("**, **") || "No suggestions"} **\n`; if (desc.length + addition.length > 2000) { mbed.setFooter("This spellcheck has been shortened."); return true;