From 1c7e0fbeae59f38e7649f3c64380e8673bcf858a Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 15 Apr 2016 12:30:52 -0700 Subject: [PATCH] nefarious: handle inbound & outbound PRIVMSG/NOTICE --- protocols/nefarious.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/protocols/nefarious.py b/protocols/nefarious.py index 07faf06..4c02e4a 100644 --- a/protocols/nefarious.py +++ b/protocols/nefarious.py @@ -252,6 +252,20 @@ class P10Protocol(Protocol): self.irc.channels[channel].users.add(client) self.irc.users[client].channels.add(channel) + def message(self, numeric, target, text): + """Sends a PRIVMSG from a PyLink client.""" + if not self.irc.isInternalClient(numeric): + raise LookupError('No such PyLink client exists.') + + self._send(numeric, 'P %s :%s' % (target, text)) + + def notice(self, numeric, target, text): + """Sends a NOTICE from a PyLink client.""" + if not self.irc.isInternalClient(numeric): + raise LookupError('No such PyLink client exists.') + + self._send(numeric, 'O %s :%s' % (target, text)) + def ping(self, source=None, target=None): """Sends a PING to a target server. Periodic PINGs are sent to our uplink automatically by the Irc() internals; plugins shouldn't have to use this.""" @@ -568,6 +582,19 @@ class P10Protocol(Protocol): handle_create = handle_join + def handle_privmsg(self, source, command, args): + """Handles incoming PRIVMSG/NOTICE.""" + # <- ABAAA P AyAAA :privmsg text + # <- ABAAA O AyAAA :notice text + target = args[0] + + # We use lowercase channels internally, but uppercase UIDs. + if utils.isChannel(target): + target = utils.toLower(self.irc, target) + return {'target': target, 'text': args[1]} + + handle_notice = handle_privmsg + def handle_end_of_burst(self, source, command, args): """Handles end of burst from our uplink.""" # Send EOB acknowledgement; this is required by the P10 specification,