Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Example of command:
- from util import hook
- @hook.command('h')
- @hook.command(autohelp=False)
- def hello_world(inp):
- """Returns 'Hello World' when command matches."""
- return "Hello World"
- That specifies an 'h' command, and a 'hello_world' command, if either of those are found it will run the plugin.
- ---
- 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.
- Example of regex:
- import re
- from util import hook
- hello_re = ('hello world', re.I)
- @hook.regex(*karma_re)
- def hello_world(inp):
- """Returns 'Hello World' when regex matches"""
- return "Hello World"
- 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.
- There are a few compile options you can use:
- re.I
- re.IGNORECASE
- Perform case-insensitive matching; expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.
- re.L
- re.LOCALE
- Make \w, \W, \b, \B, \s and \S dependent on the current locale.
- re.M
- re.MULTILINE
- 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.
- re.S
- re.DOTALL
- Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline.
- re.U
- re.UNICODE
- Make \w, \W, \b, \B, \d, \D, \s and \S dependent on the Unicode character properties database.
- re.X
- re.VERBOSE
- 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.
- More info here: http://docs.python.org/library/re.html
- ---
- 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
- Example of event:
- from util import hook
- #autorejoin channels
- @hook.event('KICK')
- def rejoin(paraml, conn=None):
- if paraml[1] == conn.nick:
- if paraml[0].lower() in conn.channels:
- conn.join(paraml[0])
- That specifies a 'KICK' event, so when skybot is kicked it will attempt to rejoin the channel.
- Other events currently used by Skybot:
- 'PRIVMSG', runs something if something is sent through a private message to Skybot.
- 'INVITE', runs something if Skybot is invited to a channel.
- 'TOPIC', runs something if the topic is changed.
- 'MODE', runs something if channel mode is changed.
- 'PART', runs something if someone quits.
- '004', runs something if this event is encountered, which is a post-registration greeting.
- More events here: http://www.solidirc.com/server_help/Commands.html
- Numeric events here: http://www.alien.net.au/irc/irc2numerics.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement