From 693d44191f8ea0788fd49d9c7e00fc499da215d1 Mon Sep 17 00:00:00 2001 From: "Robert \"ar\" Gerus" Date: Sun, 9 Jun 2013 18:21:55 +0200 Subject: [PATCH] some refuctoring and plugin reloading. --- plugins/commands.rb | 4 ++-- plugins/commands/reload.rb | 4 ++-- repost.rb | 14 ++++++++++---- run.rb | 5 +---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/commands.rb b/plugins/commands.rb index a6143cd..5d1f005 100644 --- a/plugins/commands.rb +++ b/plugins/commands.rb @@ -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 diff --git a/plugins/commands/reload.rb b/plugins/commands/reload.rb index c67b0ab..30dca47 100644 --- a/plugins/commands/reload.rb +++ b/plugins/commands/reload.rb @@ -1,5 +1,5 @@ Client.register_command("reload") { |args| - Client.reload_commands + Client.load_plugins - "commands reloaded..." + "plugins reloaded..." } diff --git a/repost.rb b/repost.rb index 9b265c3..d46ea08 100644 --- a/repost.rb +++ b/repost.rb @@ -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 diff --git a/run.rb b/run.rb index b06c7d8..71eef71 100755 --- a/run.rb +++ b/run.rb @@ -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!