Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added sinatra.

  • Loading branch information...
commit c9eb12827239477f84cdf463d3cef024cede872c 1 parent 4cbd6db
@purzelrakete purzelrakete authored
View
2  CREDITS.markdown
@@ -1,2 +1,2 @@
- thanks to yakischloba and careo on #eventmachine
-- thanks to masuidrive (http://blog.masuidrive.jp/) for a helpful gist which i can't find anymore. it showed me how to write an irc client using eventmachine.
+- thanks to masuidrive (http://blog.masuidrive.jp/) for a helpful gist which i can't find anymore. it demonstrated irc+eventmachine.
View
10 README.markdown
@@ -4,7 +4,7 @@
launch like this. note - leave the # off the channel names. you can add many channel names, main one is first.
- ruby script/mini.rb irc.freenode.net 6667 my_bot_name my_bot_nickserv_passwd my_bot_channel
+ ruby script/mini.rb irc.freenode.net 6667 my_bot_name my_bot_nickserv_passwd my_bot_control_channel next_channel
now send some data down the pipes!
@@ -13,10 +13,16 @@ now send some data down the pipes!
echo "#musicteam,#legal,@alice New album uploaded: ..." | nc somemachine 12345
tail -f /var/log/important.log | nc somemachine 12345
+to send IRC commands, 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:
#!/usr/local/bin/ruby
puts "called miniminimini with #{ ARGV.inspect }"
-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.
+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.
+
+you have to be on the control channel for the script to execute. this is the first channel in your list.
View
4 TODO.textile
@@ -1,3 +1 @@
-* add buffering to avoid flooding
-* add sinatra
-* add datamapper
+- add logbot functions
View
6 lib/mini.rb
@@ -1,6 +1,10 @@
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/irc'
+require File.dirname(__FILE__) + '/mini/web'
View
20 lib/mini/irc.rb
@@ -1,5 +1,3 @@
-require 'ostruct'
-
#
# Connect to and handle IRC.
#
@@ -18,7 +16,9 @@ def initialize(options)
def say(msg, targets = [])
targets = ['#' + config.channels.first] if targets.blank?
msg.split("\n").each do |msg|
- targets.each { |target| command "PRIVMSG #{ target.delete("@") } :#{ msg }" }
+ targets.each do |target|
+ command (msg.starts_with?("/") ? msg[1..-1] : "PRIVMSG #{ target.delete("@") } :#{ msg }")
+ end
end
end
@@ -26,20 +26,24 @@ def command(*cmd)
send_data "#{ cmd.flatten.join(' ') }\r\n"
end
- def execute(sender, receiver, msg)
+ def queue(sender, receiver, msg)
@queue << [sender.split("!").first, msg]
command "NAMES", "#" + config.channels.first
end
- def unwind(nicks)
+ def dequeue(nicks)
self.moderators = nicks.split.map { |nick| nick.delete("@").delete("+") }
while job = @queue.pop
sender, cmd = job
- say(%x{ miniminimini #{ cmd } }) if self.moderators.include?(sender)
+ execute(cmd) if self.moderators.include?(sender)
end
end
+ def execute(cmd)
+ say(%x{ miniminimini #{ cmd } })
+ end
+
def self.connect(options)
self.connection = EM.connect(options[:server], (options[:port] || "6667").to_i, self, options)
end
@@ -55,8 +59,8 @@ def post_init
def receive_line(line)
case line
when /^PING (.*)/ : command('PONG', $1)
- when /^:(\S+) PRIVMSG (.*) :\?(.*)$/ : execute($1, $2, $3)
- when /^:\S* \d* #{ config.user } @ #{ '#' + config.channels.first } :(.*)/ : unwind($1)
+ when /^:(\S+) PRIVMSG (.*) :\?(.*)$/ : queue($1, $2, $3)
+ when /^:\S* \d* #{ config.user } @ #{ '#' + config.channels.first } :(.*)/ : dequeue($1)
else puts line; end
end
View
5 lib/mini/web.rb
@@ -0,0 +1,5 @@
+@@web = Sinatra.new do
+ get("/:command/:secret") do
+ Mini::IRC.connection.exececute(["miniweb", params[:command], params.to_yaml].join) if params[:secret] == ENV['MINI_SECRET']
+ end
+end
View
9 script/mini.rb
@@ -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
-server, port, user, password, *channels = ARGV
+mini_secret, mini_port, web_port, server, port, user, password, *channels = [ENV['MINI_SECRET'], ENV['MINI_PORT'], ENV['WEB_PORT'], ARGV].flatten
EventMachine::run do
Mini::IRC.connect \
@@ -9,7 +9,8 @@
:port => port,
:user => user,
:password => password,
- :channels => [channels].flatten
-
- EventMachine::start_server("0.0.0.0", ENV['MINI_PORT'] || 12345, Mini::Listener)
+ :channels => [*channels]
+
+ EventMachine::start_server("0.0.0.0", mini_port || 12345, Mini::Listener)
+ @@web.run! :port => 2345 || web_port
end
Please sign in to comment.
Something went wrong with that request. Please try again.