commit 465ef0cbbace5df31f7cf9d991d2a4523ef3702f Author: 8dx Date: Mon Jul 1 12:02:17 2013 -0500 initial init diff --git a/classes/Hooks.rb b/classes/Hooks.rb new file mode 100644 index 00000000..93cb385a --- /dev/null +++ b/classes/Hooks.rb @@ -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 + diff --git a/classes/Util.rb b/classes/Util.rb new file mode 100644 index 00000000..416782b3 --- /dev/null +++ b/classes/Util.rb @@ -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 + diff --git a/extendobot b/extendobot new file mode 100755 index 00000000..146b5319 --- /dev/null +++ b/extendobot @@ -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 diff --git a/mixins/authed.r b/mixins/authed.r new file mode 100644 index 00000000..e69de29b diff --git a/plugins/DynPlug.rb b/plugins/DynPlug.rb new file mode 100644 index 00000000..beba2afc --- /dev/null +++ b/plugins/DynPlug.rb @@ -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 + + diff --git a/plugins/Helo.rb b/plugins/Helo.rb new file mode 100644 index 00000000..d7e445bb --- /dev/null +++ b/plugins/Helo.rb @@ -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 + + diff --git a/plugins/PlugList.rb b/plugins/PlugList.rb new file mode 100644 index 00000000..242666f3 --- /dev/null +++ b/plugins/PlugList.rb @@ -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 + +