messed around a lot with Util adding some stuff in there BotTools is fixed so join/part/stay should be working Markovian was configured to ignore certain content eg urls RawCmd is updated to actually spit back error messages, as well as inform people when they lack sufficien tACL Replace just had a <> wrapped around the nick URLThief is a new idea that just grabs urls as they come into chat along with a simple interface for getting random ones or regex to find other ones URLInfo moved to a disabled folder I created for disabled plugins as it conflicts with g1mp Artism as well is a new project, intended for playing ANSI art, as well as grabbing it from online and translating it with ansirc in real time. tcpbot just a symlink to extendobot. Next update: prolly gonna have a ton of ansi files in this bitch.
90 lines
2.4 KiB
Ruby
90 lines
2.4 KiB
Ruby
require 'cinch'
|
|
require 'open-uri'
|
|
require 'uri'
|
|
require_relative '../classes/Util.rb'
|
|
class URLThief
|
|
include Cinch::Plugin
|
|
include Hooks::ACLHook
|
|
include Util::PluginHelper
|
|
listen_to :channel
|
|
set :prefix, /^:/
|
|
@clist = %w{url.rand}
|
|
@@commands["url.rand"] = ":url.rand - spit out a random url from the url db"
|
|
match /url\.rand/, method: :url_rand
|
|
#@clist.push('url.find')
|
|
#@@commands "url.find" = ":url.find /regex/ - search through url list to find any matching urls?!!?"
|
|
#match /url\.find \/(.+?)\//, method: :url_find
|
|
|
|
|
|
def url_find(m, regex)
|
|
db = Util::Util.instance.getCollection("extendobot","urls")
|
|
res = db.find({
|
|
"url" => /#{regex}/i
|
|
}).to_a
|
|
resp = "#{m.user.nick}: "
|
|
if(res.empty?)
|
|
resp << Util::Util.instance.getExcuse() << " (couldn't find anything matching /#{}regex}/)"
|
|
else
|
|
resp << "here is what i found for /#{regex}/:\n" << res.map {|e| e['url'] }.join(" | ")
|
|
end
|
|
m.reply(resp)
|
|
end
|
|
|
|
def url_rand(m)
|
|
|
|
db = Util::Util.instance.getCollection("extendobot","urls")
|
|
proj = {
|
|
"$project": {
|
|
url: 1,
|
|
"_id": 0
|
|
}
|
|
}
|
|
res = db.aggregate([
|
|
{
|
|
"$match": {
|
|
"server": Util::Util.instance.hton(m.bot),
|
|
}
|
|
},
|
|
proj,
|
|
{
|
|
"$sample": {
|
|
size: 1
|
|
}
|
|
}
|
|
]).to_a.shift
|
|
resp = "#{m.user.nick}: "
|
|
if(res.nil?)
|
|
exc = Util::Util.instance.getExcuse()
|
|
resp << "#{exc} (couldn't find a url lol)"
|
|
else
|
|
resp << res['url']
|
|
m.reply("#{m.user.nick}: #{res['url']}")
|
|
end
|
|
end
|
|
|
|
def listen(m)
|
|
text = m.message
|
|
user = m.user.nick
|
|
#return if (["sayok","g1mp","van","durnkb0t", "[0]"].include? user)
|
|
|
|
return if m.message.match /^:/
|
|
channel = m.channel.name
|
|
schemes = %w{http https ftp gemini gopher irc ssh}
|
|
urxp = URI.regexp(schemes)
|
|
if(text.match(urxp))
|
|
debug "got urlz in msg: #{text}."
|
|
urls = URI.extract(text,schemes)
|
|
debug "url list:" + urls.join(', ')
|
|
urls.each { |url|
|
|
db = Util::Util.instance.getCollection("extendobot","urls")
|
|
tm = Time.now.to_i
|
|
server = Util::Util.instance.hton("#{m.bot.config.server}:#{m.bot.config.port}")
|
|
puts "inserting #{url} into db..."
|
|
db.insert_one({'channel' => channel, 'url' => url, 'time' => tm, 'server' => server})
|
|
}
|
|
else
|
|
puts "oops no urls in '#{text}'"
|
|
end
|
|
end
|
|
end
|