Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Make it possible to send any argument to the connect method when using SingleServerIRCBot #1

Merged
merged 2 commits into from over 2 years ago

2 participants

Emil Hesslow Peter Ruibal
Emil Hesslow

No description provided.

Emil Hesslow WizKid Generalise the arguments to SingleServerIRCBot so if connection argum…
…ents are added further down SingleServerIRCBot don't have to be updated
db3e86b
Peter Ruibal

I've recently become of a fan of the
dict(foo=bar) style of dictionaries than the {'foo': bar}

Either way works for me. Just wondering if you knew if there was any particular benefit to doing it one way vs. the other.

I just like {'foo': bar} more. Less to type :)

Peter Ruibal
Owner

we should probably bump minor version in irclib.py to 0, 5, 0 since this is a breaking change.

Emil Hesslow

These where the only places I found 0.4.8

Peter Ruibal fmoo merged commit 7b137c6 into from
Peter Ruibal fmoo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Nov 30, 2011
Emil Hesslow WizKid Generalise the arguments to SingleServerIRCBot so if connection argum…
…ents are added further down SingleServerIRCBot don't have to be updated
db3e86b
Dec 01, 2011
Emil Hesslow WizKid Bump version to 0.5.0 because the api changes in SingleServerIRCBot 1072d14
This page is out of date. Refresh to see the latest.
83 ircbot.py
@@ -42,37 +42,74 @@ class SingleServerIRCBot(SimpleIRCClient):
42 42 have operator or voice modes. The "database" is kept in the
43 43 self.channels attribute, which is an IRCDict of Channels.
44 44 """
45   - def __init__(self, server_list, nickname, realname, reconnection_interval=60, localaddress="", ipv6=0):
  45 + def __init__(self, server_list, connection_kwargs, reconnection_interval=60):
46 46 """Constructor for SingleServerIRCBot objects.
47 47
48 48 Arguments:
49 49
50   - server_list -- A list of tuples (server, port[, password[, ssl])
51   - that defines which servers the bot should try to
52   - connect to.
  50 + server_list -- A list of dicts containing connection arguments.
53 51
54   - nickname -- The bot's nickname.
55   -
56   - realname -- The bot's realname.
  52 + connection_kwargs -- Dict of connection arguments.
57 53
58 54 reconnection_interval -- How long the bot should wait
59 55 before trying to reconnect.
60 56
61   - dcc_connections -- A list of initiated/accepted DCC
62   - connections.
  57 + How a connection is made:
  58 +
  59 + When a connection is made the arguments from connection_kwargs are
  60 + used but then overridden by the arguments for the currect server.
  61 +
  62 + The only requirement is that all servers need to contain server and
  63 + port key and connection_kwargs need to contain nickname key
  64 +
  65 + Other than that you can send in anything that
  66 + SimpleIRCClient.connect() accept. This means that you don't have to
  67 + change this class if you change the arguments to
  68 + SimpleIRCClient.connect()
  69 +
  70 + Example:
  71 +
  72 + server_list = [
  73 + {
  74 + 'server': 'www.example1.com',
  75 + 'port': '6669',
  76 + },
  77 + {
  78 + 'server': 'www.example2.com',
  79 + 'port': '6669',
  80 + },
  81 + {
  82 + 'server': 'www.example3.com',
  83 + 'port': '6669',
  84 + 'ssl': False,
  85 + },
  86 + ]
  87 +
  88 + connection_kwargs = {
  89 + 'nickname': 'bot',
  90 + 'ssl': True,
  91 + }
  92 +
  93 + This config means that ssl will be used for example1 and 2 but not 3
  94 +
63 95 """
64 96
65 97 SimpleIRCClient.__init__(self)
66 98 self.channels = IRCDict()
67 99 self.server_list = server_list
  100 + self.connection_kwargs = connection_kwargs
  101 +
  102 + for server in self.server_list:
  103 + if not "server" in server or not "port" in server:
  104 + raise Exception("All servers need to contain a port and server")
  105 +
  106 + if not "nickname" in self.connection_kwargs:
  107 + raise Exception("connection_kwargs need to contain a nickname")
  108 +
68 109 if not reconnection_interval or reconnection_interval < 0:
69 110 reconnection_interval = 2**31
70 111 self.reconnection_interval = reconnection_interval
71 112
72   - self._nickname = nickname
73   - self._realname = realname
74   - self._localaddress = localaddress
75   - self._ipv6 = ipv6
76 113 for i in ["disconnect", "join", "kick", "mode",
77 114 "namreply", "nick", "part", "quit"]:
78 115 self.connection.add_global_handler(i,
@@ -87,21 +124,13 @@ def _connected_checker(self):
87 124
88 125 def _connect(self):
89 126 """[Internal]"""
90   - password = None
91   - ssl = False
92   - if len(self.server_list[0]) > 2:
93   - password = self.server_list[0][2]
94   - if len(self.server_list[0]) > 3:
95   - ssl = self.server_list[0][3]
  127 + kwargs = dict(
  128 + self.connection_kwargs.items() +
  129 + self.server_list[0].items()
  130 + )
  131 +
96 132 try:
97   - self.connect(self.server_list[0][0],
98   - self.server_list[0][1],
99   - self._nickname,
100   - password,
101   - ircname=self._realname,
102   - localaddress=self._localaddress,
103   - ipv6=self._ipv6,
104   - ssl=ssl)
  133 + self.connect(**kwargs)
105 134 except ServerConnectionError:
106 135 pass
107 136
2  irclib.py
@@ -71,7 +71,7 @@
71 71 import time
72 72 import types
73 73
74   -VERSION = 0, 4, 8
  74 +VERSION = 0, 5, 0
75 75 DEBUG = 0
76 76
77 77 # TODO
2  python-irclib.spec
... ... @@ -1,6 +1,6 @@
1 1 Summary: A set of Python modules for IRC support.
2 2 Name: python-irclib
3   -Version: 0.4.8
  3 +Version: 0.5.0
4 4 Release: 1
5 5 Group: Development/Libraries
6 6 License: LGPL
2  setup.py
@@ -2,7 +2,7 @@
2 2
3 3 from distutils.core import setup
4 4 setup(name="python-irclib",
5   - version="0.4.8",
  5 + version="0.5.0",
6 6 py_modules=["irclib", "ircbot"],
7 7 author="Joel Rosdahl",
8 8 author_email="joel@rosdahl.net",
10 testbot.py
@@ -30,8 +30,14 @@
30 30
31 31 class TestBot(SingleServerIRCBot):
32 32 def __init__(self, channel, nickname, server, port=6667, ssl=False):
33   - SingleServerIRCBot.__init__(self, [(server, port, None, ssl)],
34   - nickname, nickname)
  33 + SingleServerIRCBot.__init__(self, [{
  34 + 'server': server,
  35 + 'port': port,
  36 + 'ssl': ssl
  37 + }], {
  38 + 'nickname': nickname,
  39 + 'ircname': nickname
  40 + })
35 41 self.channel = channel
36 42
37 43 def on_nicknameinuse(self, c, e):

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.