some refuctoring and plugin reloading.
This commit is contained in:
parent
b5ff36d688
commit
693d44191f
4 changed files with 15 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Client.register_command("reload") { |args|
|
||||
Client.reload_commands
|
||||
Client.load_plugins
|
||||
|
||||
"commands reloaded..."
|
||||
"plugins reloaded..."
|
||||
}
|
||||
|
|
14
repost.rb
14
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
|
||||
|
|
5
run.rb
5
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!
|
||||
|
|
Loading…
Reference in a new issue