Advertisement
Atheuz

Untitled

Jun 23rd, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. There are a couple different types of hooks that can be used for plugins in Skybot. The most common one is the command hook, which takes a .command as input, checks that it's a command and if it is it attempts to run it.
  2.  
  3. Example of command:
  4.  
  5. from util import hook
  6.  
  7. @hook.command('h')
  8. @hook.command(autohelp=False)
  9. def hello_world(inp):
  10. """Returns 'Hello World' when command matches."""
  11.  
  12. return "Hello World"
  13.  
  14. That specifies an 'h' command, and a 'hello_world' command, if either of those are found it will run the plugin.
  15.  
  16. ---
  17.  
  18. Another type of hook is the regex hook, it takes a regex and if any string output in the channel matches that regex it will attempt to run the plugin.
  19.  
  20. Example of regex:
  21.  
  22. import re
  23.  
  24. from util import hook
  25.  
  26. hello_re = ('hello world', re.I)
  27.  
  28. @hook.regex(*karma_re)
  29. def hello_world(inp):
  30. """Returns 'Hello World' when regex matches"""
  31.  
  32. return "Hello World"
  33.  
  34. That specifies a 'hello world' regex, that is case insensitive. If the regex is matched in any string output in the channel, it will attempt to run the plugin.
  35.  
  36.  
  37. ---
  38.  
  39. Yet another type of a hook is the event hook, it takes an IRC event such as KICK, INVITE OR PRIVMSG and if any of those happens it will attempt to run the plugin
  40.  
  41. Example of event:
  42.  
  43. from util import hook
  44.  
  45. #autorejoin channels
  46. @hook.event('KICK')
  47. def rejoin(paraml, conn=None):
  48. if paraml[1] == conn.nick:
  49. if paraml[0].lower() in conn.channels:
  50. conn.join(paraml[0])
  51.  
  52. That specifies a 'KICK' event, so when skybot is kicked it will attempt to rejoin the channel.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement