class Plugins::Seen

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/Zeta/plugins/seen.rb, line 16
def initialize(*args)
  super
  @users = load_seen
end

Public Instance Methods

clear_seen() click to toggle source
# File lib/Zeta/plugins/seen.rb, line 69
def clear_seen
  @users = {}
  File.delete(File.join(Dir.home, '.zeta', 'cache', 'seen.rb'))
end
execute(m, nick) click to toggle source
# File lib/Zeta/plugins/seen.rb, line 30
def execute(m, nick)
  nick.rstrip!
  if nick == @bot.nick
    m.reply 'You are a Stupid human!'
  elsif nick == m.user.nick
    m.reply "Unfortunately, I see an idiot by the name of #{m.user.nick}"
  elsif @users.key?(nick) && (@users[nick].where == m.channel)
    time_ago = time_ago_in_words(Time.at(@users[nick].time))
    m.reply "Seen ∴ \x0304#{@users[nick].who}\x0F was last seen talking in here about \x02#{time_ago}\x0F ago."
  else
    m.reply "I haven't seen #{nick} say anything yet!"
  end
end
finalize() click to toggle source
# File lib/Zeta/plugins/seen.rb, line 21
def finalize
  save_seen()
end
listen(m) click to toggle source
# File lib/Zeta/plugins/seen.rb, line 25
def listen(m)
  return if m.channel == '#services'
  @users[m.user.nick] = SeenStruct.new(m.user, m.channel, Time.now)
end
load_seen() click to toggle source
# File lib/Zeta/plugins/seen.rb, line 55
def load_seen
  if File.exists?(File.join(Dir.home, '.zeta', 'cache', 'seen.rb'))
    begin
      File.open(File.join(Dir.home, '.zeta', 'cache', 'seen.rb')) do |file|
        return Marshal.load(file)
      end
    rescue
      return Hash.new
    end
  else
    return Hash.new
  end
end
save_seen() click to toggle source
# File lib/Zeta/plugins/seen.rb, line 48
def save_seen
  File.open(File.join(Dir.home, '.zeta', 'cache', 'seen.rb'), 'w+') do |file|
    Marshal.dump(@users, file)
  end

end
sync(m) click to toggle source
# File lib/Zeta/plugins/seen.rb, line 44
def sync(m)
  save_seen()
end