Small tweaks to IRC code
This commit is contained in:
parent
9f90ae049e
commit
7a9e8c7fef
@ -20,10 +20,6 @@ from lib.hash import double_sha256
|
|||||||
from lib.util import LoggedClass
|
from lib.util import LoggedClass
|
||||||
|
|
||||||
|
|
||||||
VERSION = '1.0'
|
|
||||||
DEFAULT_PORTS = {'t': 50001, 's': 50002}
|
|
||||||
|
|
||||||
|
|
||||||
class IRC(LoggedClass):
|
class IRC(LoggedClass):
|
||||||
|
|
||||||
Peer = namedtuple('Peer', 'ip_addr host ports')
|
Peer = namedtuple('Peer', 'ip_addr host ports')
|
||||||
@ -165,27 +161,32 @@ class IRC(LoggedClass):
|
|||||||
|
|
||||||
class IrcClient(LoggedClass):
|
class IrcClient(LoggedClass):
|
||||||
|
|
||||||
|
VERSION = '1.0'
|
||||||
|
DEFAULT_PORTS = {'t': 50001, 's': 50002}
|
||||||
|
|
||||||
def __init__(self, irc_address, nick, host, tcp_port, ssl_port):
|
def __init__(self, irc_address, nick, host, tcp_port, ssl_port):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.irc_host, self.irc_port = irc_address
|
self.irc_host, self.irc_port = irc_address
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
self.realname = IrcClient.create_realname(host, tcp_port, ssl_port)
|
self.realname = self.create_realname(host, tcp_port, ssl_port)
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
|
|
||||||
def connect(self, keepalive=60):
|
def connect(self, keepalive=60):
|
||||||
'''Connect this client to its IRC server'''
|
'''Connect this client to its IRC server'''
|
||||||
self.connection.connect(self.irc_host, self.irc_port, self.nick,
|
self.connection.connect(self.irc_host, self.irc_port, self.nick,
|
||||||
ircname=self.realname)
|
ircname=self.realname)
|
||||||
self.connection.set_keepalive(keepalive)
|
self.connection.set_keepalive(keepalive)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def create_realname(host, tcp_port, ssl_port):
|
def create_realname(cls, host, tcp_port, ssl_port):
|
||||||
def port_text(letter, port):
|
def port_text(letter, port):
|
||||||
if letter in DEFAULT_PORTS and port == DEFAULT_PORTS[letter]:
|
if not port:
|
||||||
return letter
|
return ''
|
||||||
|
if port == cls.DEFAULT_PORTS.get(letter):
|
||||||
|
return ' ' + letter
|
||||||
else:
|
else:
|
||||||
return letter + str(port)
|
return ' ' + letter + str(port)
|
||||||
tcp = ' ' + port_text('t', tcp_port) if tcp_port else ''
|
|
||||||
ssl = ' ' + port_text('s', ssl_port) if ssl_port else ''
|
tcp = port_text('t', tcp_port)
|
||||||
return '{} v{}{}{}'.format(host, VERSION, tcp, ssl)
|
ssl = port_text('s', ssl_port)
|
||||||
|
return '{} v{}{}{}'.format(host, cls.VERSION, tcp, ssl)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user