3 # :title: Note plugin for rbot
5 # Author:: dmitry kim <dmitry dot kim at gmail dot com>
7 # Copyright:: (C) 200?-2009 dmitry 'jsn' kim
9 # License:: MIT license
11 class NotePlugin < Plugin
13 Note = Struct.new('Note', :time, :from, :private, :text)
15 Config.register Config::BooleanValue.new 'note.private_message',
17 :desc => 'Send all notes in private messages instead of channel messages.'
21 return if @registry.length < 1
22 debug 'Checking registry for old-formatted notes...'
24 @registry.keys.each do |key|
25 unless key == key.downcase
26 @registry[key.downcase] = @registry[key] + (@registry[key.downcase] || [])
31 debug "#{n} entries converted and merged."
34 def help(plugin, topic='')
35 'note <nick> <string> => stores a note (<string>) for <nick>'
40 nick = m.sourcenick.downcase
41 # Keys are case insensitive to avoid storing a message
42 # for <person> instead of <Person> or visa-versa.
43 return unless @registry.has_key? nick
46 @registry[nick].each do |n|
47 s = "[#{n.time.strftime('%b-%e %H:%M')}] <#{n.from}> #{n.text}"
48 if n.private or @bot.config['note.private_message']
55 @bot.say m.replyto, "#{m.sourcenick}, you have notes! " +
59 @bot.say m.sourcenick, 'you have notes! ' + priv.join(' ')
69 nick = params[:nick].downcase
70 q = @registry[nick] || Array.new
71 s = params[:string].to_s.strip
72 raise 'cowardly discarding the empty note' if s.empty?
73 q.push Note.new(Time.now, m.sourcenick, m.private?, s)
77 m.reply "error: #{e.message}"
82 NotePlugin.new.map 'note :nick *string'