From 05fc3a3e4aa982703b77a48e0fc3f3c30d2aed8a Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 21 Sep 2014 22:51:25 -0500 Subject: [PATCH] Fix handling of mulilingual defines. --- earwigbot/commands/dictionary.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/earwigbot/commands/dictionary.py b/earwigbot/commands/dictionary.py index acc74b4..9c136b4 100644 --- a/earwigbot/commands/dictionary.py +++ b/earwigbot/commands/dictionary.py @@ -51,9 +51,6 @@ class Dictionary(Command): except exceptions.SiteNotFoundError: site = self.bot.wiki.add_site(project="wiktionary", lang=lang) - multilingual = "#" in term - if multilingual: - lang_requested = term.rsplit("#", 1)[1] page = site.get_page(term, follow_redirects=True) try: entry = page.get() @@ -68,11 +65,17 @@ class Dictionary(Command): if not languages: return u"Couldn't parse {0}!".format(page.url) + if "#" in term: # Requesting a specific language + lang = term.rsplit("#", 1)[1] + if lang not in languages: + resp = u"Language {0} not found in definition." + return resp.format(lang) + definition = self.get_definition(languages[lang], level) + return u"({0}) {1}".format(lang, definition) + result = [] for lang, section in sorted(languages.items()): definition = self.get_definition(section, level) - if multilingual and lang == lang_requested: - return u"({0}) {1}".format(lang, definition) result.append(u"({0}) {1}".format(lang, definition)) return u"; ".join(result)