Class: Cinch::Plugins::Notes

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/plugins/notes.rb,
lib/cinch/plugins/notes/note.rb,
lib/cinch/plugins/notes/version.rb

Overview

Versioning Info

Defined Under Namespace

Classes: Note

Constant Summary collapse

VERSION =
'1.0.4'

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Notes

Returns a new instance of Notes.



15
16
17
18
19
# File 'lib/cinch/plugins/notes.rb', line 15

def initialize(*args)
  super
  @storage = Cinch::Storage.new(config[:filename] || 'yaml/notes.yml')
  @storage.data ||= {}
end

Instance Method Details

#make_note(m, user, message) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/cinch/plugins/notes.rb', line 21

def make_note(m, user, message)
  note = Note.new(m.user.nick, user, message)
  @storage.data[user.downcase] ||= []
  @storage.data[user.downcase] << note
  @storage.synced_save(@bot)
  m.reply 'ok, I will let them know!'
end

#send_notes(m) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/cinch/plugins/notes.rb', line 29

def send_notes(m)
  nick = m.user.nick.downcase
  return unless @storage.data.key?(nick)
  @storage.data[nick].each do |note|
    next if note.sent
    m.user.send("#{note.from} asked me to tell you '#{note.message}'")
    note.mark_sent
  end
  @storage.synced_save(@bot)
end