Plugins are centric to the RubyServ ecosystem because it is what handles how your services will function.
Plugins go into the plugins directory, and the best example of one of the plugins is RubyServ itself, found in plugins/core.rb.
The only thing required in a plugin are include RubyServ::Plugin and configure. The module name doesn't matter, but stay out of the RubyServ namespace to avoid namespace clashes.
configure is a very important method that is used to configure what the bots nickname, hostname, realname, etc, are.
Parameters:
nickname (String) (Required)hostname (String) (Optional)username (String) (Optional)realname (String) (Optional)channels (Array) (Optional)
Example:
module SomeServ
include RubyServ::Plugin
configure do |config|
config.nickname = 'SomeServ'
config.hostname = 'someserv.does.something'
# ...
end
endParameters:
/pattern/ (Regexp) (Required)options (Hash) (Optional)&block (????) (Required)
Supported options:
prefix (default: true)
Example:
module SomeServ
include RubyServ::Plugin
# ...
match(/some (\S+)/) do |m, param|
m.reply "some #{param} called by #{m.user.nickname}"
end
# ...
endWhen greating groups when in the pattern (in this case, (\S+)) match will take a param for each group. So:
match(/some (\S+) (\S+)/) would yield you: |m, first, second|
Parameters:
event (Symbol) (Required)option (Hash) (Optional)&block (????) (Required)
Supported options:
Example:
module SomeServ
include RubyServ::Plugin
# ...
event :privmsg do |m|
m.reply "#{m.user.nickname} someone said something!"
end
# ...
endweb definitions are translated to Sinatra routes, so if you are familiar with Sinatra some of it's magic is available to you.
Parameters:
request_type (Symbol) (Required)route (String) (Required)&block (????) (Required)
Example:
module SomeServ
include RubyServ::Plugin
# ...
web :post, '/testing' do
RubyServ::IRC::Client.find_by_nickname(@nickname).first.message('#channel', 'there was a POST to /testing!')
end
# ...
endBe unique with your routes per service, or you'll be looking at clashes.
before_match is designed to act like before_filter in rails, so it should not be very unfamiliar. It simlply runs all methods that before_match specifics before match and event are run. This does not apply to web.
Parameters:
method_name (Symbol) (Required)
Example:
module SomeServ
include RubyServ::Plugin
before_match :test
match(/google/) do |m|
# ...
end
def test
# ...
end
endSmall warning about before_match is that if instance variables are assigned they will be accessible to the other methods. Do with that what you will.
