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)
17 return if @registry.nil? or @registry.length < 1
18 debug 'Checking registry for old-formatted notes...'
20 @registry.dup.each_key do |key|
21 unless key == key.downcase
22 @registry[key.downcase] = @registry[key] + @registry[key.downcase]
27 debug "#{n} entries converted and merged."
30 def help(plugin, topic='')
31 'note <nick> <string> => stores a note (<string>) for <nick>'
36 nick = m.sourcenick.downcase
37 # Keys are case insensitive to avoid storing a message
38 # for <person> instead of <Person> or visa-versa.
39 return unless @registry.has_key? nick
42 @registry[nick].each do |n|
43 s = "[#{n.time.strftime('%H:%M')}] <#{n.from}> #{n.text}"
44 (n.private ? priv : pub).push s
47 @bot.say m.replyto, "#{m.sourcenick}, you have notes! " +
52 @bot.say m.sourcenick, 'you have notes! ' + priv.join(' ')
62 nick = params[:nick].downcase
63 q = @registry[nick] || Array.new
64 s = params[:string].to_s.strip
65 raise 'cowardly discarding the empty note' if s.empty?
66 q.push Note.new(Time.now, m.sourcenick, m.private?, s)
70 m.reply "error: #{e.message}"
75 NotePlugin.new.map 'note :nick *string'