Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Commit

Permalink
Client supports connect timeout.
Browse files Browse the repository at this point in the history
Now, the irc client support a configurable connect timeout.
  • Loading branch information
s0undt3ch committed Apr 5, 2011
1 parent 030fc57 commit 4473ee0
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions girclib/client.py
Expand Up @@ -40,8 +40,9 @@ def __init__(self, host="", port=6667, nickname="girclib", username=None,
self.realname = realname
self.password = password

def connect(self):
BaseIRCClient.connect(self, self.host, self.port, use_ssl=False)
def connect(self, timeout=30):
BaseIRCClient.connect(self, self.host, self.port, use_ssl=False,
timeout=timeout)

class IRCClient(BasicIRCClient):
"""
Expand Down Expand Up @@ -232,13 +233,21 @@ def on_topic_changed(self, emitter, user=None, channel=None, new_topic=None):


if __name__ == '__main__':
import sys
import gevent
import logging
from girclib.helpers import setup_logging
format='%(asctime)s [%(lineno)-4s] %(levelname)-7.7s: %(message)s'
setup_logging(format, 5)
# client = IRCClient('irc.freenode.net', 6667, 'girclib', 'gIRClib')
client = IRCClient('localhost', 6665, 'girclib', 'gIRClib')
# log = logging.getLogger('gIRClib')

try:
host, port, channel = sys.argv[1:]
except ValueError:
print 'USAGE: %s %s <network> <port> <\#channel>' % (
sys.executable, sys.argv[0]
)
sys.exit(1)

setup_logging(level=logging.DEBUG)
client = IRCClient(host, int(port), 'girclib', 'gIRClib')

# Just for the fun, start telnet backdoor on port 2000
from gevent.backdoor import BackdoorServer
Expand All @@ -260,12 +269,13 @@ def on_rpl_endofnames(emitter, channel=None):
if nick == "girclib":
continue
client.ping(nick)
gevent.sleep(20) # Some networks require us to wait before another ping


@signals.on_signed_on.connect
def _on_motd(emitter):
log.info("Signed on. Let's join #ufs")
client.join("ufs")
log.info("Signed on. Let's join %s", channel)
client.join(channel)

@signals.on_disconnected.connect
def disconnected(emitter):
Expand Down

0 comments on commit 4473ee0

Please sign in to comment.