Class: Plugins::Seen
- Inherits:
-
Object
- Object
- Plugins::Seen
- Includes:
- Cinch::Helpers, Cinch::Plugin
- Defined in:
- lib/Zeta/plugins/seen.rb
Defined Under Namespace
Classes: SeenStruct
Instance Method Summary collapse
- #clear_seen ⇒ Object
- #execute(m, nick) ⇒ Object
- #finalize ⇒ Object
-
#initialize(*args) ⇒ Seen
constructor
A new instance of Seen.
- #listen(m) ⇒ Object
- #load_seen ⇒ Object
- #save_seen ⇒ Object
- #sync(m) ⇒ Object
Methods included from Cinch::Plugin
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_seen ⇒ Object
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 |
#finalize ⇒ Object
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., Time.now) end |
#load_seen ⇒ Object
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_seen ⇒ Object
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 |