From 8d601d52bdaeb7fe4d59ddd1dec241adfad3a33e Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Wed, 21 Sep 2011 22:42:06 -0400 Subject: [PATCH] add ipv6 support --- __init__.py | 2 +- irc.py | 12 ++++++++---- phenny | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 03a82e8..185973a 100755 --- a/__init__.py +++ b/__init__.py @@ -34,7 +34,7 @@ def run_phenny(config): def connect(config): p = bot.Phenny(config) - p.run(config.host, config.port, config.ssl) + p.run(config.host, config.port, config.ssl, config.ipv6) try: Watcher() except Exception, e: diff --git a/irc.py b/irc.py index 5645046..0c1ce2c 100755 --- a/irc.py +++ b/irc.py @@ -67,14 +67,18 @@ class Bot(asynchat.async_chat): self.__write(args, text) except Exception, e: pass - def run(self, host, port=6667, ssl=False): - self.initiate_connect(host, port, ssl) + def run(self, host, port=6667, ssl=False, ipv6=False): + self.initiate_connect(host, port, ssl, ipv6) - def initiate_connect(self, host, port, ssl): + def initiate_connect(self, host, port, ssl, ipv6): if self.verbose: message = 'Connecting to %s:%s...' % (host, port) print >> sys.stderr, message, - self.create_socket(socket.AF_INET, socket.SOCK_STREAM) + if ipv6 and socket.has_ipv6: + af = socket.AF_INET6 + else: + af = socket.AF_INET + self.create_socket(af, socket.SOCK_STREAM) self.connect((host, port)) if ssl: import ssl diff --git a/phenny b/phenny index dc8eac6..32d3253 100755 --- a/phenny +++ b/phenny @@ -29,6 +29,7 @@ def create_default_config(fn): host = 'irc.example.net' port = 6667 ssl = False + ipv6 = False channels = ['#example', '#test'] owner = 'yournickname' @@ -144,6 +145,9 @@ def main(argv=None): if not hasattr(module, 'ssl'): module.ssl = False + if not hasattr(module, 'ipv6'): + module.ipv6 = False + if not hasattr(module, 'password'): module.password = None