3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

nefarious: AWAY and INVITE support

This commit is contained in:
James Lu 2016-04-17 20:28:51 -07:00
parent 20123c52e0
commit 933029824c

View File

@ -234,6 +234,30 @@ class P10Protocol(Protocol):
realhost=realhost))
return u
def away(self, source, text):
"""Sends an AWAY message from a PyLink client. <text> can be an empty string
to unset AWAY status."""
if not self.irc.isInternalClient(source):
raise LookupError('No such PyLink client exists.')
if text:
self._send(source, 'A :%s' % text)
else:
self._send(source, 'A')
self.irc.users[source].away = text
def invite(self, numeric, target, channel):
"""Sends INVITEs from a PyLink client."""
# Note: we have to send a nick as the target, not a UID.
# <- ABAAA I PyLink-devel #services 1460948992
if not self.irc.isInternalClient(numeric):
raise LookupError('No such PyLink client exists.')
nick = self.irc.users[target].nick
self._send(numeric, 'I %s %s %s' % (nick, channel, self.irc.channels[channel].ts))
def join(self, client, channel):
"""Joins a PyLink client to a channel."""
# <- ABAAB J #test3 1460744371
@ -994,4 +1018,27 @@ class P10Protocol(Protocol):
return {'channel': channel, 'setter': args[1], 'text': topic,
'oldtopic': oldtopic}
def handle_invite(self, source, command, args):
"""Handles incoming INVITEs."""
# From P10 docs:
# 1 <target nick>
# 2 <channel>
# - note that the target is a nickname, not a numeric.
# <- ABAAA I PyLink-devel #services 1460948992
target = self._getUid(args[0])
channel = utils.toLower(self.irc, args[1])
return {'target': target, 'channel': channel}
def handle_away(self, numeric, command, args):
"""Handles incoming AWAY messages."""
# <- ABAAA A :blah
# <- ABAAA A
try:
self.irc.users[numeric].away = text = args[0]
except IndexError: # User is unsetting away status
self.irc.users[numeric].away = text = ''
return {'text': text}
Class = P10Protocol