class Plugin_manager
Public Class Methods
new(plugin_folder)
click to toggle source
# File lib/rirc.rb, line 125 def initialize(plugin_folder) @plugins = [] @plugin_folder = plugin_folder @err_path = "./.errlog" end
Public Instance Methods
add_chan(plugin_name, channel)
click to toggle source
# File lib/rirc.rb, line 209 def add_chan(plugin_name, channel) if !plugin_loaded(name) return "#{plugin_name} is not loaded" end get_plugin(name).add_chan(channel) return "#{channel} added to #{plugin_name}" end
add_chan_clear_any(plugin_name, channel)
click to toggle source
# File lib/rirc.rb, line 219 def add_chan_clear_any(plugin_name, channel) if !plugin_loaded(name) return "#{plugin_name} is not loaded" end rm_chan(plugin_name, "any") add_chan(plugin_name, channel) return "#{channel} added to #{plugin_name}" end
check_all(message, admins, backlog)
click to toggle source
regex check function that returns responses for all plugins in an array inputs:
- IRC_message object - array of admins [can be an empty array] - backlog array [can be an empty array]
output: array of strings
# File lib/rirc.rb, line 366 def check_all(message, admins, backlog) if @plugins.length == 0 return [] end response = [] # this is incredibly inneficient but it makes check_plugin flexible @plugins.each { |a| response.push(check_plugin(a.name, message, admins, backlog)) } return response end
check_plugin(name, message, admins, backlog)
click to toggle source
regex check function this function uses the IRC_message
object for message input inputs:
- name - IRC_message object - array of admins [can be an empty array] - backlog array [can be an empty array]
output: string
# File lib/rirc.rb, line 332 def check_plugin(name, message, admins, backlog) #checks an individual plugin's (by name) regex against message if @plugins.length == 0 return "" end if !plugin_loaded(name) return "" else if message.message.match(get_plugin(name).regex) and (get_plugin(name).chans.include? "any" or get_plugin(name).chans.include? message.channel) begin return get_plugin(name).script(message, admins, backlog) # plugins use the IRC_message object rescue => e if File.exist?(@err_path) File.write(@err_path, "PLUGIN #{name} FAILED TO RUN", File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') File.write(@err_path, e.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, e.backtrace.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') end return "an error occured for plugin: #{name}" end end end return "" end
get_chans()
click to toggle source
# File lib/rirc.rb, line 187 def get_chans if @plugins.length == 0 return [] end names = [] @plugins.each { |a| names.push(a.chans) } return names end
get_files()
click to toggle source
# File lib/rirc.rb, line 174 def get_files if @plugins.length == 0 return [] end names = [] @plugins.each { |a| names.push(a.file_name) } return names end
get_helps()
click to toggle source
# File lib/rirc.rb, line 161 def get_helps if @plugins.length == 0 return [] end names = [] @plugins.each { |a| names.push(a.help) } return names end
get_names()
click to toggle source
search functions
# File lib/rirc.rb, line 148 def get_names if @plugins.length == 0 return [] end names = [] @plugins.each { |a| names.push(a.name) } return names end
get_plugin(name)
click to toggle source
# File lib/rirc.rb, line 253 def get_plugin(name) # gets a plugin by name or nil if it is not loaded if @plugins.length == 0 return nil end @plugins.each { |a| if a.name == name then return a end } return nil end
get_regexps()
click to toggle source
# File lib/rirc.rb, line 240 def get_regexps if @plugins.length == 0 return [] end names = [] @plugins.each { |a| names.push(a.regex) } return names end
plugin_chans(name)
click to toggle source
# File lib/rirc.rb, line 286 def plugin_chans(name) # gets the array of channels for a plugin if @plugins.length == 0 return nil end @plugins.each { |a| if a.name == name then return a.chans end } return nil end
plugin_file_name(name)
click to toggle source
# File lib/rirc.rb, line 275 def plugin_file_name(name) # gets the file name for a plugin if @plugins.length == 0 return nil end @plugins.each { |a| if a.name == name then return a.file_name end } return nil end
plugin_help(name)
click to toggle source
# File lib/rirc.rb, line 264 def plugin_help(name) # gets the help for a plugin if @plugins.length == 0 return nil end @plugins.each { |a| if a.name == name then return a.help end } return nil end
plugin_load(name)
click to toggle source
load
# File lib/rirc.rb, line 381 def plugin_load(name) $LOAD_PATH << "#{@plugin_folder}" response = "" temp_plugin = nil if name.match(/.rb$/) begin load "#{name}" plugin_loader = Loader.new temp_plugin = plugin_loader.get_plugin if plugin_loaded(temp_plugin.name) temp_plugin = nil return "Plugin #{name} is already loaded" end @plugins.push(temp_plugin) temp_plugin = nil response = "#{name[0..-4]} loaded" rescue => e response = "cannot load plugin" if File.exist?(@err_path) File.write(@err_path, "PLUGIN #{name} FAILED TO LOAD", File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') File.write(@err_path, e.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, e.backtrace.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') end end else begin load "#{name}.rb" plugin_loader = Loader.new temp_plugin = plugin_loader.get_plugin if plugin_loaded(temp_plugin.name) temp_plugin = nil return "Plugin #{name} is already loaded" end @plugins.push(temp_plugin) temp_plugin = nil response = "#{name} loaded" rescue => e response = "cannot load plugin" if File.exist?(@err_path) File.write(@err_path, "PLUGIN #{name} FAILED TO LOAD", File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') File.write(@err_path, e.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, e.backtrace.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') end end end $LOAD_PATH << './' return response end
plugin_loaded(name)
click to toggle source
check if a plugin is loaded
# File lib/rirc.rb, line 309 def plugin_loaded(name) if @plugins.length == 0 return false end @plugins.each do |a| if a.name == name return true end end return false end
plugin_regex(name)
click to toggle source
# File lib/rirc.rb, line 297 def plugin_regex(name) # gets the regex for a plugin if @plugins.length == 0 return nil end @plugins.each { |a| if a.name == name then return a.regex end } return nil end
plugins()
click to toggle source
def initialize(plugin_folder, err_path) @plugins = [] @plugin_folder = plugin_folder @err_path = err_path.to_s end
# returns all the plugins
# File lib/rirc.rb, line 138 def plugins if @plugins.length == 0 return [] end return @plugins end
reload(name)
click to toggle source
reload
# File lib/rirc.rb, line 449 def reload(name) if !plugin_loaded(name) return "plugin is not loaded" end temp_file_name = get_plugin(name).file_name unload(name) plugin_load(temp_file_name) return "plugin #{name} reloaded" end
rm_chan(plugin_name, channel)
click to toggle source
# File lib/rirc.rb, line 230 def rm_chan(plugin_name, channel) if !plugin_loaded(name) return "#{plugin_name} is not loaded" end get_plugin(name).rm_chan(channel) return "#{channel} removed from #{plugin_name}" end
unload(name)
click to toggle source
unload
# File lib/rirc.rb, line 436 def unload(name) if !plugin_loaded(name) return "plugin is not loaded" end get_plugin(name).cleanup @plugins.delete_if { |a| a.name == name } return "plugin #{name} unloaded" end