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.")
return
end
if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb"))
m.reply("plugin with name #{modname} already exists")
return false;
end
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
begin
if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb"))
m.reply("plugin with name #{modname} already exists")
return false;
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
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
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.")
return
end
if(File.exist?("/var/src/ruby/extendobot/plugins/#{modname}.rb"))
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
unload(m, modname)
mload(m, modname)
end
def unload(m, modname)
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.")
return
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
i = ibot.plugins.find_index { |x| x.class == modname }
if(i != nil)
m.reply("#{modname} already loaded; try :reload instead")
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))
m.reply("#{modname} loaded successfully")
end
end
else
m.reply("#{modname} not found...")
end