transcribe: refuse to auto-detect very short text

langdetect labels 'ok' as Slovak with high confidence, so the probability gate
alone was not enough. Require 12+ characters before guessing, and document the
translate command in the README.
This commit is contained in:
2026-11-02 16:07:16 -06:00
parent 95b14dc8c1
commit eb4f7139a2
2 changed files with 10 additions and 0 deletions
+7
View File
@@ -285,6 +285,13 @@ class Transcribe(commands.Cog):
"Language detection isn't installed. Reinstall the cog so its "
"requirements install, or use `[p]translate <target> from <source>`."
)
# Short strings get confident nonsense out of langdetect ("ok" reads as
# Slovak), so require enough text before trusting a guess.
if len(text.strip()) < 12:
raise ServiceError(
"That's too short to identify the language reliably. "
"Use `[p]translate <target> from <source>`."
)
try:
guesses = detect_langs(text)
except LangDetectException as exc: