comparison start_bots_from_xml_config.py @ 180:102f895347ff

added a required "importance" argument to Bot.error() Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 13 Feb 2010 16:32:28 +0100
parents 64a0e9636ae6
children
comparison
equal deleted inserted replaced
179:f6c6708c6c0e 180:102f895347ff
20 from xml.dom.minidom import parse 20 from xml.dom.minidom import parse
21 from time import sleep 21 from time import sleep
22 import sys 22 import sys
23 import traceback 23 import traceback
24 24
25 from admin import Admin
25 from bot import Bot 26 from bot import Bot
27 import say_levels
26 28
27 29
28 try: 30 try:
29 if len(sys.argv) > 1: 31 if len(sys.argv) > 1:
30 config = parse(sys.argv[1]) 32 config = parse(sys.argv[1])
47 for bot_el in config.getElementsByTagName('bot'): 49 for bot_el in config.getElementsByTagName('bot'):
48 debug = False 50 debug = False
49 if bot_el.hasAttribute('debug'): 51 if bot_el.hasAttribute('debug'):
50 if bot_el.getAttribute('debug') == 'true': 52 if bot_el.getAttribute('debug') == 'true':
51 debug = True 53 debug = True
52 admins_jid = [] 54
55 admins = []
53 for admin_el in bot_el.getElementsByTagName('admin'): 56 for admin_el in bot_el.getElementsByTagName('admin'):
54 if admin_el.hasAttribute('jid'): 57 if admin_el.hasAttribute('jid'):
55 admins_jid.append(admin_el.getAttribute('jid')) 58 admin = Admin()
56 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug) 59 admin.jid = admin_el.getAttribute('jid')
60 if admin_el.hasAttribute('say_level'):
61 admin.say_level = say_levels.get(admin_el.getAttribute('say_level'))
62 else:
63 admin.say_level = say_levels.warning
64 admins.append(admin)
65
66 bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins=admins, debug=debug)
57 bots.append(bot) 67 bots.append(bot)
58 for bridge_el in bot_el.getElementsByTagName('bridge'): 68 for bridge_el in bot_el.getElementsByTagName('bridge'):
59 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0] 69 xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0]
60 irc = bridge_el.getElementsByTagName('irc')[0] 70 irc = bridge_el.getElementsByTagName('irc')[0]
61 71
69 irc_charsets = irc.getAttribute('charsets').split() 79 irc_charsets = irc.getAttribute('charsets').split()
70 else: 80 else:
71 irc_charsets = None 81 irc_charsets = None
72 82
73 if bridge_el.hasAttribute('say_level'): 83 if bridge_el.hasAttribute('say_level'):
74 say_level = bridge_el.getAttribute('say_level') 84 say_level = say_levels.get(bridge_el.getAttribute('say_level'))
75 else: 85 else:
76 say_level = 'all' 86 say_level = say_levels.nothing
77 87
78 if bridge_el.hasAttribute('mode'): 88 if bridge_el.hasAttribute('mode'):
79 mode = bridge_el.getAttribute('mode') 89 mode = bridge_el.getAttribute('mode')
80 else: 90 else:
81 mode = 'normal' 91 mode = 'bypass'
82 92
83 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval, irc_charsets=irc_charsets) 93 bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval, irc_charsets=irc_charsets)
84 94
85 try: 95 try:
86 if len(bots) == 0: 96 if len(bots) == 0: