report options when given ambiguous command, make .dict report which word the definition is for

This commit is contained in:
Ryan Hitchman 2010-07-08 11:22:43 -06:00
parent 3e9708cc79
commit b0259336cd
2 changed files with 11 additions and 5 deletions

View File

@ -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)

View File

@ -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: