-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_bot.rb
40 lines (36 loc) · 886 Bytes
/
test_bot.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
#!/usr/bin/env ruby
require 'collecta_bot'
#Jabber::debug = true
class SearchBot < Collecta::Bot
def self.format_result(msg, debug = true)
begin
return msg unless payload = Collecta::Payload.new(msg)
return msg if payload.type == :unknown
m = "\n#{payload.type}: [#{payload.meta}] "
if payload.type == :notify
m += " -> #{payload.body}"
elsif payload.type == :query
m += " -> (#{payload.category}) #{payload.title}\n"
m += payload.body
if payload.links
m += "\nLinks: \n"
m += payload.links.inspect
end
else
return msg
end
m
rescue Exception => e
puts "[E] #{e.to_s}" if debug
return msg
end
end
end
if __FILE__ == $0
# register a handler for SIGINTs
trap(:INT) do
EM.stop
exit
end
SearchBot.run("config.yml")
end