From 9f52f0376ea3d5d0b2a79adaf73abbb33730471f Mon Sep 17 00:00:00 2001 From: Eevee Date: Sat, 27 Mar 2010 00:25:18 -0700 Subject: [PATCH] jdic should not crash on no results. --- plugins/WWWJDIC/plugin.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/WWWJDIC/plugin.py b/plugins/WWWJDIC/plugin.py index f141604..5e548a3 100644 --- a/plugins/WWWJDIC/plugin.py +++ b/plugins/WWWJDIC/plugin.py @@ -78,6 +78,24 @@ class WWWJDIC(callbacks.Plugin): # So grab everything from that pre tag, split by lines, and spit it # back out. soup = BeautifulSoup(res) + if not soup.pre: + # Nothing found? + reply = u"Hmm, nothing found -- but I only look for exact " \ + "matches and common words. Try denshi jisho directly: " + + jisho_url = u"http://jisho.org/words?jap={jap}&eng={eng}&dict=edict" + if thing[0] in ('@', '#'): + # Prefixes for roomaji + reply += jisho_url.format(jap=thing[1:], eng=u'') + # wtf why is any() overridden + elif filter(lambda c: ord(c) > 256, thing): + reply += jisho_url.format(jap=thing, eng=u'') + else: + reply += jisho_url.format(jap=u'', eng=thing) + + self._reply(irc, reply) + return + thing_ct = 0 for entry in soup.pre.string.splitlines(): entry = entry.strip() -- 2.7.4