Advertisement
Atheuz

Untitled

Jun 23rd, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 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. There are a few compile options you can use:
  37.  
  38. re.I
  39. re.IGNORECASE
  40.  
  41. Perform case-insensitive matching; expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.
  42.  
  43. re.L
  44. re.LOCALE
  45.  
  46. Make \w, \W, \b, \B, \s and \S dependent on the current locale.
  47.  
  48. re.M
  49. re.MULTILINE
  50.  
  51. When specified, the pattern character '^' matches at the beginning of the string and at the beginning of each line (immediately following each newline); and the pattern character '$' matches at the end of the string and at the end of each line (immediately preceding each newline). By default, '^' matches only at the beginning of the string, and '$' only at the end of the string and immediately before the newline (if any) at the end of the string.
  52.  
  53. re.S
  54. re.DOTALL
  55.  
  56. Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline.
  57.  
  58. re.U
  59. re.UNICODE
  60.  
  61. Make \w, \W, \b, \B, \d, \D, \s and \S dependent on the Unicode character properties database.
  62.  
  63.  
  64. re.X
  65. re.VERBOSE
  66.  
  67. This flag allows you to write regular expressions that look nicer. Whitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash, and, when a line contains a '#' neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such '#' through the end of the line are ignored.
  68.  
  69. More info here: http://docs.python.org/library/re.html
  70.  
  71. ---
  72.  
  73. 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
  74.  
  75. Example of event:
  76.  
  77. from util import hook
  78.  
  79. #autorejoin channels
  80. @hook.event('KICK')
  81. def rejoin(paraml, conn=None):
  82. if paraml[1] == conn.nick:
  83. if paraml[0].lower() in conn.channels:
  84. conn.join(paraml[0])
  85.  
  86. That specifies a 'KICK' event, so when skybot is kicked it will attempt to rejoin the channel.
  87.  
  88. Other events currently used by Skybot:
  89.  
  90. 'PRIVMSG', runs something if something is sent through a private message to Skybot.
  91. 'INVITE', runs something if Skybot is invited to a channel.
  92. 'TOPIC', runs something if the topic is changed.
  93. 'MODE', runs something if channel mode is changed.
  94. 'PART', runs something if someone quits.
  95. '004', runs something if this event is encountered, which is a post-registration greeting.
  96.  
  97. More events here: http://www.solidirc.com/server_help/Commands.html
  98. Numeric events here: http://www.alien.net.au/irc/irc2numerics.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement