From 933029824c44fa800120965099b61547b40e8754 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 17 Apr 2016 20:28:51 -0700 Subject: [PATCH] nefarious: AWAY and INVITE support --- protocols/nefarious.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/protocols/nefarious.py b/protocols/nefarious.py index 5dd474e..0f46065 100644 --- a/protocols/nefarious.py +++ b/protocols/nefarious.py @@ -234,6 +234,30 @@ class P10Protocol(Protocol): realhost=realhost)) return u + def away(self, source, text): + """Sends an AWAY message from a PyLink client. 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 + # 2 + # - 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