-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.rb
36 lines (32 loc) · 851 Bytes
/
common.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
require 'pg'
require 'json'
$config = open('key.json') do |io|
JSON.load(io)
end
def getconfig()
$config
end
def pgconnect(teamname)
config = getconfig()
res = PG::connect(
:host => config[teamname]['db']['host'],
:user => config[teamname]['db']['user'],
:dbname => config[teamname]['db']['dbname'],
:password => config[teamname]['db']['password']
)
res.internal_encoding= 'UTF-8'
res
end
def messageAddField(message)
message['raw'] = JSON.generate(message)
message['created'] = Time.at(message['ts'].split('.')[0].to_i)
if message.include?('attachments')
message['attachments'].each do |attachment|
if !attachment.include?('fallback')
next
end
message['text'] = message['text'] + (message['text'] == '' ? '' : "\n") + "--\n" + attachment['fallback']
end
end
message
end