Some documentation + example config file
This commit is contained in:
parent
8654d3efd7
commit
9cf5513b7c
3 changed files with 29 additions and 0 deletions
17
config.example.rb
Normal file
17
config.example.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Config = {
|
||||||
|
|
||||||
|
:server => {
|
||||||
|
:host => "irc.freenode.net",
|
||||||
|
:port => 6667,
|
||||||
|
:realname => "repost",
|
||||||
|
},
|
||||||
|
|
||||||
|
:client => {
|
||||||
|
:nick => "repost",
|
||||||
|
:channels => ["#repost-test"]
|
||||||
|
},
|
||||||
|
|
||||||
|
# Space separated list of plugin names
|
||||||
|
:plugins => %w()
|
||||||
|
|
||||||
|
}
|
|
@ -5,11 +5,16 @@ class Repost < EventMachine::IRC::Client
|
||||||
def dispatch_raw_message(message = {})
|
def dispatch_raw_message(message = {})
|
||||||
self.triggers = [] if self.triggers.nil?
|
self.triggers = [] if self.triggers.nil?
|
||||||
self.triggers.each do |trigger|
|
self.triggers.each do |trigger|
|
||||||
|
# Having per-command lists of blocks of code to call would be
|
||||||
|
# faster, but it's not a problem for now. Might refactor this loop
|
||||||
|
# and register_trigger() method if it comes to that.
|
||||||
trigger[:code].call(message) if message[:command] == trigger[:command]
|
trigger[:code].call(message) if message[:command] == trigger[:command]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_trigger(command, &code)
|
def register_trigger(command, &code)
|
||||||
|
# Make sure the Array of triggers is not empty and then append to it a
|
||||||
|
# Hash containing the command it should be called at and the code
|
||||||
self.triggers = [] if self.triggers.nil?
|
self.triggers = [] if self.triggers.nil?
|
||||||
self.triggers << {:command => command, :code => code}
|
self.triggers << {:command => command, :code => code}
|
||||||
end
|
end
|
||||||
|
|
7
run.rb
7
run.rb
|
@ -3,6 +3,7 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'eventmachine'
|
require 'eventmachine'
|
||||||
require 'em-irc'
|
require 'em-irc'
|
||||||
|
# Our config file is just a single Hash, nothing too fancy.
|
||||||
require_relative 'config'
|
require_relative 'config'
|
||||||
require_relative 'repost'
|
require_relative 'repost'
|
||||||
|
|
||||||
|
@ -23,12 +24,18 @@ repost = Repost.new do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The provided triggers/callbacks for actions are limited - there are no
|
||||||
|
# quit/part callbacks, for example - and we'd have to catch raw messages
|
||||||
|
# anyway. And since we're doing that, we can just go ahead and hook up to
|
||||||
|
# raw callbacks exclusively.
|
||||||
on :raw do |message|
|
on :raw do |message|
|
||||||
self.dispatch_raw_message message
|
self.dispatch_raw_message message
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Loading plugins here, because we need the repost object in scope to be able
|
||||||
|
# to do anything.
|
||||||
Config[:plugins].each do |plugin|
|
Config[:plugins].each do |plugin|
|
||||||
puts "Loading plugin #{plugin}"
|
puts "Loading plugin #{plugin}"
|
||||||
eval File.read(File.dirname($0) + "/plugins/#{plugin}.rb")
|
eval File.read(File.dirname($0) + "/plugins/#{plugin}.rb")
|
||||||
|
|
Loading…
Reference in a new issue