Permalink
Browse files

finsihed

  • Loading branch information...
1 parent 7e54056 commit 267f11562e60cfe264d570a23a2c75cebde9c2be @purzelrakete purzelrakete committed Feb 19, 2009
Showing with 22 additions and 18 deletions.
  1. +1 −1 CREDITS.markdown
  2. 0 LICENSE.textile → LICENSE.markdown
  3. +5 −3 README.textile → README.markdown
  4. +16 −14 lib/mini/irc.rb
View
@@ -1,2 +1,2 @@
-- thanks to yakischloba and careo on #eventmachine (freenode)
+- 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.
File renamed without changes.
@@ -1,6 +1,6 @@
-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. also logs channels. history and webhooks via sinatra.
-# usage
+## usage
launch like this. note - leave the # off the channel names. you can add many channel names, main one is first.
@@ -11,4 +11,6 @@ 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
+ tail -f /var/log/important.log | nc somemachine 12345
+
+run stuff by typing ?command in the main mini channel or by dmsging mini bot. this will invoke miniminimini.rb with the command as an arg. place miniminimini.rb on your $PATH.
View
@@ -3,9 +3,8 @@
#
module Mini
class IRC < EventMachine::Connection
-
include EventMachine::Protocols::LineText2
- cattr_accessor *(@@config = [:user, :password, :server, :port, :channels])
+ cattr_accessor *((@@config = [:user, :password, :server, :port, :channels]) + [:moderators])
def say(msg, targets = [])
targets = ['#' + IRC.channels.first] if targets.blank?
@@ -19,19 +18,25 @@ def command(*cmd)
end
def execute(sender, receiver, msg)
- (@queue ||= []) << [sender, receiver, msg]
+ (@queue ||= []) << [sender.split("!").first, msg]
command "NAMES", "#" + IRC.channels.first
end
+ def unwind(nicks)
+ IRC.moderators = nicks.split.map { |nick| nick.delete("@").delete("+") }
+
+ while job = (@queue ||= []).pop
+ sender, bang = job
+ say(%x{ #{ ruby -S miniminimini.rb bang[1..-1] } }) if IRC.moderators.include?(sender)
+ end
+ end
+
def self.connect(options)
@@config.each { |param| IRC.send("#{ param }=", options[param]) }
- EM.connect(IRC.server, IRC.port, self, options)
+ EM.connect(IRC.server, IRC.port.to_i, self, options)
end
- #
- # Callbacks
- #
-
+ # callbacks
def post_init
command "USER", [IRC.user]*4
command "NICK", IRC.user
@@ -42,8 +47,8 @@ def post_init
def receive_line(line)
case line
when /^PING (.*)/ : command('PONG', $1)
- when /^:(\S+) PRIVMSG (.*) :\!(.*)$/ : execute($1, $2, $3)
- when /^:NAMES / : unwind(nicks)
+ when /^:(\S+) PRIVMSG (.*) :\?(.*)$/ : execute($1, $2, $3)
+ when /^:\S* \d* #{ IRC.user } @ #{ '#' + IRC.channels.first } :(.*)/ : unwind($1)
else puts line; end
end
@@ -54,7 +59,4 @@ def unbind
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
+end

0 comments on commit 267f115

Please sign in to comment.