3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

clientbot: implement IRCv3.2 CAP and IRCv3.1 multi-prefix (#290)

This commit is contained in:
James Lu 2016-12-16 22:28:40 -08:00
parent cbc7f438d2
commit 3bc9b1bc55

View File

@ -7,6 +7,7 @@ from pylinkirc.classes import Protocol, IrcUser, IrcServer
FALLBACK_REALNAME = 'PyLink Relay Mirror Client' FALLBACK_REALNAME = 'PyLink Relay Mirror Client'
COMMON_PREFIXMODES = [('h', 'halfop'), ('a', 'admin'), ('q', 'owner'), ('y', 'owner')] COMMON_PREFIXMODES = [('h', 'halfop'), ('a', 'admin'), ('q', 'owner'), ('y', 'owner')]
IRCV3_CAPABILITIES = {'multi-prefix'}
class ClientbotWrapperProtocol(Protocol): class ClientbotWrapperProtocol(Protocol):
def __init__(self, irc): def __init__(self, irc):
@ -21,6 +22,7 @@ class ClientbotWrapperProtocol(Protocol):
self.casemapping = 'ascii' self.casemapping = 'ascii'
self.caps = {} self.caps = {}
self.ircv3_caps = set()
# Initialize counter-based pseudo UID generators # Initialize counter-based pseudo UID generators
self.uidgen = utils.PUIDGenerator('PUID') self.uidgen = utils.PUIDGenerator('PUID')
@ -61,6 +63,12 @@ class ClientbotWrapperProtocol(Protocol):
# Clear states from last connect # Clear states from last connect
self.who_received.clear() self.who_received.clear()
self.kick_queue.clear() self.kick_queue.clear()
self.caps.clear()
self.ircv3_caps.clear()
f('CAP LS 302')
f('CAP REQ :%s' % ' '.join(IRCV3_CAPABILITIES))
f('CAP END')
sendpass = self.irc.serverdata.get("sendpass") sendpass = self.irc.serverdata.get("sendpass")
if sendpass: if sendpass:
@ -395,8 +403,26 @@ class ClientbotWrapperProtocol(Protocol):
else: else:
parsed_args = func(idsource, command, args) parsed_args = func(idsource, command, args)
if parsed_args is not None: if parsed_args is not None:
parsed_args['tags'] = tags # Add message tags to this dict.
return [idsource, command, parsed_args] return [idsource, command, parsed_args]
def handle_cap(self, source, command, args):
"""
Handles IRCv3 capabilities transmission.
"""
subcmd = args[1]
if subcmd == 'LS':
# Server: CAP * LS * :multi-prefix extended-join account-notify batch invite-notify tls
# Server: CAP * LS * :cap-notify server-time example.org/dummy-cap=dummyvalue example.org/second-dummy-cap
# Server: CAP * LS :userhost-in-names sasl=EXTERNAL,DH-AES,DH-BLOWFISH,ECDSA-NIST256P-CHALLENGE,PLAIN
caps = args[-1].split('=')
elif subcmd == 'ACK':
# Server: CAP * ACK :multi-prefix sasl
newcaps = set(args[-1].split())
log.debug('(%s) Received ACK for capabilities %s', self.irc.name, newcaps)
self.ircv3_caps |= newcaps
def handle_001(self, source, command, args): def handle_001(self, source, command, args):
""" """
Handles 001 / RPL_WELCOME. Handles 001 / RPL_WELCOME.