Skip to content

Commit

Permalink
initial korean implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bgv2 committed Jun 1, 2024
1 parent ad878d0 commit f2931ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}`));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f2931ba

Please sign in to comment.