41 lines
1.2 KiB
Ruby
41 lines
1.2 KiB
Ruby
|
require 'cinch'
|
||
|
require 'open-uri'
|
||
|
require 'time_difference'
|
||
|
require 'date'
|
||
|
require_relative '../classes/Util.rb'
|
||
|
class OnSight
|
||
|
include Cinch::Plugin
|
||
|
include Hooks::ACLHook
|
||
|
include Util::PluginHelper
|
||
|
@clist = %w{seen}
|
||
|
@@commands["seen"] = ":seen <nick> - when was the last time <nick> was seen? "
|
||
|
set :prefix, /^:/
|
||
|
match /seen (.+?)$/, method: :seen
|
||
|
|
||
|
def seen(m, nick)
|
||
|
db = Util::Util.instance.getCollection("extendobot","logs")
|
||
|
puts "seen seen seen seen\n"*10
|
||
|
puts ":seen #{nick}"
|
||
|
res = db.find({
|
||
|
"server" => Util::Util.instance.hton("#{m.bot.config.server}:#{m.bot.config.port}"),
|
||
|
"channel" => m.channel.name,
|
||
|
'user' => nick
|
||
|
}).limit(1).sort({"time" => -1})
|
||
|
out = ""
|
||
|
debug "lastseen #{nick}?\n"*10
|
||
|
if(res.count > 0)
|
||
|
row = res.to_a.shift
|
||
|
tm = row[:time]
|
||
|
dt = Time.at(tm)
|
||
|
now = Time.now
|
||
|
td = TimeDifference.between(dt,now).humanize
|
||
|
out << "<#{row[:user]}>" << " "
|
||
|
out << row['text']
|
||
|
out << "\n#{td.downcase} ago (#{dt.strftime '%c'})"
|
||
|
else
|
||
|
out << "who tf is #{nick}?"
|
||
|
end
|
||
|
m.reply(out)
|
||
|
end
|
||
|
end
|