From 2252a3480048566f1f7068a4720eb7905f8799b6 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 10 Jul 2012 00:04:44 -0400 Subject: [PATCH] Don't allow infinite retries. --- earwigbot/commands/dictionary.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/earwigbot/commands/dictionary.py b/earwigbot/commands/dictionary.py index 28e5db8..897ea60 100644 --- a/earwigbot/commands/dictionary.py +++ b/earwigbot/commands/dictionary.py @@ -45,7 +45,7 @@ class Dictionary(Command): else: self.reply(data, defined.encode("utf8")) - def define(self, term, lang): + def define(self, term, lang, tries=2): try: site = self.bot.wiki.get_site(project="wiktionary", lang=lang) except exceptions.SiteNotFoundError: @@ -55,10 +55,10 @@ class Dictionary(Command): try: entry = page.get() except (exceptions.PageNotFoundError, exceptions.InvalidPageError): - if term.lower() != term: - return self.define(term.lower(), lang) - if term.capitalize() != term: - return self.define(term.capitalize(), lang) + if term.lower() != term and tries: + return self.define(term.lower(), lang, tries - 1) + if term.capitalize() != term and tries: + return self.define(term.capitalize(), lang, tries - 1) return "no definition found." languages = self.get_languages(entry)