This repository was archived by the owner on Oct 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.rb
More file actions
68 lines (61 loc) · 1.81 KB
/
note.rb
File metadata and controls
68 lines (61 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#++
#
# :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 pare_keys(keye)
keye.downcase.gsub(Regexp.new('(?:_|\^)[^\^|\|]*$'),'')
end
def message(m)
begin
return unless @registry.has_key? pare_keys(m.sourcenick)
pub = []
priv = []
@registry[pare_keys(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 pare_keys(m.sourcenick)
rescue Exception => e
m.reply e.message
end
end
def note(m, params)
begin
q = @registry[pare_keys(params[:nick])] || Array.new
s = params[:string].to_s.strip
raise 'cowardly discarding the empty note' if s.empty?
qq = q.collect{|f| f.from == pare_keys(m.sourcenick)}
if qq.size > 3
debug __FILE__
m.reply "Stop trying to spam notes you petrified rhinoceros pizzle"
q.shift
q.push Note.new(Time.now, pare_keys(m.sourcenick), m.private?, s)
@registry[pare_keys(params[:nick])] = q
else
q.push Note.new(Time.now, pare_keys(m.sourcenick), m.private?, s)
@registry[pare_keys(params[:nick])] = q
m.okay
end
rescue Exception => e
m.reply "error: #{e.message}"
end
end
end
NotePlugin.new.map 'note :nick *string'