diff options
author | dmitry kim <jason@nichego.net> | 2009-06-06 16:34:53 +0400 |
---|---|---|
committer | dmitry kim <jason@nichego.net> | 2009-06-06 16:34:53 +0400 |
commit | 8e055d24373d965a568431c6bacc71019553a953 (patch) | |
tree | 732229b979ba737b2e93db593b23344c1af8b248 | |
parent | 05fd07d54769b435e837d7dd9ec4dfc1f6a6a5c2 (diff) |
* (plugins) note: misc cleanups
-rw-r--r-- | data/rbot/plugins/note.rb | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/data/rbot/plugins/note.rb b/data/rbot/plugins/note.rb index 16c98e78..66e0c1ec 100644 --- a/data/rbot/plugins/note.rb +++ b/data/rbot/plugins/note.rb @@ -1,18 +1,28 @@ -Note = Struct.new('Note', :time, :from, :private, :text) +#++ +# +# :title: Note plugin for rbot +# +# Author:: dmitry kim <dmitry dot kim at gmail dot com> +# +# Copyright:: (C) 200?-2009 dmitry 'jsn' kim +# +# License:: MIT license class NotePlugin < Plugin + Note = Struct.new('Note', :time, :from, :private, :text) + def help(plugin, topic="") "note <nick> <string> => stores a note (<string>) for <nick>" end - def listen(m) + def message(m) begin - return if !m.kind_of?(PrivMessage) || !@registry.has_key?(m.sourcenick) + return unless @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) + (n.private ? priv : pub).push s end if !pub.empty? @bot.say m.replyto, "#{m.sourcenick}, you have notes! " + @@ -22,7 +32,7 @@ class NotePlugin < Plugin if !priv.empty? @bot.say m.sourcenick, "you have notes! " + priv.join(' ') end - @registry.delete(m.sourcenick) + @registry.delete m.sourcenick rescue Exception => e m.reply e.message end @@ -31,10 +41,9 @@ class NotePlugin < Plugin 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(' ')) + s = params[:string].to_s.strip + raise 'cowardly discarding the empty note' if s.empty? + q.push Note.new(Time.now, m.sourcenick, m.private?, s) @registry[params[:nick]] = q m.okay rescue Exception => e @@ -42,5 +51,5 @@ class NotePlugin < Plugin end end end -plugin = NotePlugin.new -plugin.map 'note :nick *string' + +NotePlugin.new.map 'note :nick *string' |