did a lot of stuff

This commit is contained in:
oz modic 2016-03-14 22:25:53 -06:00
parent c64a0a146e
commit 46add55e5b
9 changed files with 112 additions and 30 deletions

Binary file not shown.

@ -20,10 +20,9 @@ module Hooks
@@levelRequired = 0
def aclcheck(m)
user = m.user.nick
acl = Util::Util.instance.getDB("acl")
users = acl.collection("users")
users = Util::Util.instance.getCollection("acl","users")
name = Util::Util.instance.hton(m.bot.config.server)
res = users.find_one({'user' => user, 'server' => name})
res = users.find({'user' => user, 'server' => name}).each.next_values()[0]
Thread.current[:result] = res
if res['level'].to_i >= @@levelRequired.to_i
Thread.current[:aclpass] = true

@ -6,20 +6,22 @@ module Util
class Util
require 'mongo';
include Mongo;
def self.instance
Mongo::Logger.logger.level = ::Logger::FATAL
def self.instance
@@instance ||= new
end
def initialize
@@mongo = MongoClient.new
end
def getConn
return @@mongo
@@url = "127.0.0.1:27017"
@@mongos = {};
@@mongos[:chans] = Mongo::Client.new([@@url], :database => "chans")
@@mongos[:extendobot] = Mongo::Client.new([@@url], :database => "extendobot")
@@mongos[:acl] = Mongo::Client.new([@@url], :database => "acl")
end
def getDB(dbn)
return @@mongo.db(dbn)
return @@mongos[dbn.to_sym]
end
def getCollection(dbn,col)
return @@mongo.db(dbn).collection(col)
return self.getDB(dbn)[col.to_sym]
end
def getServers()
servers = Array.new()
@ -31,7 +33,9 @@ module Util
end
def hton(host)
col = getCollection("chans","servers")
return col.find_one({ "host" => host })['name']
name = ""
name = col.find({ "host" => host }).limit(1).each
return name.next_values()[0]["name"];
end
def MainLoop
Thread.list.each { |thr|
@ -92,11 +96,10 @@ module Util
@bot = Cinch::Bot.new do
configure do |c|
c.server = host
mong = Util.instance
mong = Util.new
conf = mong.getCollection("extendobot","config");
name = Util.instance.hton(host)
nick = conf.find_one({ 'key' => 'nick', 'server' => name })
c.nick = nick['val']
name = mong.hton(host)
c.nick = conf.find({ 'key' => 'nick', 'server' => name }).each.next_values()[0]["val"]
chans = mong.getCollection("chans","channels")
cList = chans.find({'autojoin' => true, 'server' => name}).collect { |x|
x['channel']
@ -104,10 +107,13 @@ module Util
c.channels = cList
pList = Array.new
Pathname.glob("/var/src/ruby/extendobot/plugins/*.rb").each { |plugin|
require plugin
puts "found plugin #{plugin}"
load plugin
puts Object.const_get(File.basename(plugin.basename,File.extname(plugin)).to_s)
pList.push(Object.const_get(File.basename(plugin.basename,File.extname(plugin)).to_s))
}
c.plugins.plugins = pList;
c.plugins.plugins = pList
end
end

@ -3,7 +3,7 @@
require 'cinch'
require_relative './classes/Util'
utils = Util::Util.instance;
utils = Util::Util.new;
bots = Util::BotFamily.instance
servers = utils.getServers()
servers.each { |serv|
@ -14,8 +14,9 @@ servers.each { |serv|
}
)
puts "autoconnect to #{serv['name']}"
else
puts "ignoring #{serv['name']}"
end
puts "ignoring #{serv['name']}"
}
bots.startAll
utils.MainLoop

Binary file not shown.

@ -7,10 +7,17 @@ class DynPlug
include Util::PluginHelper
set :prefix, /^:/
@@commands["dynload"] = ":dynload <plugname> <url> - dynamically load a plugin from <url> using <plugname> as plugin name"
@@commands["reload"] = ":reload <plugname> - reload plugin source"
@@commands["unload"] = ":unload <plugname> - unload plugin source"
@@commands["load"] = ":load <plugname> - load plugin source"
@@levelRequired = 10
match /dynload ([a-zA-Z][a-zA-Z0-9]+) (.+)/;
match /dynload ([a-zA-Z][a-zA-Z0-9]+) (.+)/, method: :dynload;
match /reload ([a-zA-Z][a-zA-Z0-9]+)/, method: :reload;
match /unload ([a-zA-Z][a-zA-Z0-9]+)/, method: :unload;
match /load ([a-zA-Z][a-zA-Z0-9]+)/, method: :mload;
def execute(m, modname, url)
def dynload(m, modname, url)
aclcheck(m)
if(!aclcheck(m))
m.reply("#{m.user.nick}: your access level is not high enough for this command.")
@ -28,11 +35,76 @@ class DynPlug
plugin.write content
end
end
require "/var/src/ruby/extendobot/plugins/#{modname}.rb";
ibot = Util::BotFamily.instance.get(Util::Util.instance.hton(m.bot.config.server))
ibot.bot.plugins.register_plugin(Object.const_get(modname))
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)
aclcheck(m)
if(!aclcheck(m))
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
end
def unload(m, modname)
aclcheck(m)
if(!aclcheck(m))
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) }
if(i == nil)
m.reply("#{modname} not loaded currently")
else
ibot.plugins.unregister_plugin(ibot.bot.plugins[i])
m.reply("#{modname} unloaded successfully")
end
else
m.reply("#{modname} not found...")
end
end
def mload(m, modname)
aclcheck(m)
if(!aclcheck(m))
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 == modname }
if(i != nil)
m.reply("#{modname} already loaded; try :reload instead")
else
load "/var/src/ruby/extendobot/plugins/#{modname}.rb"
ibot.plugins.register_plugin(Object.const_get(modname))
m.reply("#{modname} loaded successfully")
end
else
m.reply("#{modname} not found...")
end
end
end

@ -4,7 +4,7 @@ class Helo
include Cinch::Plugin
include Util::PluginHelper
set :prefix, /^:/
@@commands["helo"] = ":helo - say hi!"
@@commands["helo"] = ":helo - say helo"
match /helo/;
def execute(m)

@ -5,13 +5,14 @@ class Help
include Util::PluginHelper
@@commands["help"] = ":help [<cmd>] - produce help for <cmd>"
set :prefix, /^:/
match /help (.+)?/, method: :gethelp
match /help( .+)?/, method: :gethelp
def gethelp(m, mdl = nil)
case mdl
when nil
m.reply("try :help <cmd> to get help for a command.")
else
mdl.strip!
cmds = self.class.class_eval { @@commands }
m.reply(cmds[mdl])
end

@ -7,11 +7,14 @@ class PlugTool
@@commands["commands"] = ":commands - produce list of commands"
set :prefix, /^:/
match /commands/, method: :pluginfo
match /plugs/, method: :interstitial
match /plugs( .+)?/, method: :interstitial
def interstitial(m, sub = nil)
debug "in interstitial, for sub to #{sub.to_s}"
case sub
def interstitial(m, filter = nil)
debug "in interstitial, for filter to #{filter.to_s}"
if(filter != nil)
filter.strip!
end
case filter
when ".enabled"
plugs(m,:enabled)
when ".disabled"