Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

latest stuffs

  • Loading branch information...
commit 7e540561f1e94202c75d569b88e90a87a9a0b5a6 1 parent 931c115
Rany Keddo purzelrakete authored
2  CREDITS.markdown
View
@@ -0,0 +1,2 @@
+- thanks to yakischloba and careo on #eventmachine (freenode)
+- 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.
7 LICENSE.textile
View
@@ -0,0 +1,7 @@
+Copyright (c) 2009 Rany Keddo
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0  README
View
No changes.
14 README.textile
View
@@ -0,0 +1,14 @@
+a ruby eventmachine bot inspired by richard jones' irccat. also logs channels. history and webhooks via sinatra.
+
+# usage
+
+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
+
+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
5 TODO.textile
View
@@ -0,0 +1,5 @@
+* add buffering to avoid flooding
+* add !commands
+* only respond to ppl on main chan
+* add sinatra
+* add datamapper
6 lib/mini.rb
View
@@ -0,0 +1,6 @@
+require 'rubygems'
+require 'eventmachine'
+require 'activesupport'
+
+require File.dirname(__FILE__) + '/mini/listener'
+require File.dirname(__FILE__) + '/mini/irc'
60 lib/mini/irc.rb
View
@@ -0,0 +1,60 @@
+#
+# Connect to and handle IRC.
+#
+module Mini
+ class IRC < EventMachine::Connection
+
+ include EventMachine::Protocols::LineText2
+ cattr_accessor *(@@config = [:user, :password, :server, :port, :channels])
+
+ def say(msg, targets = [])
+ targets = ['#' + IRC.channels.first] if targets.blank?
+ msg.split("\n").each do |msg|
+ targets.each { |target| command "PRIVMSG #{ target.delete("@") } :#{ msg }" }
+ end
+ end
+
+ def command(*cmd)
+ send_data "#{ cmd.flatten.join(' ') }\r\n"
+ end
+
+ def execute(sender, receiver, msg)
+ (@queue ||= []) << [sender, receiver, msg]
+ command "NAMES", "#" + IRC.channels.first
+ end
+
+ def self.connect(options)
+ @@config.each { |param| IRC.send("#{ param }=", options[param]) }
+ EM.connect(IRC.server, IRC.port, self, options)
+ end
+
+ #
+ # Callbacks
+ #
+
+ def post_init
+ command "USER", [IRC.user]*4
+ command "NICK", IRC.user
+ command("NickServ IDENTIFY", IRC.user, IRC.password) if IRC.password
+ IRC.channels.each { |channel| command("JOIN", "##{ channel }") } if IRC.channels
+ end
+
+ def receive_line(line)
+ case line
+ when /^PING (.*)/ : command('PONG', $1)
+ when /^:(\S+) PRIVMSG (.*) :\!(.*)$/ : execute($1, $2, $3)
+ when /^:NAMES / : unwind(nicks)
+ else puts line; end
+ end
+
+ def unbind
+ EM.add_timer(3) do
+ reconnect(IRC.server, IRC.port)
+ post_init
+ end
+ end
+ end
+end
+
+__END__
+:hubbard.freenode.net 353 dslkfjlds @ #eventmachine :+dslkfjlds +joseferr +yakischloba +rsimon +alloy +Aria +mchung +dj2 +takiuchi_ +elven +elliottcable @raggi +tmm1 +igrigorik +manveru +SuttoL @ChanServ +wyhaines +garbagecat
13 lib/mini/listener.rb
View
@@ -0,0 +1,13 @@
+module Mini
+ module Listener
+ mattr_accessor :connection
+
+ # echo "#musicteam,#legal,@alice New album uploaded: ..." | nc -q0 somemachine 12345.
+ def receive_data(data)
+ all, targets, *payload = *data.match(/^(([\#@]\S+,? ?)*)(.*)$/)
+ targets = targets.split(",").map { |target| target.strip }.uniq
+
+ Listener.connection.say(payload.pop.strip, targets)
+ end
+ end
+end
16 script/mini.rb
View
@@ -0,0 +1,16 @@
+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
+
+EventMachine::run do
+ @irc = Mini::IRC.connect \
+ :server => server,
+ :port => port,
+ :user => user,
+ :password => password,
+ :channels => [channels].flatten
+
+ Mini::Listener.connection = @irc
+ EventMachine::start_server("0.0.0.0", 12345, Mini::Listener)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.