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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 345e1b155662e980216df2f98aa79ca99add2c17
4
- data.tar.gz: 8011e855084b385146c42160cef09fa75188469c
3
+ metadata.gz: 6f64f23d469c363076a95b08fb398401d39c9f87
4
+ data.tar.gz: 70893cdb001ec0d02a62d9d4761ec06f2d2dd460
5
5
  SHA512:
6
- metadata.gz: 3ed78d1a910dae6c790bdbdafb8b1faab19b5fcd04c25d98151ef46fa91cf0bafbd22ccec636e1d914dee310e05f402da719bedd0a8d268e3e3ebbfd6b5ff005
7
- data.tar.gz: e4961e9eb426f89631bcaf6dcdd3058eca28419dc38cedffe894ca35ad9d6c32a0fd5818bc76d71cded98bf79de4386e6f1b8a705764574d1a60694fd5ed2f68
6
+ metadata.gz: 838d2f9fe040fba456cf044bd25c8a13828f894b7593e2d6603909dc09085b5e6ff854a973015cf86fff233a047bd8ccca2952fbf1b0533fa53cefb544513298
7
+ data.tar.gz: c53eb1d6176f607746ae8a9689f7b884987357f664277cc91727bd5f058e7e4918a11b9b70c7f586b37f36d2be6cbb7bda6cae9018357e091700df45cc2f8444
@@ -9,6 +9,10 @@ module MosEisley
9
9
  end
10
10
  end
11
11
 
12
+ def self.me_message(channel:, text:)
13
+ post_to_slack('chat.meMessage', {channel: channel, text: text})
14
+ end
15
+
12
16
  def self.post_message(msg)
13
17
  post_to_slack('chat.postMessage', msg)
14
18
  end
@@ -1,5 +1,5 @@
1
1
  module MosEisley
2
2
 
3
- VERSION = '0.1.2'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
 
5
5
  end
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 arguments
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.split
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!('&', '&amp;')
70
+ esced.gsub!('<', '&lt;')
71
+ esced.gsub!('>', '&gt;')
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!('&gt;', '>')
89
+ plain.gsub!('&lt;', '<')
90
+ plain.gsub!('&amp;', '&')
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.1.2
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-01-20 00:00:00.000000000 Z
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