From b0259336cd515bcdaf79b2b3fac62710807999bc Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Thu, 8 Jul 2010 11:22:43 -0600 Subject: [PATCH] report options when given ambiguous command, make .dict report which word the definition is for --- core/main.py | 8 +++++++- plugins/dictionary.py | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/main.py b/core/main.py index 51f8759..c363f9d 100644 --- a/core/main.py +++ b/core/main.py @@ -129,6 +129,8 @@ def match_command(command): prefix = filter(lambda x: x.startswith(command), commands) if len(prefix) == 1: return prefix[0] + elif prefix: + return prefix return command @@ -156,7 +158,11 @@ def main(conn, out): trigger = m.group(1).lower() command = match_command(trigger) - if command in bot.commands: + if isinstance(command, list): # multiple potential matches + input = Input(conn, *out) + input.reply("did you mean %s or %s?" % + (', '.join(command[:-1]), command[-1])) + elif command in bot.commands: input = Input(conn, *out) input.trigger = trigger input.inp_unstripped = m.group(2) diff --git a/plugins/dictionary.py b/plugins/dictionary.py index 32e9010..755e98e 100644 --- a/plugins/dictionary.py +++ b/plugins/dictionary.py @@ -43,11 +43,11 @@ def define(inp): return 'No results for ' + inp def format_output(show_examples): - result = '' - - correction = h.xpath('//span[@class="correct-word"]') + result = '%s: ' % h.xpath('//dt[@class="title-word"]/a/text()')[0] + + correction = h.xpath('//span[@class="correct-word"]/text()') if correction: - result = 'definition for "%s": ' % correction[0].text + result = 'definition for "%s": ' % correction[0] sections = [] for section in definition: