Mobb
Mobb is the simplest, most lightweight, fastest Bot framework written by Ruby.
Install
you can install Mobb by rubygems like
gem isntall mobb
or you can use a bundler. Writes the following in Gemfile
source "https://rubygems.org"
gem "mobb", "~> 0.1"
and install
bundle install
Examples
Write your logic in app.rb like...
require 'mobb'
set :name, "example bot"
on "hello" do
"hi! i'm #{settings.name}!"
endand start mobb application
ruby app.rb
then the shell will start to wait for your input, so you can type 'hello' and hit enter, then you get.
hi! i'm example bot!"
Helpers
You can define helper methods like this.
require 'mobb'
helpers do
def greet(name)
"Hi #{name}, what't up"
end
end
on "hello" do
greet(@env.user.name)
endConditions
You can use conditions react_to_bot, include_myself and reply_to_me.
require 'mobb'
set :service, 'slack'
# Mobb ignore all bot messages, but when set reply_to_bot true, Mobb react all bot messages
# this example will act infinit loop when receive message 'Yo'
on 'Yo', react_to_bot: true do
'Yo'
end
# This block react only message reply to bot
on /Hi/, reply_to_me: true do
"Hi #{@env.user.name}"
endAnd you can define conditions yourself.
require 'mobb'
set :service, 'slack'
set(:probability) { |value| condition { rand <= value } }
on /Yo/, reply_to_me: true, probability: 0.1 do
"Yo"
end
on /Yo/, reply_to_me: true do
"Ha?"
endChain methods
If you want to act heavy task your bot, you can use chain/trigger syntax.
require 'mobb'
on /taks start (\w+)/ do |name|
chain 'heavy task1', 'heavy task2', name: name
'start!'
end
trigger 'heavy task1' do
payload = @env.payload
sleep 19
"task1 #{payload[:name]} done!"
end
trigger 'heavy task2' do
payload = @env.payload
sleep 30
"task2 #{payload[:name]} done!"
endPass
You can pass block to use pass keyword
require 'mobb'
on 'yo' do
$stderr.puts 'this block will be pass'
pass
'this value never evaluted'
end
on 'yo' do
$stderr.puts 'catch!'
'yo'
endService handlers
Mobb is implemented based on Repp Interface. Shell and Slack adapter is currently available.
require 'mobb'
set :serice, 'slack'
on /hey (\w+)/ do |someone|
"hey #{someone}, waz up?"
endTODO
- Test, Test, Test
- Documents
- Parallel event handling