comparison bot.py @ 133:e662ff6ecf50

added change-bridge-mode command Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Fri, 15 Jan 2010 16:32:45 +0100
parents 52d94261a406
children 931a5edc7971
comparison
equal deleted inserted replaced
132:6a6885dbed25 133:e662ff6ecf50
35 35
36 36
37 class Bot(threading.Thread): 37 class Bot(threading.Thread):
38 38
39 commands = ['xmpp-participants', 'irc-participants', 'bridges'] 39 commands = ['xmpp-participants', 'irc-participants', 'bridges']
40 admin_commands = ['add-bridge', 'add-xmpp-admin', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge'] 40 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridge-mode', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge']
41 41
42 def __init__(self, jid, password, nickname, admins_jid=[], error_fd=sys.stderr, debug=False): 42 def __init__(self, jid, password, nickname, admins_jid=[], error_fd=sys.stderr, debug=False):
43 threading.Thread.__init__(self) 43 threading.Thread.__init__(self)
44 self.bare_jid = xmpp.protocol.JID(jid=jid) 44 self.bare_jid = xmpp.protocol.JID(jid=jid)
45 self.bare_jid.setResource('') 45 self.bare_jid.setResource('')
921 elif command == 'halt': 921 elif command == 'halt':
922 self.stop() 922 self.stop()
923 return 923 return
924 924
925 925
926 elif command in ['remove-bridge', 'restart-bridge', 'stop-bridge']: 926 elif command in ['change-bridge-mode', 'remove-bridge', 'restart-bridge', 'stop-bridge']:
927 # we need to know which bridge the command is for 927 # we need to know which bridge the command is for
928 if len(args_array) == 0: 928 if len(args_array) == 0:
929 if isinstance(participant, Participant): 929 if isinstance(participant, Participant):
930 b = participant.bridge 930 b = participant.bridge
931 else: 931 else:
945 elif len(bridges) == 1: 945 elif len(bridges) == 1:
946 b = bridges[0] 946 b = bridges[0]
947 elif len(bridges) > 1: 947 elif len(bridges) > 1:
948 return 'More than one bridge matches "'+args_array[0]+'", please be more specific. '+self.respond('bridges') 948 return 'More than one bridge matches "'+args_array[0]+'", please be more specific. '+self.respond('bridges')
949 949
950 if command == 'remove-bridge': 950 if command == 'change-bridge-mode':
951 new_mode = args_array[1]
952 if not new_mode in Bridge._modes:
953 return '"'+new_mode+'" is not a valid mode, list of modes: '+' '.join(Bridge._modes)
954 r = b.changeMode(new_mode)
955 if r:
956 return r
957 return 'Mode changed.'
958 elif command == 'remove-bridge':
951 self.removeBridge(b) 959 self.removeBridge(b)
952 return 'Bridge removed.' 960 return 'Bridge removed.'
953 elif command == 'restart-bridge': 961 elif command == 'restart-bridge':
954 b.restart() 962 b.restart()
955 return 'Bridge restarted.' 963 return 'Bridge restarted.'