/
quote_plugin.rb
48 lines (37 loc) · 1.11 KB
/
quote_plugin.rb
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
class QuotePlugin
include NinjaPlugin
match /quote (.+)/
match /grab (.+)/, :method => :grab
def usage
"!quote <nick> [type]"
end
def grab(m, pattern)
if chan = m.channel
history = @bot.history[chan.name] || []
history.reverse_each do |message|
next if message[:text] =~ /^\!(\S+)/
if message[:text] =~ /#{Regexp.escape(pattern)}/ || message[:nick] =~ /#{Regexp.escape(pattern)}/
user = Channel.get_user(chan.name, message[:nick])
message = user.messages.create(:type => "famous", :text => message[:text], :created_at => message[:date])
m.reply "#{m.user.nick}: grabbed! >> #{message.to_s}"
break
end
end
end
end
def execute(m, query)
@bot.localize!
nick, type = query.split(" ", 2)
if chan = m.channel
user = Channel.get_user(chan.name, nick)
conditions = {:user_id => user.id}
if type
conditions[:type] = type
end
if message = Message.random_message(conditions)
m.reply "#{m.user.nick}: #{message.to_s}"
end
end
end
end
register_plugin QuotePlugin