3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 11:39:25 +01:00
PyLink/plugins/hooks.py
James Lu d23d34e316 Refactor hooks to send parsed arguments instead of raw args
ref #18.

- Command handlers that support hooks will now return parsed args, which are then sent to the hooks
- Hook commands are now stored in uppercase letters, consistent with the IRC spec
2015-07-04 19:00:29 -07:00

19 lines
685 B
Python

# hooks.py: test of PyLink hooks
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
def hook_join(irc, source, command, args):
channel = args['channel']
users = args['users']
print('%s joined channel %s (JOIN hook caught)' % (users, channel))
utils.add_hook(hook_join, 'JOIN')
def hook_privmsg(irc, source, command, args):
channel = args['target']
text = args['text']
if utils.isChannel(channel) and irc.pseudoclient.nick in text:
utils.msg(irc, channel, 'hi there!')
print('%s said my name on channel %s (PRIVMSG hook caught)' % (source, channel))
utils.add_hook(hook_privmsg, 'PRIVMSG')