-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblabberbot.rb
More file actions
99 lines (77 loc) · 2.38 KB
/
Copy pathblabberbot.rb
File metadata and controls
99 lines (77 loc) · 2.38 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'socket'
require 'cinch'
require 'open-uri'
require 'nokogiri'
require 'cgi'
MY_CHANNELS = ["#channel01 key","#channel02","#channel03"]
MY_LISTENING_IP = "0.0.0.0"
MY_LISTENING_PORT = 2001
require_relative "plugins/link_info"
require_relative "plugins/zabbix_trigger_info"
require_relative "plugins/tube_status"
require_relative "plugins/tumbleweed"
require_relative "plugins/lana"
class BlabberBot
include Cinch::Plugin
listen_to :monitor_msg, :method => :send_msg
match /phrasing (.+)/
def lookup(word)
url = "http://www.urbandictionary.com/define.php?term=#{CGI.escape(word)}"
CGI.unescape_html Nokogiri::HTML(open(url)).at("div.meaning").text.gsub(/\s+/, ' ') rescue nil
end
def execute(m, word)
m.reply(lookup(word) || "No results found", true)
end
end
class Help
include Cinch::Plugin
listen_to :monitor_msg, :method => :send_msg
match /help/
def execute(m)
m.reply <<-HELP
Tube:
!tube broken
- list all tube lines with current problems
!tube line foo
- get the detailed status about tube line foo (NB, must be a real tube line, eg '!tube line circle'
Link Info
- no commands, this plugin posts the contents of the <title></title> tag for any posted URIs
Zabbix triggers
!zabbix triggers
- show all current triggers in the problem state on zabbix2
Urban Dictionary Lookup
!phrasing
- do an urban dictionary lookup for the given phrase, and return the first result (if any). Probably NSFW
Tumbleweed
!tumbleweed
- return a one line ascii representation of tubleweed. It's not big, it's not clever, it's just a one line response
HELP
end
end
bot = Cinch::Bot.new do
configure do |c|
c.nick = "blabberbot"
c.realname = "load of old nonsense"
c.user = "speak to Mat"
c.server = "irc.example.com"
c.port = 6697
c.ssl.use = true
c.channels = MY_CHANNELS
c.verbose = false
c.plugins.plugins = [BlabberBot,Cinch::LinkInfo,TubeStatus,Help,Tumbleweed,Lana]
end
end
def server(bot)
print "Thread Start\n"
server = TCPServer.new MY_LISTENING_IP, MY_LISTENING_PORT
loop do
Thread.start(server.accept) do |client|
message = client.gets
bot.handlers.dispatch(:monitor_msg, nil, message)
client.puts "Ok\n"
client.close
end #Thread.Start
end #loop
end
Thread.new { server(bot) }
bot.start