Mercurial > xib
comparison commands.py @ 216:d527d7b75f56
merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 06 Mar 2010 22:55:47 +0100 |
parents | 2a81c480439a |
children | 87fa6bc893de |
comparison
equal
deleted
inserted
replaced
215:b900585bdbbb | 216:d527d7b75f56 |
---|---|
51 return globals()[command_func](bot, command, args_array, bridge) | 51 return globals()[command_func](bot, command, args_array, bridge) |
52 | 52 |
53 | 53 |
54 def _find_bridges(bot, args_array): | 54 def _find_bridges(bot, args_array): |
55 ret = '' | 55 ret = '' |
56 b = [] | 56 matches = [] |
57 for arg in args_array: | 57 for arg in args_array: |
58 try: | 58 try: |
59 bn = int(arg) | 59 bn = int(arg) |
60 if bn < 1: | 60 if bn < 1: |
61 raise IndexError | 61 raise IndexError |
62 b.append(bot.bridges[bn-1]) | 62 matches.append(bot.bridges[bn-1]) |
63 except IndexError: | 63 except IndexError: |
64 ret += '\nInvalid bridge number "'+str(bn)+'".' | 64 ret += '\nInvalid bridge number "'+str(bn)+'".' |
65 except ValueError: | 65 except ValueError: |
66 found_bridges = bot.find_bridges(arg) | 66 found_bridges = [b for b in bot.iter_bridges(patterns=[arg])] |
67 if len(found_bridges) == 0: | 67 if len(found_bridges) == 0: |
68 ret += '\nNo bridge found matching "'+arg+'".' | 68 ret += '\nNo bridge found matching "'+arg+'".' |
69 else: | 69 else: |
70 b.extend(found_bridges) | 70 matches.extend(found_bridges) |
71 | 71 |
72 if ret != '' or len(b) == 0: | 72 if ret != '' or len(matches) == 0: |
73 if ret != '': | 73 if ret != '': |
74 ret += '\n\n' | 74 ret += '\n\n' |
75 ret += bridges(bot, 'bridges', [], None)+'\n\n' | 75 ret += bridges(bot, 'bridges', [], None)+'\n\n' |
76 | 76 |
77 return (b, ret) | 77 return (matches, ret) |
78 | 78 |
79 | 79 |
80 def add_bridge(bot, command, args_array, bridge): | 80 def add_bridge(bot, command, args_array, bridge): |
81 parser = ArgumentParser(prog=command) | 81 parser = ArgumentParser(prog=command) |
82 parser.add_argument('xmpp_room_jid', type=str) | 82 parser.add_argument('xmpp_room_jid', type=str) |