forked from rapid7/metabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.rb
50 lines (38 loc) · 970 Bytes
/
helpers.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
49
50
def filter_command(string)
return "" unless string # nil becomes empty string
return unless string.class == String # Allow other types unmodified
unless /^[\w\s\[\]\{\}\/\\\.\-\"\(\)]*$/.match string
raise "WARNING! Invalid character in: #{string}"
end
string
end
def output_or_link(m, message)
m.reply(message) unless File.directory?(tmp_directory)
if message.lines.count < 4
m.reply(message)
else
m.reply(link(message))
end
end
def tmp_directory
"/var/www/metabot-tmp"
end
def server_link
"http://#{get_hostname}/metabot-tmp"
end
def get_hostname
require 'socket'
host = Socket.gethostname
end
def link(message)
x = random_string
File.open("#{tmp_directory}/#{x}","w"){|file| file.puts(message)}
return "#{server_link}/#{x}"
end
def random_string(size=16)
chars = ('a'..'z').to_a + ('A'..'Z').to_a
(0...size).collect { chars[Kernel.rand(chars.length)] }.join
end
def is_admin?(user)
true if @admins.include? user.nick
end