# HG changeset patch # User Charly COSTE # Date 1263759263 -3600 # Node ID e0eea72ea493f462f341c01932e6503c3e798554 # Parent 332bb2e8e71ed06d5d3a8bc46747ad1c8d109dbc new bridge attribute "irc_connection_interval" (in seconds) Signed-off-by: Charly COSTE diff --git a/README b/README --- a/README +++ b/README @@ -23,6 +23,7 @@ Changaco > Changelog: 0.3: - new mode "bypass", this allows to connect more than one bot for each IRC server without having so many nickname conflicts that the bot looks like it is in limited mode + - new bridge attribute "irc_connection_interval" (in seconds) 0.2: - fixed many many bugs - new command system diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -43,12 +43,13 @@ class Bridge: class NoSuchParticipantException(Exception): pass - def __init__(self, owner_bot, xmpp_room_jid, irc_room, irc_server, mode, say_level, irc_port=6667): + def __init__(self, owner_bot, xmpp_room_jid, irc_room, irc_server, mode, say_level, irc_port=6667, irc_connection_interval=1): """Create a new bridge.""" self.bot = owner_bot self.irc_server = irc_server self.irc_port = irc_port self.irc_room = irc_room.lower() + self.irc_connection_interval = irc_connection_interval self.xmpp_room_jid = xmpp_room_jid if hasattr(self.__class__, '_'+say_level): self.say_level = getattr(self.__class__, '_'+say_level) diff --git a/example_config.xml b/example_config.xml --- a/example_config.xml +++ b/example_config.xml @@ -10,7 +10,7 @@ - + diff --git a/participant.py b/participant.py --- a/participant.py +++ b/participant.py @@ -108,7 +108,7 @@ class Participant: def createDuplicateOnIRC(self): if isinstance(self.xmpp_c, xmpp.client.Client) or isinstance(self.irc_connection, ServerConnection): return - sleep(1) # try to prevent "reconnecting too fast" shit + sleep(self.bridge.irc_connection_interval) # to prevent "reconnecting too fast" self.irc_connection = self.bridge.bot.irc.open_connection(self.bridge.irc_server, self.bridge.irc_port, self.duplicate_nickname) self.irc_connection.connect(nick_callback=self._irc_nick_callback) diff --git a/start_bots_from_xml_config.py b/start_bots_from_xml_config.py --- a/start_bots_from_xml_config.py +++ b/start_bots_from_xml_config.py @@ -58,6 +58,12 @@ try: 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' say_level = 'all' if bridge_el.hasAttribute('say_level'): say_level = bridge_el.getAttribute('say_level') @@ -65,7 +71,7 @@ try: mode = bridge_el.getAttribute('mode') else: mode = 'normal' - bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level) + bot.new_bridge(xmpp_room.getAttribute('jid'), irc.getAttribute('chan'), irc.getAttribute('server'), mode, say_level, irc_connection_interval=irc_connection_interval) while True: