From 88e510b4cf7de322da82966aba16c6aedf584fa2 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 23 Jul 2016 00:55:06 -0700 Subject: [PATCH] clientbot: begin work on special hooks & move event relaying to a separate plugin --- plugins/relay_clientbot.py | 14 ++++++++++++++ protocols/clientbot.py | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 plugins/relay_clientbot.py diff --git a/plugins/relay_clientbot.py b/plugins/relay_clientbot.py new file mode 100644 index 0000000..fe7c733 --- /dev/null +++ b/plugins/relay_clientbot.py @@ -0,0 +1,14 @@ +# relay_clientbot.py: Clientbot extensions for Relay + +from pylinkirc import utils +from pylinkirc.log import log + +def handle_cbmessages(irc, source, command, args): + target = args['target'] + text = args['text'] + if irc.pseudoclient: + # TODO: configurable format + irc.proto.message(irc.pseudoclient.uid, target, + '<%s> %s' % (irc.getFriendlyName(source), text)) + +utils.add_hook(handle_cbmessages, 'CLIENTBOT_MESSAGE') diff --git a/protocols/clientbot.py b/protocols/clientbot.py index a1efea1..7f1b79e 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -129,6 +129,7 @@ class ClientbotWrapperProtocol(Protocol): else: log.debug('(%s) join: faking JOIN of client %s/%s to %s', self.irc.name, client, self.irc.getFriendlyName(client), channel) + self.irc.callHooks([client, 'CLIENTBOT_JOIN', {'channel': channel}]) def kick(self, source, channel, target, reason=''): """Sends channel kicks.""" @@ -154,14 +155,18 @@ class ClientbotWrapperProtocol(Protocol): def message(self, source, target, text, notice=False): """Sends messages to the target.""" command = 'NOTICE' if notice else 'PRIVMSG' - target = self._expandPUID(target) - self.irc.send('%s %s :%s' % (command, target, self._formatText(source, text))) + if self.irc.pseudoclient and self.irc.pseudoclient.uid == source: + self.irc.send('%s %s :%s' % (command, self._expandPUID(target), text)) + else: + self.irc.callHooks([source, 'CLIENTBOT_MESSAGE', {'target': target, 'is_notice': notice, 'text': text}]) def nick(self, source, newnick): """STUB: Sends NICK changes.""" if source == self.irc.pseudoclient.uid: self.irc.send('NICK :%s' % (channel, self._expandPUID(target), reason)) + else: + self.irc.callHooks([source, 'CLIENTBOT_NICK', {'newnick': newnick}]) self.irc.users[source].nick = newnick def notice(self, source, target, text): @@ -188,10 +193,13 @@ class ClientbotWrapperProtocol(Protocol): # Only parts for the main PyLink client are actually forwarded. Others are ignored. if self.irc.pseudoclient and source == self.irc.pseudoclient.uid: self.irc.send('PART %s :%s' % (channel, reason)) + else: + self.irc.callHooks([source, 'CLIENTBOT_PART', {'channel': channel, 'text': reason}]) def quit(self, source, reason): """STUB: Quits a client.""" self.removeClient(source) + self.irc.callHooks([source, 'CLIENTBOT_QUIT', {'text': reason}]) def sjoin(self, server, channel, users, ts=None, modes=set()): """STUB: bursts joins from a server."""