瀏覽代碼

Don't allow infinite retries.

tags/v0.1^2
Ben Kurtovic 12 年之前
父節點
當前提交
2252a34800
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. +5
    -5
      earwigbot/commands/dictionary.py

+ 5
- 5
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)


Loading…
取消
儲存