Arrange IRC server construction
reorder constructor argument to a more logical order on_connect can be a simple string or a callable
This commit is contained in:
parent
55b1eb5075
commit
e7fd7c5ec4
1 changed files with 14 additions and 9 deletions
|
@ -33,18 +33,18 @@ class IRC(SocketServer):
|
||||||
|
|
||||||
"""Concrete implementation of a connexion to an IRC server"""
|
"""Concrete implementation of a connexion to an IRC server"""
|
||||||
|
|
||||||
def __init__(self, owner, nick="nemubot", host="localhost", port=6667,
|
def __init__(self, host="localhost", port=6667, ssl=False, owner=None,
|
||||||
ssl=False, username=None, password=None, realname="Nemubot",
|
nick="nemubot", username=None, password=None,
|
||||||
encoding="utf-8", caps=None, channels=list(),
|
realname="Nemubot", encoding="utf-8", caps=None,
|
||||||
on_connect=None):
|
channels=list(), on_connect=None):
|
||||||
"""Prepare a connection with an IRC server
|
"""Prepare a connection with an IRC server
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
owner -- bot's owner
|
|
||||||
nick -- bot's nick
|
|
||||||
host -- host to join
|
host -- host to join
|
||||||
port -- port on the host to reach
|
port -- port on the host to reach
|
||||||
ssl -- is this server using a TLS socket
|
ssl -- is this server using a TLS socket
|
||||||
|
owner -- bot's owner
|
||||||
|
nick -- bot's nick
|
||||||
username -- the username as sent to server
|
username -- the username as sent to server
|
||||||
password -- if a password is required to connect to the server
|
password -- if a password is required to connect to the server
|
||||||
realname -- the bot's realname
|
realname -- the bot's realname
|
||||||
|
@ -60,7 +60,7 @@ class IRC(SocketServer):
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
self.realname = realname
|
self.realname = realname
|
||||||
|
|
||||||
self.id = self.username + "@" + host + ":" + port
|
self.id = self.username + "@" + host + ":" + str(port)
|
||||||
self.printer = IRCPrinter
|
self.printer = IRCPrinter
|
||||||
SocketServer.__init__(self, host=host, port=port, ssl=ssl)
|
SocketServer.__init__(self, host=host, port=port, ssl=ssl)
|
||||||
|
|
||||||
|
@ -128,7 +128,12 @@ class IRC(SocketServer):
|
||||||
def _on_connect(msg):
|
def _on_connect(msg):
|
||||||
# First, send user defined command
|
# First, send user defined command
|
||||||
if on_connect is not None:
|
if on_connect is not None:
|
||||||
for oc in on_connect():
|
if callable(on_connect):
|
||||||
|
toc = on_connect()
|
||||||
|
else:
|
||||||
|
toc = on_connect
|
||||||
|
if toc is not None:
|
||||||
|
for oc in toc:
|
||||||
self.write(oc)
|
self.write(oc)
|
||||||
# Then, JOIN some channels
|
# Then, JOIN some channels
|
||||||
for chn in channels:
|
for chn in channels:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue