comparison start_bots_from_xml_config.py @ 17:32a35f7eff70

Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots. Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 20 Aug 2009 01:00:54 +0200
parents a9077fa9cac9
children c1b84196c100
comparison
equal deleted inserted replaced
16:0c4a7452d66c 17:32a35f7eff70
19 19
20 from bot import bot 20 from bot import bot
21 from time import sleep 21 from time import sleep
22 from xml.dom.minidom import parse 22 from xml.dom.minidom import parse
23 import sys 23 import sys
24 import traceback
24 25
25 26
26 bots = []
27 27
28 try: 28 try:
29 if len(sys.argv) > 1: 29 if len(sys.argv) > 1:
30 config = parse(sys.argv[1]) 30 config = parse(sys.argv[1])
31 else: 31 else:
38 for bot_el in config.getElementsByTagName('bot'): 38 for bot_el in config.getElementsByTagName('bot'):
39 if bot_el.getAttribute('jid') in bots_jids: 39 if bot_el.getAttribute('jid') in bots_jids:
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 for bot_el in config.getElementsByTagName('bot'):
44 debug = False
45 if bot_el.hasAttribute('debug'):
46 if bot_el.getAttribute('debug') == 'true':
47 debug = True
48 bot_ = bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), debug=debug)
49 bots.append(bot_)
50 for bridge_el in bot_el.getElementsByTagName('bridge'):
51 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
52 irc = bridge_el.getElementsByTagName('irc')[0]
53 bridge_ = bot_.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'))
54 43
55 44
56 try: 45 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 bot_ = bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), debug=debug)
53 bots.append(bot_)
54 for bridge_el in bot_el.getElementsByTagName('bridge'):
55 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
56 irc = bridge_el.getElementsByTagName('irc')[0]
57 say_participants_list = True
58 if bridge_el.hasAttribute('say_participants_list'):
59 if bridge_el.getAttribute('say_participants_list') == 'false':
60 say_participants_list = False
61 if bridge_el.hasAttribute('mode'):
62 mode = bridge_el.getAttribute('mode')
63 else:
64 mode = 'normal'
65 bridge_ = bot_.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_participants_list)
66
67
57 while True: 68 while True:
58 sleep(1) 69 sleep(1)
59 except: 70 except:
60 del bots 71 for bot in bots:
72 del bot
73 traceback.print_exc()
61 quit(3) 74 quit(3)