Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support any language in the word command. #458

Merged
merged 18 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"rethinkdb-ts": "^2.6.1",
"shoukaku": "^4.1.1",
"tinyld": "^1.3.4",
"wiktionary-scraper": "^0.0.2-patch.1",
"wiktionary-scraper": "^0.0.3",
"youtubei": "^1.6.7"
},
"devDependencies": {
Expand Down
7 changes: 2 additions & 5 deletions source/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import database from "logos:constants/database";
import defaults from "logos:constants/defaults";
import dictionaries from "logos:constants/dictionaries";
import directories from "logos:constants/directories";
import discord from "logos:constants/discord";
import emojis from "logos:constants/emojis";
import endpoints from "logos:constants/endpoints";
import gifs from "logos:constants/gifs";
Expand Down Expand Up @@ -39,16 +40,11 @@ const constants = Object.freeze({
MAXIMUM_DELETABLE_MESSAGES: 500,
MAXIMUM_INDEXABLE_MESSAGES: 1000,
MAXIMUM_CORRECTION_MESSAGE_LENGTH: 3072,
MAXIMUM_USERNAME_LENGTH: 32,
MAXIMUM_VOLUME: 100,
MAXIMUM_HISTORY_ENTRIES: 100,
MAXIMUM_QUEUE_ENTRIES: 100,
MAXIMUM_EMBED_FIELD_LENGTH: 1024,
MAXIMUM_EMBED_DESCRIPTION_LENGTH: 3072,
RESULTS_PER_PAGE: 10,
STATUS_CYCLE_PERIOD: 10 * time.second,
// The 10 seconds are to account for potential network lag.
INTERACTION_TOKEN_EXPIRY: 15 * time.minute - 10 * time.second,
SLOWMODE_COLLISION_TIMEOUT: 5 * time.second,
AUTO_DELETE_MESSAGE_TIMEOUT: 10 * time.second,
PICK_MISSING_WORD_CHOICES: 4,
Expand All @@ -67,6 +63,7 @@ export default Object.freeze({
defaults,
dictionaries,
directories,
discord,
emojis,
endpoints,
gifs,
Expand Down
246 changes: 246 additions & 0 deletions source/constants/dictionaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,252 @@ const dictionariesByLanguage = Object.freeze({
Spanish: ["wiktionary"],
Swedish: ["wiktionary"],
Turkish: ["wiktionary"],
Abkhazian: ["wiktionary"],
Afar: ["wiktionary"],
Afrikaans: ["wiktionary"],
Akan: ["wiktionary"],
Albanian: ["wiktionary"],
Amharic: ["wiktionary"],
Arabic: ["wiktionary"],
Assamese: ["wiktionary"],
Aymara: ["wiktionary"],
Azerbaijani: ["wiktionary"],
Bashkir: ["wiktionary"],
Basque: ["wiktionary"],
Belarusian: ["wiktionary"],
Bengali: ["wiktionary"],
Bihari: ["wiktionary"],
Bislama: ["wiktionary"],
Breton: ["wiktionary"],
Bulgarian: ["wiktionary"],
Burmese: ["wiktionary"],
Catalan: ["wiktionary"],
Cherokee: ["wiktionary"],
Chewa: ["wiktionary"],
"Chinese/Simplified": ["wiktionary"],
"Chinese/Traditional": ["wiktionary"],
Corsican: ["wiktionary"],
"Creole/Haitian": ["wiktionary"],
"Creole/Mauritian": ["wiktionary"],
"Creole/SierraLeone": ["wiktionary"],
"CzechoSlovak/Czech": ["wiktionary"],
"CzechoSlovak/Slovak": ["wiktionary"],
Dholuo: ["wiktionary"],
Dzongkha: ["wiktionary"],
English: ["wiktionary"],
Esperanto: ["wiktionary"],
Estonian: ["wiktionary"],
Ewe: ["wiktionary"],
Faroese: ["wiktionary"],
Fijian: ["wiktionary"],
"Filipino/Cebuano": ["wiktionary"],
"Filipino/Kapampangan": ["wiktionary"],
"Filipino/Tagalog": ["wiktionary"],
"Filipino/Waray": ["wiktionary"],
Frisian: ["wiktionary"],
Ga: ["wiktionary"],
Galician: ["wiktionary"],
Ganda: ["wiktionary"],
Georgian: ["wiktionary"],
Greenlandic: ["wiktionary"],
Guarani: ["wiktionary"],
Gujarati: ["wiktionary"],
Hausa: ["wiktionary"],
Hawaiian: ["wiktionary"],
Hebrew: ["wiktionary"],
Hindi: ["wiktionary"],
Hmong: ["wiktionary"],
Icelandic: ["wiktionary"],
Igbo: ["wiktionary"],
Indonesian: ["wiktionary"],
Interlingua: ["wiktionary"],
Interlingue: ["wiktionary"],
Inuktitut: ["wiktionary"],
Inupiak: ["wiktionary"],
Irish: ["wiktionary"],
Italian: ["wiktionary"],
Japanese: ["wiktionary"],
Javanese: ["wiktionary"],
Kannada: ["wiktionary"],
Kashmiri: ["wiktionary"],
Kazakh: ["wiktionary"],
Khasi: ["wiktionary"],
Khmer: ["wiktionary"],
Korean: ["wiktionary"],
Kurdish: ["wiktionary"],
Kyrgyz: ["wiktionary"],
Lao: ["wiktionary"],
Latin: ["wiktionary"],
Latvian: ["wiktionary"],
Limbu: ["wiktionary"],
Lingala: ["wiktionary"],
Lithuanian: ["wiktionary"],
Lozi: ["wiktionary"],
LubaLulua: ["wiktionary"],
Luxembourgish: ["wiktionary"],
Macedonian: ["wiktionary"],
Malagasy: ["wiktionary"],
Malay: ["wiktionary"],
Malayalam: ["wiktionary"],
Maldivian: ["wiktionary"],
Maltese: ["wiktionary"],
Manx: ["wiktionary"],
Maori: ["wiktionary"],
Marathi: ["wiktionary"],
Mongolian: ["wiktionary"],
Nauru: ["wiktionary"],
Nepali: ["wiktionary"],
Newar: ["wiktionary"],
"Norwegian/Nynorsk": ["wiktionary"],
Occitan: ["wiktionary"],
Odia: ["wiktionary"],
Oromo: ["wiktionary"],
Ossetian: ["wiktionary"],
Pashto: ["wiktionary"],
Pedi: ["wiktionary"],
Persian: ["wiktionary"],
"Portuguese/European": ["wiktionary"],
Punjabi: ["wiktionary"],
Quechua: ["wiktionary"],
Rajasthani: ["wiktionary"],
RhaetoRomance: ["wiktionary"],
"RwandaRundi/Kinyarwanda": ["wiktionary"],
"RwandaRundi/Kirundi": ["wiktionary"],
Samoan: ["wiktionary"],
Sango: ["wiktionary"],
Sanskrit: ["wiktionary"],
Scots: ["wiktionary"],
ScottishGaelic: ["wiktionary"],
"SerboCroatian/Bosnian": ["wiktionary"],
"SerboCroatian/Croatian": ["wiktionary"],
"SerboCroatian/Montenegrin": ["wiktionary"],
"SerboCroatian/Serbian": ["wiktionary"],
Seselwa: ["wiktionary"],
Shona: ["wiktionary"],
Sindhi: ["wiktionary"],
Sinhala: ["wiktionary"],
Slovenian: ["wiktionary"],
Somali: ["wiktionary"],
"Sotho/Southern": ["wiktionary"],
Sundanese: ["wiktionary"],
Swahili: ["wiktionary"],
Swazi: ["wiktionary"],
Syriac: ["wiktionary"],
Tajik: ["wiktionary"],
Tamil: ["wiktionary"],
Tatar: ["wiktionary"],
Telugu: ["wiktionary"],
Thai: ["wiktionary"],
Tibetan: ["wiktionary"],
Tigrinya: ["wiktionary"],
Tonga: ["wiktionary"],
Tsonga: ["wiktionary"],
Tswana: ["wiktionary"],
Tumbuka: ["wiktionary"],
Turkmen: ["wiktionary"],
Twi: ["wiktionary"],
Ukrainian: ["wiktionary"],
Urdu: ["wiktionary"],
Uyghur: ["wiktionary"],
Uzbek: ["wiktionary"],
Venda: ["wiktionary"],
Vietnamese: ["wiktionary"],
Volapuk: ["wiktionary"],
Welsh: ["wiktionary"],
Wolof: ["wiktionary"],
Xhosa: ["wiktionary"],
Yiddish: ["wiktionary"],
Yoruba: ["wiktionary"],
Zhuang: ["wiktionary"],
Zulu: ["wiktionary"],
Berber: ["wiktionary"],
Klingon: ["wiktionary"],
"Arabic/Egyptian": ["wiktionary"],
Aragonese: ["wiktionary"],
Armenian: ["wiktionary"],
Asturian: ["wiktionary"],
Avar: ["wiktionary"],
"Azerbaijani/Southern": ["wiktionary"],
Bavarian: ["wiktionary"],
"Bikol/Central": ["wiktionary"],
Bishnupriya: ["wiktionary"],
"Buriat/Russian": ["wiktionary"],
Chavacano: ["wiktionary"],
Chechen: ["wiktionary"],
Chinese: ["wiktionary"],
"Chinese/Wu": ["wiktionary"],
"Chinese/Yue": ["wiktionary"],
Chuvash: ["wiktionary"],
Cornish: ["wiktionary"],
Dotyali: ["wiktionary"],
"Emiliano-Romagnolo": ["wiktionary"],
Erzya: ["wiktionary"],
"Filipino/Ilocano": ["wiktionary"],
"Frisian/Northern": ["wiktionary"],
"Frisian/Western": ["wiktionary"],
"German/Low": ["wiktionary"],
"German/Swiss": ["wiktionary"],
"Hindi/Fijian": ["wiktionary"],
Ido: ["wiktionary"],
"Italian/Neapolitan": ["wiktionary"],
"Italian/Venetian": ["wiktionary"],
Kalmyk: ["wiktionary"],
"Karachay-Balkar": ["wiktionary"],
Komi: ["wiktionary"],
"Konkani/Goan": ["wiktionary"],
"Kurdish/Northern": ["wiktionary"],
Lezgian: ["wiktionary"],
Limburgish: ["wiktionary"],
Lojban: ["wiktionary"],
Lombard: ["wiktionary"],
"Luri/Northern": ["wiktionary"],
Maithili: ["wiktionary"],
"Mari/Eastern": ["wiktionary"],
"Mari/Western": ["wiktionary"],
Mazanderani: ["wiktionary"],
Minangkabau: ["wiktionary"],
Mingrelian: ["wiktionary"],
Mirandese: ["wiktionary"],
Nahuatl: ["wiktionary"],
Norwegian: ["wiktionary"],
Pfaelzisch: ["wiktionary"],
Piedmontese: ["wiktionary"],
Portuguese: ["wiktionary"],
"Punjabi/Western": ["wiktionary"],
Romansh: ["wiktionary"],
Rusyn: ["wiktionary"],
Sardinian: ["wiktionary"],
SerboCroatian: ["wiktionary"],
Sicilian: ["wiktionary"],
"Sorbian/Lower": ["wiktionary"],
"Sorbian/Upper": ["wiktionary"],
Tuvinian: ["wiktionary"],
Uighur: ["wiktionary"],
Veps: ["wiktionary"],
Vlaams: ["wiktionary"],
Walloon: ["wiktionary"],
Yakut: ["wiktionary"],
Zaza: ["wiktionary"],
"Portuguese/Brazilian": ["wiktionary"],
Bambara: ["wiktionary"],
Bhojpuri: ["wiktionary"],
Dogri: ["wiktionary"],
Filipino: ["wiktionary"],
Konkani: ["wiktionary"],
"Kurdish/Sorani": ["wiktionary"],
Meitei: ["wiktionary"],
Mizo: ["wiktionary"],
"Sotho/Northern": ["wiktionary"],
"Arabic/Emirati": ["wiktionary"],
"Arabic/SaudiArabian": ["wiktionary"],
"Catalan/Valencian": ["wiktionary"],
"English/Australian": ["wiktionary"],
"French/Canadian": ["wiktionary"],
"French/French": ["wiktionary"],
"Portuguese/Portuguese": ["wiktionary"],
"Spanish/Mexican": ["wiktionary"],
"Spanish/Spanish": ["wiktionary"],
"Spanish/American": ["wiktionary"],
} satisfies Record<LearningLanguage, Dictionary[]> as Record<LearningLanguage, Dictionary[]>);

export default Object.freeze({ languages: dictionariesByLanguage });
Expand Down
10 changes: 10 additions & 0 deletions source/constants/discord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import time from "logos:constants/time";

export default Object.freeze({
// The 10 seconds are to account for potential network lag.
INTERACTION_TOKEN_EXPIRY: 15 * time.minute - 10 * time.second,
MAXIMUM_USERNAME_LENGTH: 32,
MAXIMUM_EMBED_FIELD_LENGTH: 1024,
MAXIMUM_EMBED_DESCRIPTION_LENGTH: 3072,
MAXIMUM_AUTOCOMPLETE_CHOICES: 25,
} as const);
7 changes: 4 additions & 3 deletions source/constants/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export default Object.freeze({
translate: "https://lingvanex-translate.p.rapidapi.com/translate",
},
wordnik: {
relatedWords: (lemma: string) => `https://api.wordnik.com/v4/word.json/${lemma}/relatedWords`,
relatedWords: (lemma: string) =>
`https://api.wordnik.com/v4/word.json/${encodeURIComponent(lemma)}/relatedWords`,
},
wordsApi: {
host: "wordsapiv1.p.rapidapi.com",
word: (lemma: string) => `https://wordsapiv1.p.rapidapi.com/words/${lemma}`,
word: (lemma: string) => `https://wordsapiv1.p.rapidapi.com/words/${encodeURIComponent(lemma)}`,
},
dicolink: {
host: "dicolink.p.rapidapi.com",
definitions: (lemma: string) => `https://dicolink.p.rapidapi.com/mot/${lemma}/definitions`,
definitions: (lemma: string) => `https://dicolink.p.rapidapi.com/mot/${encodeURIComponent(lemma)}/definitions`,
},
} as const);
18 changes: 9 additions & 9 deletions source/constants/languages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DetectionLanguage } from "logos:constants/languages/detection";
import type { FeatureLanguage } from "logos:constants/languages/feature";
import type { LearningLanguage } from "logos:constants/languages/learning";
import { type DetectionLanguage, languages as detectionLanguages } from "logos:constants/languages/detection";
import { type FeatureLanguage, languages as featureLanguages } from "logos:constants/languages/feature";
import { collectLanguages, sortLanguages } from "logos:constants/languages/languages";
import { type LearningLanguage, languages as learningLanguages } from "logos:constants/languages/learning";
import {
type DiscordLocale,
type LocalisationLanguage,
Expand All @@ -15,12 +16,11 @@ import {

const languages = Object.freeze({
languages: {
localisation: [
...new Set<LocalisationLanguage>([...localisationLanguages.discord, ...localisationLanguages.logos]),
].sort((a, b) => a.localeCompare(b, "en", { sensitivity: "base" })),
translation: [
...new Set<TranslationLanguage>([...translationLanguages.deepl, ...translationLanguages.google]),
].sort((a, b) => a.localeCompare(b, "en", { sensitivity: "base" })),
detection: sortLanguages(collectLanguages<DetectionLanguage>(detectionLanguages)),
feature: sortLanguages([...featureLanguages]),
learning: sortLanguages([...learningLanguages]),
localisation: sortLanguages(collectLanguages<LocalisationLanguage>(localisationLanguages)),
translation: sortLanguages(collectLanguages<TranslationLanguage>(translationLanguages)),
},
locales: {
discord: Object.values(localisationLanguageToLocale.discord) as DiscordLocale[],
Expand Down
24 changes: 24 additions & 0 deletions source/constants/languages/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,28 @@ const localeToLanguage = {
eld: Object.mirror(languageToLocale.eld),
};

function isCLDLanguage(language: string): language is CLDLanguage {
return language in languageToLocale.cld;
}

function isTinyLDLanguage(language: string): language is TinyLDLanguage {
return language in languageToLocale.tinyld;
}

function isFastTextLanguage(language: string): language is FastTextLanguage {
return language in languageToLocale.fasttext;
}

function isELDLanguage(language: string): language is ELDLanguage {
return language in languageToLocale.eld;
}

function isDetectionLanguage(language: string): language is DetectionLanguage {
return (
isCLDLanguage(language) || isTinyLDLanguage(language) || isFastTextLanguage(language) || isELDLanguage(language)
);
}

function isCLDLocale(locale: string): locale is CLDLocale {
return locale in localeToLanguage.cld;
}
Expand Down Expand Up @@ -1013,6 +1035,7 @@ function getELDLanguageByLocale(locale: ELDLocale): ELDLanguage {
}

export {
isDetectionLanguage,
getTinyLDLanguageByLocale,
isTinyLDLocale,
isCLDLocale,
Expand All @@ -1021,6 +1044,7 @@ export {
getFastTextLanguageByLocale,
isELDLocale,
getELDLanguageByLocale,
languages,
};
export type {
Detector,
Expand Down
Loading