some refuctoring and plugin reloading.

master
Robert "ar" Gerus 2013-06-09 18:21:55 +02:00
parent b5ff36d688
commit 693d44191f
4 changed files with 15 additions and 12 deletions

View File

@ -24,7 +24,7 @@ class Repost
99
end
def reload_commands
def load_commands
self.commands = []
Dir.glob(File.dirname($0) + "/plugins/commands/*.rb") { |filename|
load filename
@ -33,7 +33,7 @@ class Repost
end
Client.reload_commands
Client.load_commands
Client.register_trigger("PRIVMSG") { |msg|
# who sent the message

View File

@ -1,5 +1,5 @@
Client.register_command("reload") { |args|
Client.reload_commands
Client.load_plugins
"commands reloaded..."
"plugins reloaded..."
}

View File

@ -3,7 +3,6 @@ class Repost < EventMachine::IRC::Client
attr_accessor :triggers
def dispatch_raw_message(message = {})
self.triggers = [] if self.triggers.nil?
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
@ -13,10 +12,17 @@ class Repost < EventMachine::IRC::Client
end
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?
# Append a Hash containing the command it should be called at and the
# and the code.
self.triggers << {:command => command, :code => code}
end
def load_plugins
self.triggers = []
Config[:plugins].each do |plugin|
puts "Loading plugin #{plugin}"
load File.dirname($0) + '/plugins/' + plugin + '.rb'
end if not Config[:plugins].nil?
end
end

5
run.rb
View File

@ -39,9 +39,6 @@ end
# Loading plugins here, because we need the Client object in scope to be able
# to do anything.
Config[:plugins].each do |plugin|
puts "Loading plugin #{plugin}"
load File.dirname($0) + '/plugins/' + plugin + '.rb'
end if not Config[:plugins].nil?
Client.load_plugins
Client.run!