First semi-reasonable version of the code.

This commit is contained in:
Robert "ar" Gerus 2013-05-29 16:46:16 +02:00
commit cf64f64b89
3 changed files with 55 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
config.rb
*.swp
*.swo
*~

17
repost.rb Normal file
View file

@ -0,0 +1,17 @@
class Repost < EventMachine::IRC::Client
attr_accessor :triggers
def dispatch_raw_message(message = {})
self.triggers = [] if self.triggers.nil?
self.triggers.each do |trigger|
trigger[:code].call(message) if message[:command] == trigger[:command]
end
end
def register_trigger(command, &code)
self.triggers = [] if self.triggers.nil?
self.triggers << {:command => command, :code => code}
end
end

34
run.rb Executable file
View file

@ -0,0 +1,34 @@
#!env ruby
require 'rubygems'
require 'eventmachine'
require 'em-irc'
require './config'
require './repost'
repost = Repost.new do
host Config[:server][:host]
port Config[:server][:port]
on :connect do
puts "connected! changing nick to #{Config[:client][:nick]}"
nick Config[:client][:nick]
end
on :nick do
Config[:client][:channels].each do |channel|
puts "joining #{channel}"
join channel
end
end
on :raw do |message|
self.dispatch_raw_message message
end
end
#repost.register_trigger("PRIVMSG") { |msg| p msg }
repost.run!