mos-eisley 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http-client/webapi.rb +4 -0
- data/lib/mos-eisley/version.rb +1 -1
- data/lib/s3po/message.rb +10 -2
- data/lib/s3po/s3po.rb +38 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f64f23d469c363076a95b08fb398401d39c9f87
|
4
|
+
data.tar.gz: 70893cdb001ec0d02a62d9d4761ec06f2d2dd460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 838d2f9fe040fba456cf044bd25c8a13828f894b7593e2d6603909dc09085b5e6ff854a973015cf86fff233a047bd8ccca2952fbf1b0533fa53cefb544513298
|
7
|
+
data.tar.gz: c53eb1d6176f607746ae8a9689f7b884987357f664277cc91727bd5f058e7e4918a11b9b70c7f586b37f36d2be6cbb7bda6cae9018357e091700df45cc2f8444
|
data/lib/http-client/webapi.rb
CHANGED
data/lib/mos-eisley/version.rb
CHANGED
data/lib/s3po/message.rb
CHANGED
@@ -46,9 +46,11 @@ module MosEisley
|
|
46
46
|
|
47
47
|
# Adds text after a space if text already exists
|
48
48
|
# @param t [String] text to add
|
49
|
+
# @return [Object] self
|
49
50
|
def add_text(t)
|
50
51
|
nt = [event[:text], t].compact.join(' ')
|
51
52
|
event[:text] = nt[0].upcase + nt[1..-1]
|
53
|
+
return self
|
52
54
|
end
|
53
55
|
|
54
56
|
def attachments
|
@@ -79,11 +81,17 @@ module MosEisley
|
|
79
81
|
event[:thread_ts]
|
80
82
|
end
|
81
83
|
|
82
|
-
def
|
84
|
+
def text_body
|
83
85
|
return nil unless simple_message?
|
84
86
|
t = event[:text]
|
85
87
|
t = t.sub(/^<@#{MosEisley.config.meta[:user_id]}[|]?[^>]*>/, '') if for_me?
|
86
|
-
t
|
88
|
+
return t
|
89
|
+
end
|
90
|
+
|
91
|
+
def text_plain
|
92
|
+
t = text_body
|
93
|
+
return nil unless t
|
94
|
+
return S3PO.decode_text(t)
|
87
95
|
end
|
88
96
|
|
89
97
|
def postable_object
|
data/lib/s3po/s3po.rb
CHANGED
@@ -60,5 +60,43 @@ module MosEisley
|
|
60
60
|
return GenericEvent.new(e)
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
# Escape string with basic Slack rules; no command encoding is done as it often requires more information than provided in the text
|
65
|
+
# @param text [String] string to escape
|
66
|
+
# @return [String] escaped text
|
67
|
+
def self.escape_text(text)
|
68
|
+
esced = String.new(text)
|
69
|
+
esced.gsub!('&', '&')
|
70
|
+
esced.gsub!('<', '<')
|
71
|
+
esced.gsub!('>', '>')
|
72
|
+
return esced
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return plain text parsing Slack escapes and commands
|
76
|
+
# @param text [String] string to decode
|
77
|
+
# @return [String] plain text
|
78
|
+
def self.decode_text(text)
|
79
|
+
plain = String.new(text)
|
80
|
+
# keep just the labels
|
81
|
+
plain.gsub!(/<([#@]*)[^>|]*\|([^>]*)>/, '<\1\2>')
|
82
|
+
# process commands
|
83
|
+
plain.gsub!(/<!(everyone|channel|here)>/, '<@\1>')
|
84
|
+
plain.gsub!(/<!(.*?)>/, '<\1>')
|
85
|
+
# remove brackets
|
86
|
+
plain.gsub!(/<(.*?)>/, '\1')
|
87
|
+
# unescape
|
88
|
+
plain.gsub!('>', '>')
|
89
|
+
plain.gsub!('<', '<')
|
90
|
+
plain.gsub!('&', '&')
|
91
|
+
return plain
|
92
|
+
end
|
93
|
+
|
94
|
+
# Enclose Slack command in control characters
|
95
|
+
# @param cmd [String] command
|
96
|
+
# @param label [String] optional label
|
97
|
+
# @return [String] escaped command
|
98
|
+
def self.escape_command(cmd, label = nil)
|
99
|
+
"<#{cmd}" + (label ? "|#{label}" : '') + '>'
|
100
|
+
end
|
63
101
|
end
|
64
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mos-eisley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken J.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|