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
12 Note = Struct.new('Note', :time, :from, :private, :text)
14 def help(plugin, topic="")
15 "note <nick> <string> => stores a note (<string>) for <nick>"
20 return unless @registry.has_key? m.sourcenick
23 @registry[m.sourcenick].each do |n|
24 s = "[#{n.time.strftime('%H:%M')}] <#{n.from}> #{n.text}"
25 (n.private ? priv : pub).push s
28 @bot.say m.replyto, "#{m.sourcenick}, you have notes! " +
33 @bot.say m.sourcenick, "you have notes! " + priv.join(' ')
35 @registry.delete m.sourcenick
43 q = @registry[params[:nick]] || Array.new
44 s = params[:string].to_s.strip
45 raise 'cowardly discarding the empty note' if s.empty?
46 q.push Note.new(Time.now, m.sourcenick, m.private?, s)
47 @registry[params[:nick]] = q
50 m.reply "error: #{e.message}"
55 NotePlugin.new.map 'note :nick *string'