Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more documentation, added gem command and default miniminimini script

  • Loading branch information...
commit 9c96ab99f4d601d654be78aa6315173fb51dcf97 1 parent c9eb128
@purzelrakete purzelrakete authored
View
63 README.markdown
@@ -1,28 +1,61 @@
-# a ruby eventmachine bot inspired by richard jones' irccat. also logs channels. history and webhooks via sinatra.
+# a ruby eventmachine bot inspired by richard jones' irccat. interact via netcat, irc or web.
+## installing
+
+ sudo gem install purzelrakete-mini --source=http://gems.github.com
+
## usage
-launch like this. note - leave the # off the channel names. you can add many channel names, main one is first.
+launch: (leave the # off the channel names. you can add many channel names, main one is first)
+
+ minictl irc.freenode.net 6667 my_bot_name my_bot_nickserv_passwd my_bot_control_channel next_channel
+
+íf you want to background this, just do something like
- ruby script/mini.rb irc.freenode.net 6667 my_bot_name my_bot_nickserv_passwd my_bot_control_channel next_channel
+ nohup minictl irc.freenode.net 6667 mimi secret mini-lounge &
+
+### via netcat
now send some data down the pipes!
- echo "Ilovethistuffs yes .. i .. do. " | nc localhost 12345
- vmstat | nc localhost 12345
- echo "#musicteam,#legal,@alice New album uploaded: ..." | nc somemachine 12345
- tail -f /var/log/important.log | nc somemachine 12345
+ echo "Ilovethistuffs yes .. i .. do. " | nc localhost 12345
+ vmstat | nc localhost 12345
+ echo "#musicteam,#legal,@alice New album uploaded: ..." | nc somemachine 12345
+ tail -f /var/log/important.log | nc somemachine 12345
-to send IRC commands, prepend '/':
+to send IRC commands from the bot, prepend '/':
- echo "/JOIN #some_channel"
-
-run stuff by typing ?command in the main mini channel or by dmsging mini bot. this will invoke a script called miniminimini with the command as an arg. here's an example miniminimini:
+ echo "/JOIN #some_channel"
+
+### via irc
+
+run stuff by typing ?command in the main mini channel or by dmsging mini bot. this will invoke a script called miniminimini with the command as an arg. there's a default script bundled as an executable in the gem. if you want to use your own, just make sure you place it before the bundled one in your $PATH. here's an example:
+
+ #!/usr/local/bin/ruby
+ puts "called miniminimini with #{ ARGV.inspect }"
+
+don't forget to chmod +x and replace the bang as appropriate.
+
+you have to be on the control channel for the script to execute. this is the first channel in your list.
+
+### via web
+
+post to hostname:MINI_WEB_PORT/MINI_SECRET/command. ie:
+
+ curl -dtext="netcat, lolcats, pigs, sweaty snout, nixon!" http://test.com:2345/dscds789svjskdlvsdz789mkvcjvklsd6/echo
+
+of course normally, you'd proxy to startup.com:2345 from somthing sitting behind :80. Set the ENV variables before starting mini.
+
+## commands
+
+you can create commands simply by providing your own miniminimini script. ARGV.first ist the command, the rest is arguments. mini comes bundled with a ruby based miniminimini script which you can extend by adding procs like this:
- #!/usr/local/bin/ruby
+ Mini::Web.commands[:echo] = lambda { |*args| puts args }
- puts "called miniminimini with #{ ARGV.inspect }"
+## configuration
-place this on your $PATH and don't forget to chmod +x. check where ruby lives by typing `which ruby`, and replace the bang line above with your ruby path.
+the following environment variables can be used to configure mini.
-you have to be on the control channel for the script to execute. this is the first channel in your list.
+* `MINI_SECRET`: a secret key for the web server, ie /kvds78ovdsjhvksd7ckjlds7cvds879bskdl/git_commit
+* `MINI_CAT_PORT`: port for clients using netcat.
+* `MINI_WEB_PORT`: port on which the web server is started.
View
12 lib/mini.rb
@@ -1,10 +1,2 @@
-require 'rubygems'
-require 'eventmachine'
-require 'activesupport'
-require 'ostruct'
-require 'json'
-require 'sinatra'
-
-require File.dirname(__FILE__) + '/mini/listener'
-require File.dirname(__FILE__) + '/mini/irc'
-require File.dirname(__FILE__) + '/mini/web'
+%w{ rubygems eventmachine activesupport ostruct json sinatra }.each { |lib| require lib }
+%w{ listener irc web bot }.each { |lib| require File.dirname(__FILE__) + "/mini/#{ lib }" }
View
14 lib/mini/bot.rb
@@ -0,0 +1,14 @@
+#
+# Runs proc stored in Mini::Bot.commands[command].
+#
+module Mini
+ class Bot
+ cattr_accessor :commands
+ @@commands = {}
+
+ def self.run(command, args)
+ proc = Bot.commands[command]
+ proc.call(args) if proc
+ end
+ end
+end
View
2  lib/mini/irc.rb
@@ -17,7 +17,7 @@ def say(msg, targets = [])
targets = ['#' + config.channels.first] if targets.blank?
msg.split("\n").each do |msg|
targets.each do |target|
- command (msg.starts_with?("/") ? msg[1..-1] : "PRIVMSG #{ target.delete("@") } :#{ msg }")
+ command( (msg.starts_with?("/") ? msg[1..-1] : "PRIVMSG #{ target.delete("@") } :#{ msg }") )
end
end
end
View
4 script/mini.rb → script/minictl
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../lib/mini'
-abort("script/mini.rb <server> <port> <user> <password> <main channel> <channel2>. don't use hashes for the chans. ") unless ARGV.length >= 4
-mini_secret, mini_port, web_port, server, port, user, password, *channels = [ENV['MINI_SECRET'], ENV['MINI_PORT'], ENV['WEB_PORT'], ARGV].flatten
+abort("minictl <server> <port> <user> <password> <main channel> <channel2>. don't use hashes for the chans. ") unless ARGV.length >= 4
+mini_secret, mini_port, web_port, server, port, user, password, *channels = [ENV['MINI_SECRET'], ENV['MINI_CAT_PORT'], ENV['MINI_WEB_PORT'], ARGV].flatten
EventMachine::run do
Mini::IRC.connect \
View
4 script/miniminimini
@@ -0,0 +1,4 @@
+#!/usr/local/bin/ruby
+
+command, *args = ARGV
+puts Mini::Bot.run(command, args)
Please sign in to comment.
Something went wrong with that request. Please try again.