Mercurial > xib
changeset 150:e0eea72ea493
new bridge attribute "irc_connection_interval" (in seconds)
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 17 Jan 2010 21:14:23 +0100 |
parents | 332bb2e8e71e |
children | a04840ad92b7 |
files | README bridge.py example_config.xml participant.py start_bots_from_xml_config.py |
diffstat | 5 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/README +++ b/README @@ -23,6 +23,7 @@ Changaco <changaco@changaco.net> > 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
--- 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)
--- a/example_config.xml +++ b/example_config.xml @@ -10,7 +10,7 @@ </bridge> <bridge mode='minimal' say_level='nothing'> <xmpp-room jid='room@chat.example.com'/> - <irc chan='#chan' server='irc.example.org'/> + <irc chan='#chan' server='irc.example.org' connection_interval='2'/> <!-- connection_interval is in seconds --> </bridge> </bot> <!-- WARNING: do NOT start two bots with the same JID or the same nickname -->
--- 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)
--- 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: