modified dynplug to notify errors to privmsg

This commit is contained in:
oz modic 2016-03-19 04:09:09 -06:00
parent b2de14958f
commit c39ad7ba64

@ -24,22 +24,32 @@ class DynPlug
m.reply("#{m.user.nick}: your access level is not high enough for this command.") m.reply("#{m.user.nick}: your access level is not high enough for this command.")
return return
end end
if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb")) begin
m.reply("plugin with name #{modname} already exists") if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb"))
return false; m.reply("plugin with name #{modname} already exists")
end return false;
content = ""
open(url) do |f|
content = f.read
content.gsub!(%r{</?[^>]+?>}, '')
open("/var/src/ruby/extendobot/plugins/#{modname}.rb", "w") do |plugin|
plugin.write content
end end
content = ""
begin
open(url) do |f|
content = f.read
content.gsub!(%r{</?[^>]+?>}, '')
open("/var/src/ruby/extendobot/plugins/#{modname}.rb", "w") do |plugin|
plugin.write content
end
end
rescue Exception => error
m.user.send("Error downloading #{modname}: #{error}")
end
load "/var/src/ruby/extendobot/plugins/#{modname}.rb";
ibot = Util::BotFamily.instance.get(Util::Util.instance.hton(m.bot.config.server)).bot
ibot.plugins.register_plugin(Object.const_get(modname))
m.reply("#{modname} added successfully")
rescue Exception => error
m.user.send "Error loading #{modname}: #{error}"
m.reply "Error loading, deleting downloaded module. Check privmsg for details"
m.user.send "#{modname}.rb deleted" if File.unlink "/var/src/ruby/extendobot/plugins/#{modname}.rb"
end end
load "/var/src/ruby/extendobot/plugins/#{modname}.rb";
ibot = Util::BotFamily.instance.get(Util::Util.instance.hton(m.bot.config.server)).bot
ibot.plugins.register_plugin(Object.const_get(modname))
m.reply("#{modname} added successfully")
end end
def reload(m, modname) def reload(m, modname)
@ -48,19 +58,9 @@ class DynPlug
m.reply("#{m.user.nick}: your access level is not high enough for this command.") m.reply("#{m.user.nick}: your access level is not high enough for this command.")
return return
end end
if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb")) unload(m, modname)
mload(m, modname)
ibot = Util::BotFamily.instance.get(Util::Util.instance.hton(m.bot.config.server)).bot
i = ibot.plugins.find_index { |x| x.class == Kernel.const_get(modname) }
ibot.plugins.unregister_plugin(ibot.bot.plugins[i])
load "/var/src/ruby/extendobot/plugins/#{modname}.rb"
ibot.plugins.register_plugin(Object.const_get(modname))
m.reply("#{modname} reloaded successfully")
else
m.reply("#{modname} not found...")
end
end end
def unload(m, modname) def unload(m, modname)
aclcheck(m) aclcheck(m)
if(!aclcheck(m)) if(!aclcheck(m))
@ -88,17 +88,22 @@ class DynPlug
m.reply("#{m.user.nick}: your access level is not high enough for this command.") m.reply("#{m.user.nick}: your access level is not high enough for this command.")
return return
end end
if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb")) if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb"))
ibot = Util::BotFamily.instance.get(Util::Util.instance.hton(m.bot.config.server)).bot ibot = Util::BotFamily.instance.get(Util::Util.instance.hton(m.bot.config.server)).bot
i = ibot.plugins.find_index { |x| x.class == modname } i = ibot.plugins.find_index { |x| x.class == modname }
if(i != nil) if(i != nil)
m.reply("#{modname} already loaded; try :reload instead") m.reply("#{modname} already loaded; try :reload instead")
else else
load "/var/src/ruby/extendobot/plugins/#{modname}.rb" begin
load "/var/src/ruby/extendobot/plugins/#{modname}.rb"
rescue Exception => error
m.reply "Error loading #{modname}. check privmsg for details"
m.user.send "Error loading #{modname}: #{error}"
return
end
ibot.plugins.register_plugin(Object.const_get(modname)) ibot.plugins.register_plugin(Object.const_get(modname))
m.reply("#{modname} loaded successfully") m.reply("#{modname} loaded successfully")
end end
else else
m.reply("#{modname} not found...") m.reply("#{modname} not found...")
end end