mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-26 04:04:22 +01:00
clientbot: add nick, kick handling; squit and sjoin stubs
This commit is contained in:
parent
154421ffde
commit
387d47808c
@ -28,6 +28,16 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
return nick
|
return nick
|
||||||
return uid
|
return uid
|
||||||
|
|
||||||
|
def _formatText(self, source, text):
|
||||||
|
"""
|
||||||
|
Formats text with the given sender as a prefix.
|
||||||
|
"""
|
||||||
|
if source == self.irc.pseudoclient.uid:
|
||||||
|
return text
|
||||||
|
else:
|
||||||
|
# TODO: configurable formatting
|
||||||
|
return '<%s> %s' % (self.irc.getFriendlyName(source), text)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""Initializes a connection to a server."""
|
"""Initializes a connection to a server."""
|
||||||
ts = self.irc.start_ts
|
ts = self.irc.start_ts
|
||||||
@ -96,21 +106,28 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
log.debug('(%s) join: faking JOIN of client %s/%s to %s', self.irc.name, client,
|
log.debug('(%s) join: faking JOIN of client %s/%s to %s', self.irc.name, client,
|
||||||
self.irc.getFriendlyName(client), channel)
|
self.irc.getFriendlyName(client), channel)
|
||||||
|
|
||||||
|
def kick(self, source, channel, target, reason=''):
|
||||||
|
"""Sends channel kicks."""
|
||||||
|
# TODO: handle kick failures and send rejoin hooks for the target
|
||||||
|
self.irc.send('KICK %s %s :%s' % (channel, self._expandPUID(target), reason))
|
||||||
|
self.part(target, channel, reason=reason)
|
||||||
|
|
||||||
def message(self, source, target, text, notice=False):
|
def message(self, source, target, text, notice=False):
|
||||||
"""Sends messages to the target."""
|
"""Sends messages to the target."""
|
||||||
command = 'NOTICE' if notice else 'PRIVMSG'
|
command = 'NOTICE' if notice else 'PRIVMSG'
|
||||||
target = self._expandPUID(target)
|
target = self._expandPUID(target)
|
||||||
|
|
||||||
if source == self.irc.pseudoclient.uid:
|
self.irc.send('%s %s :%s' % (command, target, self._formatText(source, text)))
|
||||||
# Message has source of main PyLink client: make it so.
|
|
||||||
self.irc.send('%s %s :%s' % (command, target, text))
|
def nick(self, source, newnick):
|
||||||
else:
|
"""STUB: Sends NICK changes."""
|
||||||
# Message was sent from somewhere else. Prefix it with
|
if source == irc.pseudoclient.uid:
|
||||||
# the real sender. TODO: configurable formatting
|
self.irc.send('NICK :%s' % (channel, self._expandPUID(target), reason))
|
||||||
self.irc.send('%s %s :<%s> %s' % (command, target, self.irc.getFriendlyName(source), text))
|
self.irc.users[source].nick = newnick
|
||||||
|
|
||||||
def notice(self, source, target, text):
|
def notice(self, source, target, text):
|
||||||
"""Sends notices to the target."""
|
"""Sends notices to the target."""
|
||||||
|
# Wrap around message(), which does all the text formatting for us.
|
||||||
self.message(source, target, text, notice=True)
|
self.message(source, target, text, notice=True)
|
||||||
|
|
||||||
def ping(self, source=None, target=None):
|
def ping(self, source=None, target=None):
|
||||||
@ -133,9 +150,19 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
"""STUB: Quits a client."""
|
"""STUB: Quits a client."""
|
||||||
self.removeClient(source)
|
self.removeClient(source)
|
||||||
|
|
||||||
|
def sjoin(self, server, channel, users, ts=None, modes=set()):
|
||||||
|
"""STUB: bursts joins from a server."""
|
||||||
|
puids = {u[-1] for u in users}
|
||||||
|
for user in puids:
|
||||||
|
self.irc.users[user].channels.add(channel)
|
||||||
|
|
||||||
|
self.irc.channels[channel].users |= puids
|
||||||
|
|
||||||
|
def squit(self, source, target, text):
|
||||||
|
self._squit(source, target, text)
|
||||||
|
|
||||||
def handle_events(self, data):
|
def handle_events(self, data):
|
||||||
"""Event handler for the RFC1459/2812 (clientbot) protocol.
|
"""Event handler for the RFC1459/2812 (clientbot) protocol."""
|
||||||
"""
|
|
||||||
data = data.split(" ")
|
data = data.split(" ")
|
||||||
try:
|
try:
|
||||||
args = self.parsePrefixedArgs(data)
|
args = self.parsePrefixedArgs(data)
|
||||||
@ -236,6 +263,28 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
|
|
||||||
return {'channel': channel, 'users': [source], 'modes': self.irc.channels[channel].modes}
|
return {'channel': channel, 'users': [source], 'modes': self.irc.channels[channel].modes}
|
||||||
|
|
||||||
|
def handle_kick(self, source, command, args):
|
||||||
|
"""
|
||||||
|
Handles incoming KICKs.
|
||||||
|
"""
|
||||||
|
# <- :GL!~gl@127.0.0.1 KICK #whatever GL| :xd
|
||||||
|
channel = self.irc.toLower(args[0])
|
||||||
|
target = self.irc.nickToUid(args[1])
|
||||||
|
|
||||||
|
try:
|
||||||
|
reason = args[2]
|
||||||
|
except IndexError:
|
||||||
|
reason = ''
|
||||||
|
|
||||||
|
self.part(target, channel, reason)
|
||||||
|
return {'channel': channel, 'target': target, 'text': reason}
|
||||||
|
|
||||||
|
def handle_nick(self, source, command, args):
|
||||||
|
# <- :GL|!~GL@127.0.0.1 NICK :GL_
|
||||||
|
oldnick = self.irc.users[source].nick
|
||||||
|
self.nick(source, args[0])
|
||||||
|
return {'newnick': args[0], 'oldnick': oldnick}
|
||||||
|
|
||||||
def handle_part(self, source, command, args):
|
def handle_part(self, source, command, args):
|
||||||
"""
|
"""
|
||||||
Handles incoming PARTs.
|
Handles incoming PARTs.
|
||||||
@ -247,7 +296,6 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
reason = ''
|
reason = ''
|
||||||
|
|
||||||
|
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
self.part(source, channel, reason)
|
self.part(source, channel, reason)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user