forked from pbrisbin/basil
-
Notifications
You must be signed in to change notification settings - Fork 0
Creating plugins
pbrisbin edited this page Jun 14, 2012
·
7 revisions
There are three methods used for creating basil plugins.
Recently, basil gained the ability to check email. What basil does with these emails depends on the plugins defined in the following way:
class AnObject
def self.create_message(email)
# this method must accept a Basil::Email::Mail and (possibly) return
# a Basil::Message. If it does, the message will be handed to your
# server's broadcast_message method.
end
end
Basil.check_email(AnObject)
Email is polled (on the interval set in your config file) if and only if your server actually responds to the broadcast_message
method
A responder will only be used on messages that are "to basil":
Basil.respond_to(/a regex/) do
# logic that either returns a Message or nil
end
Within the block, you have access to two very useful instance variables:
-
@msg
is the Message that the plugin is currently responding to -
@match_data
contains the MatchData object that resulted from applying your regex
You've also got all the methods from Basil::Utils
and Basil::ChatHistory
.
Watchers are exactly like responders except that they can be triggered on messages to anyone. One example might be to show titles for any urls mentioned in the chat:
Basil.watch_for(/https?:\/\/\S+/) do
if get_html(@match_data[0]) =~ /<title>(.*?)<\/title>/
says "Title: #{$1}"
end
end