comparison start_bots_from_xml_config.py @ 171:489c157d9e82

display error when bot creation fails Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 01 Feb 2010 23:02:50 +0100
parents c021656e4c54
children 64a0e9636ae6
comparison
equal deleted inserted replaced
170:11717d14e22f 171:489c157d9e82
40 print '[Error] you cannot have two bots using the same JID' 40 print '[Error] you cannot have two bots using the same JID'
41 quit(2) 41 quit(2)
42 bots_jids.append(bot_el.getAttribute('jid')) 42 bots_jids.append(bot_el.getAttribute('jid'))
43 43
44 44
45
46 bots = []
47 for bot_el in config.getElementsByTagName('bot'):
48 debug = False
49 if bot_el.hasAttribute('debug'):
50 if bot_el.getAttribute('debug') == 'true':
51 debug = True
52 admins_jid = []
53 for admin_el in bot_el.getElementsByTagName('admin'):
54 if admin_el.hasAttribute('jid'):
55 admins_jid.append(admin_el.getAttribute('jid'))
56 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug)
57 bots.append(bot)
58 for bridge_el in bot_el.getElementsByTagName('bridge'):
59 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
60 irc = bridge_el.getElementsByTagName('irc')[0]
61
62 irc_connection_interval = 1
63 if irc.hasAttribute('connection_interval'):
64 try:
65 irc_connection_interval = float(irc.getAttribute('connection_interval'))
66 except ValueError:
67 print '[Error] the value of connection_interval must be a number'
68
69 if bridge_el.hasAttribute('say_level'):
70 say_level = bridge_el.getAttribute('say_level')
71 else:
72 say_level = 'all'
73
74 if bridge_el.hasAttribute('mode'):
75 mode = bridge_el.getAttribute('mode')
76 else:
77 mode = 'normal'
78
79 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval)
80
45 try: 81 try:
46 bots = []
47 for bot_el in config.getElementsByTagName('bot'):
48 debug = False
49 if bot_el.hasAttribute('debug'):
50 if bot_el.getAttribute('debug') == 'true':
51 debug = True
52 admins_jid = []
53 for admin_el in bot_el.getElementsByTagName('admin'):
54 if admin_el.hasAttribute('jid'):
55 admins_jid.append(admin_el.getAttribute('jid'))
56 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug)
57 bots.append(bot)
58 for bridge_el in bot_el.getElementsByTagName('bridge'):
59 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
60 irc = bridge_el.getElementsByTagName('irc')[0]
61
62 irc_connection_interval = 1
63 if irc.hasAttribute('connection_interval'):
64 try:
65 irc_connection_interval = float(irc.getAttribute('connection_interval'))
66 except ValueError:
67 print '[Error] the value of connection_interval must be a number'
68
69 if bridge_el.hasAttribute('say_level'):
70 say_level = bridge_el.getAttribute('say_level')
71 else:
72 say_level = 'all'
73
74 if bridge_el.hasAttribute('mode'):
75 mode = bridge_el.getAttribute('mode')
76 else:
77 mode = 'normal'
78
79 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval)
80
81
82 if len(bots) == 0: 82 if len(bots) == 0:
83 print 'No bots in the configuration file, exiting ...' 83 print 'No bots in the configuration file, exiting ...'
84 exit(0) 84 exit(0)
85 85
86 while True: 86 while True: