Mercurial > xib
changeset 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 | 11717d14e22f |
children | 64a0e9636ae6 |
files | bot.py start_bots_from_xml_config.py |
diffstat | 2 files changed, 37 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/bot.py +++ b/bot.py @@ -38,6 +38,7 @@ class Bot(threading.Thread): def __init__(self, jid, password, nickname, admins_jid=[], error_fd=sys.stderr, debug=False): threading.Thread.__init__(self) self.halt = False + self.bridges = [] self.bare_jid = xmpp.protocol.JID(jid=jid) self.bare_jid.setResource('') self.nickname = nickname @@ -45,7 +46,6 @@ class Bot(threading.Thread): self.error_fd = error_fd self.debug = debug self.admins_jid = admins_jid - self.bridges = [] self.xmpp_connections = {} self.irc = irclib.IRC() self.irc.bot = self
--- a/start_bots_from_xml_config.py +++ b/start_bots_from_xml_config.py @@ -42,43 +42,43 @@ for bot_el in config.getElementsByTagNam bots_jids.append(bot_el.getAttribute('jid')) + +bots = [] +for bot_el in config.getElementsByTagName('bot'): + debug = False + if bot_el.hasAttribute('debug'): + if bot_el.getAttribute('debug') == 'true': + debug = True + admins_jid = [] + for admin_el in bot_el.getElementsByTagName('admin'): + if admin_el.hasAttribute('jid'): + admins_jid.append(admin_el.getAttribute('jid')) + bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug) + bots.append(bot) + for bridge_el in bot_el.getElementsByTagName('bridge'): + xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0] + irc = bridge_el.getElementsByTagName('irc')[0] + + irc_connection_interval = 1 + if irc.hasAttribute('connection_interval'): + try: + irc_connection_interval = float(irc.getAttribute('connection_interval')) + except ValueError: + print '[Error] the value of connection_interval must be a number' + + if bridge_el.hasAttribute('say_level'): + say_level = bridge_el.getAttribute('say_level') + else: + say_level = 'all' + + if bridge_el.hasAttribute('mode'): + mode = bridge_el.getAttribute('mode') + else: + mode = 'normal' + + bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval) + try: - bots = [] - for bot_el in config.getElementsByTagName('bot'): - debug = False - if bot_el.hasAttribute('debug'): - if bot_el.getAttribute('debug') == 'true': - debug = True - admins_jid = [] - for admin_el in bot_el.getElementsByTagName('admin'): - if admin_el.hasAttribute('jid'): - admins_jid.append(admin_el.getAttribute('jid')) - bot = Bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), admins_jid=admins_jid, debug=debug) - bots.append(bot) - for bridge_el in bot_el.getElementsByTagName('bridge'): - xmpp_room = bridge_el.getElementsByTagName('xmpp-room')[0] - irc = bridge_el.getElementsByTagName('irc')[0] - - irc_connection_interval = 1 - if irc.hasAttribute('connection_interval'): - try: - irc_connection_interval = float(irc.getAttribute('connection_interval')) - except ValueError: - print '[Error] the value of connection_interval must be a number' - - if bridge_el.hasAttribute('say_level'): - say_level = bridge_el.getAttribute('say_level') - else: - say_level = 'all' - - if bridge_el.hasAttribute('mode'): - mode = bridge_el.getAttribute('mode') - else: - mode = 'normal' - - bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval) - - if len(bots) == 0: print 'No bots in the configuration file, exiting ...' exit(0)