Mercurial > xib
comparison commands.py @ 153:0a8f96a1d200
added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 17 Jan 2010 22:55:26 +0100 |
parents | 61d7cae1d15d |
children | 63db565438bd |
comparison
equal
deleted
inserted
replaced
152:17305e57f71d | 153:0a8f96a1d200 |
---|---|
24 | 24 |
25 from bridge import Bridge | 25 from bridge import Bridge |
26 | 26 |
27 | 27 |
28 commands = ['xmpp-participants', 'irc-participants', 'xmpp-connections', 'irc-connections', 'connections', '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', 'debug', '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) |
34 if len(command) > 1: | 34 if len(command) > 1: |
155 except ArgumentParser.ParseException as e: | 155 except ArgumentParser.ParseException as e: |
156 return '\n'+e.args[1] | 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) | 157 return irc_connections(bot, 'irc-connections', args_array, bot_admin, bridge)+'\n'+xmpp_connections(bot, 'xmpp-connections', args_array, bot_admin, bridge) |
158 | 158 |
159 | 159 |
160 def debug(bot, command, args_array, bot_admin, bridge): | |
161 parser = ArgumentParser(prog=command) | |
162 parser.add_argument('mode', choices=['on', 'off']) | |
163 try: | |
164 args = parser.parse_args(args_array) | |
165 except ArgumentParser.ParseException as e: | |
166 if len(args_array) == 0: | |
167 if bot.debug: | |
168 return 'Debugging is on' | |
169 else: | |
170 return 'Debugging is off' | |
171 else: | |
172 return '\n'+e.args[1] | |
173 | |
174 if args.mode == 'on': | |
175 bot.debug = True | |
176 return 'Debugging is now on' | |
177 else: | |
178 bot.debug = False | |
179 return 'Debugging is now off' | |
180 | |
181 | |
160 def halt(bot, command, args_array, bot_admin, bridge): | 182 def halt(bot, command, args_array, bot_admin, bridge): |
161 bot.stop() | 183 bot.stop() |
162 return | 184 return |
163 | 185 |
164 | 186 |