initial init
This commit is contained in:
commit
465ef0cbba
40
classes/Hooks.rb
Normal file
40
classes/Hooks.rb
Normal file
@ -0,0 +1,40 @@
|
||||
require 'cinch'
|
||||
require_relative 'Util.rb'
|
||||
module Hooks
|
||||
module AuthHook
|
||||
include Cinch::Plugin
|
||||
hook :pre, method: :is_authed
|
||||
def is_authed(m)
|
||||
user = m.user;
|
||||
if m.authed?
|
||||
Thread.current[:authpass] = true
|
||||
return true
|
||||
else
|
||||
Thread.current[:authpass] = false
|
||||
return false;
|
||||
end
|
||||
end
|
||||
end
|
||||
module ACLHook
|
||||
include Cinch::Plugin
|
||||
@cmdname = ""
|
||||
@levelRequired = ""
|
||||
hook :pre, method: :aclcheck
|
||||
def aclcheck(m)
|
||||
debug "performing aclcheck against #{m.user.name}"
|
||||
user = m.user.name
|
||||
acl = Util::Util.instance.getDB("acl")
|
||||
users = acl.collection("users")
|
||||
res = users.find_one({'user' => user})
|
||||
Thread.current[:result] = res
|
||||
if res['level'] >= @levelRequired
|
||||
Thread.current[:aclpass] = true
|
||||
return true
|
||||
else
|
||||
Thread.current[:aclpass] = false
|
||||
return false;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
57
classes/Util.rb
Normal file
57
classes/Util.rb
Normal file
@ -0,0 +1,57 @@
|
||||
require 'pathname'
|
||||
require 'cinch'
|
||||
require_relative "Hooks.rb"
|
||||
|
||||
module Util
|
||||
class Util
|
||||
require 'mongo';
|
||||
include Mongo;
|
||||
def self.instance
|
||||
@@instance ||= new
|
||||
end
|
||||
def initialize
|
||||
@@mongo = MongoClient.new
|
||||
end
|
||||
def getConn
|
||||
return @@mongo
|
||||
end
|
||||
def getDB(dbn)
|
||||
return @@mongo.db(dbn)
|
||||
end
|
||||
def getCollection(dbn,col)
|
||||
return @@mongo.db(dbn).collection(col)
|
||||
end
|
||||
end
|
||||
class Bot
|
||||
def self.instance
|
||||
@@instance ||= new
|
||||
end
|
||||
attr_accessor :bot
|
||||
def initialize
|
||||
@bot = Cinch::Bot.new do
|
||||
configure do |c|
|
||||
c.server = "irc.wtfux.org"
|
||||
mong = Util.instance
|
||||
conf = mong.getCollection("extendobot","config");
|
||||
nick = conf.find_one({'key' => "nick"})
|
||||
c.nick = nick['val']
|
||||
chans = mong.getCollection("chans","channels")
|
||||
cList = chans.find({'autojoin' => true}).collect { |x|
|
||||
x['channel']
|
||||
}
|
||||
c.channels = cList
|
||||
pList = Array.new
|
||||
Pathname.glob("/var/src/ruby/extendobot/plugins/*.rb").each { |plugin|
|
||||
require plugin
|
||||
pList.push(Object.const_get(File.basename(plugin.basename,File.extname(plugin)).to_s))
|
||||
}
|
||||
c.plugins.plugins = pList;
|
||||
end
|
||||
end
|
||||
end
|
||||
def start
|
||||
@bot.start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
8
extendobot
Executable file
8
extendobot
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/ruby1.9.1
|
||||
|
||||
require 'cinch'
|
||||
require_relative './classes/Util'
|
||||
|
||||
utils = Util::Util.instance;
|
||||
bot = Util::Bot.instance;
|
||||
bot.start
|
0
mixins/authed.r
Normal file
0
mixins/authed.r
Normal file
37
plugins/DynPlug.rb
Normal file
37
plugins/DynPlug.rb
Normal file
@ -0,0 +1,37 @@
|
||||
require 'cinch'
|
||||
require 'open-uri'
|
||||
require_relative '../classes/Util.rb'
|
||||
class DynPlug
|
||||
include Cinch::Plugin
|
||||
include Hooks::ACLHook
|
||||
set :prefix, /^:/
|
||||
@commandName = "dynload"
|
||||
@levelRequired = 10
|
||||
match /dynload ([a-zA-Z][a-zA-Z0-9]+) (.+)/;
|
||||
|
||||
def execute(m, modname, url)
|
||||
if(!Thread.current[:aclpass])
|
||||
m.reply("#{m.user.name}: your access level is not high enough for this command.")
|
||||
debug Thread.current.inspect
|
||||
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
|
||||
end
|
||||
end
|
||||
require "/var/src/ruby/extendobot/plugins/#{modname}.rb";
|
||||
ibot = Util::Bot.instance
|
||||
ibot.bot.plugins.register_plugin(Object.const_get(modname))
|
||||
m.reply("#{modname} added successfully")
|
||||
end
|
||||
end
|
||||
|
||||
|
14
plugins/Helo.rb
Normal file
14
plugins/Helo.rb
Normal file
@ -0,0 +1,14 @@
|
||||
require 'cinch'
|
||||
require_relative '../classes/Util.rb'
|
||||
class Helo
|
||||
include Cinch::Plugin
|
||||
set :prefix, /^:/
|
||||
extend Hooks::ACLHook
|
||||
match /helo/;
|
||||
|
||||
def execute(m)
|
||||
m.reply "helo #{m.user.name}"
|
||||
end
|
||||
end
|
||||
|
||||
|
19
plugins/PlugList.rb
Normal file
19
plugins/PlugList.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require 'cinch'
|
||||
require_relative '../classes/Util.rb'
|
||||
class PlugList
|
||||
include Cinch::Plugin
|
||||
@@commandName = "plugs"
|
||||
set :prefix, /^:/
|
||||
match /plugs/
|
||||
|
||||
def execute(m)
|
||||
ibot = Util::Bot.instance
|
||||
str = ""
|
||||
ibot.bot.plugins.each do |plug|
|
||||
str += " #{plug.class.name}"
|
||||
end
|
||||
m.reply str
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user