Class: Plugins::Seen

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, Cinch::Helpers, Cinch::Plugin
Defined in:
lib/Zeta/plugins/seen.rb

Defined Under Namespace

Classes: SeenStruct

Instance Method Summary collapse

Methods included from Cinch::Plugin

#check?, #log2chan

Constructor Details

#initialize(*args) ⇒ Seen

Returns a new instance of Seen.



16
17
18
19
# File 'lib/Zeta/plugins/seen.rb', line 16

def initialize(*args)
  super
  @users = load_seen
end

Instance Method Details

#clear_seenObject



69
70
71
72
# 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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

#finalizeObject



21
22
23
# File 'lib/Zeta/plugins/seen.rb', line 21

def finalize
  save_seen()
end

#listen(m) ⇒ Object



25
26
27
28
# 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_seenObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# 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_seenObject



48
49
50
51
52
53
# 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) ⇒ Object



44
45
46
# File 'lib/Zeta/plugins/seen.rb', line 44

def sync(m)
  save_seen()
end