Mercurial > xib
comparison commands.py @ 143:61d7cae1d15d
added 3 commands: connections, irc-connections and xmpp-connections
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 17 Jan 2010 12:31:59 +0100 |
parents | 8c6184411ec7 |
children | 0a8f96a1d200 |
comparison
equal
deleted
inserted
replaced
142:8c6184411ec7 | 143:61d7cae1d15d |
---|---|
23 del muc | 23 del muc |
24 | 24 |
25 from bridge import Bridge | 25 from bridge import Bridge |
26 | 26 |
27 | 27 |
28 commands = ['xmpp-participants', 'irc-participants', 'bridges'] | 28 commands = ['xmpp-participants', 'irc-participants', 'xmpp-connections', 'irc-connections', 'connections', 'bridges'] |
29 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridge-mode', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge'] | 29 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridge-mode', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge'] |
30 | 30 |
31 def execute(bot, command_line, bot_admin, bridge): | 31 def execute(bot, command_line, bot_admin, bridge): |
32 ret = '' | 32 ret = '' |
33 command = shlex.split(command_line) | 33 command = shlex.split(command_line) |
145 if r: | 145 if r: |
146 return r | 146 return r |
147 return 'Mode changed.' | 147 return 'Mode changed.' |
148 | 148 |
149 | 149 |
150 def connections(bot, command, args_array, bot_admin, bridge): | |
151 parser = ArgumentParser(prog=command) | |
152 parser.add_argument('--verbose', '-v', default=False, action='store_true') | |
153 try: | |
154 args = parser.parse_args(args_array) | |
155 except ArgumentParser.ParseException as e: | |
156 return '\n'+e.args[1] | |
157 return irc_connections(bot, 'irc-connections', args_array, bot_admin, bridge)+'\n'+xmpp_connections(bot, 'xmpp-connections', args_array, bot_admin, bridge) | |
158 | |
159 | |
150 def halt(bot, command, args_array, bot_admin, bridge): | 160 def halt(bot, command, args_array, bot_admin, bridge): |
151 bot.stop() | 161 bot.stop() |
152 return | 162 return |
163 | |
164 | |
165 def irc_connections(bot, command, args_array, bot_admin, bridge): | |
166 parser = ArgumentParser(prog=command) | |
167 parser.add_argument('--verbose', '-v', default=False, action='store_true') | |
168 try: | |
169 args = parser.parse_args(args_array) | |
170 except ArgumentParser.ParseException as e: | |
171 return '\n'+e.args[1] | |
172 n = len(bot.irc.connections) | |
173 if args.verbose: | |
174 ret = 'List of IRC connections ('+str(n)+'):' | |
175 for c in bot.irc.connections: | |
176 ret += '\n\t'+str(c) | |
177 else: | |
178 ret = 'Number of IRC connections: '+str(n) | |
179 return ret | |
153 | 180 |
154 | 181 |
155 def irc_participants(bot, command, args_array, bot_admin, bridge): | 182 def irc_participants(bot, command, args_array, bot_admin, bridge): |
156 ret = '' | 183 ret = '' |
157 if not bridge: | 184 if not bridge: |
181 def stop_bridge(bot, command, args_array, bot_admin, bridge): | 208 def stop_bridge(bot, command, args_array, bot_admin, bridge): |
182 bridge.stop() | 209 bridge.stop() |
183 return 'Bridge stopped.' | 210 return 'Bridge stopped.' |
184 | 211 |
185 | 212 |
213 def xmpp_connections(bot, command, args_array, bot_admin, bridge): | |
214 parser = ArgumentParser(prog=command) | |
215 parser.add_argument('--verbose', '-v', default=False, action='store_true') | |
216 try: | |
217 args = parser.parse_args(args_array) | |
218 except ArgumentParser.ParseException as e: | |
219 return '\n'+e.args[1] | |
220 n = len(bot.xmpp_connections) | |
221 if args.verbose: | |
222 ret = 'List of XMPP connections ('+str(n)+'):' | |
223 for nickname in bot.xmpp_connections.iterkeys(): | |
224 ret += '\n\t'+nickname | |
225 else: | |
226 ret = 'Number of XMPP connections: '+str(n) | |
227 return ret | |
228 | |
229 | |
186 def xmpp_participants(bot, command, args_array, bot_admin, bridge): | 230 def xmpp_participants(bot, command, args_array, bot_admin, bridge): |
187 ret = '' | 231 ret = '' |
188 if not bridge: | 232 if not bridge: |
189 for b in bot.bridges: | 233 for b in bot.bridges: |
190 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) | 234 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) |