view start_bots_from_xml_config.py @ 12:fd695e2b5283

Fixed bridge mode-switching Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 17 Aug 2009 01:05:30 +0200
parents 4c842d23d4ce
children a9077fa9cac9
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-


# *** LICENSE ***
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


from bot import bot
from time import sleep
from xml.dom.minidom import parse


bots = []

try:
	config = parse('config.xml')
except IOError:
	print 'Error: config.xml is missing or cannot be read'
	quit(1)

bots_jids = []
for bot_el in config.getElementsByTagName('bot'):
	if bot_el.getAttribute('jid') in bots_jids:
		print 'Error: you cannot have two bots using the same JID'
		quit(2)
	bots_jids.append(bot_el.getAttribute('jid'))
for bot_el in config.getElementsByTagName('bot'):
	debug = False
	if bot_el.hasAttribute('debug'):
		if bot_el.getAttribute('debug') == 'true':
			debug = True
	bot_ = bot(bot_el.getAttribute('jid'), bot_el.getAttribute('password'), bot_el.getAttribute('nickname'), 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]
		bridge_ = bot_.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'))


try:
	while True:
		sleep(1)
except:
	del bots
	quit(3)