summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authordmitry kim <jason@nichego.net>2009-06-06 16:08:30 +0400
committerdmitry kim <jason@nichego.net>2009-06-06 16:08:30 +0400
commit05fd07d54769b435e837d7dd9ec4dfc1f6a6a5c2 (patch)
tree9e8159aeb864eae1bfbf3000bca35f5010010c5c /data
parent105e41c59bed327e1861017112899c6bc7a4f811 (diff)
+ (plugins) note
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/note.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/data/rbot/plugins/note.rb b/data/rbot/plugins/note.rb
new file mode 100644
index 00000000..16c98e78
--- /dev/null
+++ b/data/rbot/plugins/note.rb
@@ -0,0 +1,46 @@
+Note = Struct.new('Note', :time, :from, :private, :text)
+
+class NotePlugin < Plugin
+ def help(plugin, topic="")
+ "note <nick> <string> => stores a note (<string>) for <nick>"
+ end
+
+ def listen(m)
+ begin
+ return if !m.kind_of?(PrivMessage) || !@registry.has_key?(m.sourcenick)
+ pub = []
+ priv = []
+ @registry[m.sourcenick].each do |n|
+ s = "[#{n.time.strftime('%H:%M')}] <#{n.from}> #{n.text}"
+ (n.private ? priv : pub).push(s)
+ end
+ if !pub.empty?
+ @bot.say m.replyto, "#{m.sourcenick}, you have notes! " +
+ pub.join(' ')
+ end
+
+ if !priv.empty?
+ @bot.say m.sourcenick, "you have notes! " + priv.join(' ')
+ end
+ @registry.delete(m.sourcenick)
+ rescue Exception => e
+ m.reply e.message
+ end
+ end
+
+ def note(m, params)
+ begin
+ q = @registry[params[:nick]] || Array.new
+ s = params[:string].join(' ')
+ raise 'cowardly discarding the empty note' if s.empty? || !s =~ /\S/
+ q.push Note.new(Time.now, m.sourcenick,
+ m.private?, params[:string].join(' '))
+ @registry[params[:nick]] = q
+ m.okay
+ rescue Exception => e
+ m.reply "error: #{e.message}"
+ end
+ end
+end
+plugin = NotePlugin.new
+plugin.map 'note :nick *string'