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
|
99
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload_commands
|
def load_commands
|
||||||
self.commands = []
|
self.commands = []
|
||||||
Dir.glob(File.dirname($0) + "/plugins/commands/*.rb") { |filename|
|
Dir.glob(File.dirname($0) + "/plugins/commands/*.rb") { |filename|
|
||||||
load filename
|
load filename
|
||||||
|
@ -33,7 +33,7 @@ class Repost
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Client.reload_commands
|
Client.load_commands
|
||||||
|
|
||||||
Client.register_trigger("PRIVMSG") { |msg|
|
Client.register_trigger("PRIVMSG") { |msg|
|
||||||
# who sent the message
|
# who sent the message
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Client.register_command("reload") { |args|
|
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
|
attr_accessor :triggers
|
||||||
|
|
||||||
def dispatch_raw_message(message = {})
|
def dispatch_raw_message(message = {})
|
||||||
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
|
# 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
|
# faster, but it's not a problem for now. Might refactor this loop
|
||||||
|
@ -13,10 +12,17 @@ class Repost < EventMachine::IRC::Client
|
||||||
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
|
# Append a Hash containing the command it should be called at and the
|
||||||
# Hash containing the command it should be called at and the code
|
# and the code.
|
||||||
self.triggers = [] if self.triggers.nil?
|
|
||||||
self.triggers << {:command => command, :code => code}
|
self.triggers << {:command => command, :code => code}
|
||||||
end
|
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
|
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
|
# Loading plugins here, because we need the Client object in scope to be able
|
||||||
# to do anything.
|
# to do anything.
|
||||||
Config[:plugins].each do |plugin|
|
Client.load_plugins
|
||||||
puts "Loading plugin #{plugin}"
|
|
||||||
load File.dirname($0) + '/plugins/' + plugin + '.rb'
|
|
||||||
end if not Config[:plugins].nil?
|
|
||||||
|
|
||||||
Client.run!
|
Client.run!
|
||||||
|
|
Loading…
Reference in a new issue