Class: Plugins::Seen

Inherits:
Object
  • Object
show all
Includes:
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.



26
27
28
29
# File 'lib/Zeta/plugins/seen.rb', line 26

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

Instance Method Details

#clear_seenObject



79
80
81
82
# File 'lib/Zeta/plugins/seen.rb', line 79

def clear_seen
  @users = {}
  File.delete(File.join(Dir.home, '.zeta', 'cache', 'seen.rb'))
end

#execute(m, nick) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/Zeta/plugins/seen.rb', line 41

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)
    m.reply @users[nick].to_s
  else
    m.reply "I haven't seen #{nick}"
  end
end

#finalizeObject



31
32
33
# File 'lib/Zeta/plugins/seen.rb', line 31

def finalize
  save_seen()
end

#listen(m) ⇒ Object



35
36
37
38
39
# File 'lib/Zeta/plugins/seen.rb', line 35

def listen(m)
  return if m.channel == '#staff'
  return if m.channel == '#netops'
  @users[m.user.nick] = SeenStruct.new(m.user, m.channel, m.message, Time.now)
end

#load_seenObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/Zeta/plugins/seen.rb', line 65

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



58
59
60
61
62
63
# File 'lib/Zeta/plugins/seen.rb', line 58

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



54
55
56
# File 'lib/Zeta/plugins/seen.rb', line 54

def sync(m)
  save_seen()
end