slacktail 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e33683910867a751ceb282ae4c4d3ce24fff694a54b7a1d54038301e9fa2d70
4
- data.tar.gz: 79c8568107c9ff8374514dd56e6dbc85f815750b7d9b95dcb0ee4026e844c2dd
3
+ metadata.gz: 400b1fcdd1396dd38411535c29dd04e35af8ee7f4e6322fb35c05ed0756a0ecc
4
+ data.tar.gz: 61212806581ab04e7e4143753503f2996859e302866bd24632ac49971f2eb25d
5
5
  SHA512:
6
- metadata.gz: eb2530f19b0d19657b255442152a55be621f2598911b2b837cad816a710fd406c9485da98408b1e6767af8016031d42b8394c1dc1a5b2766c89171de77aef876
7
- data.tar.gz: 1ced8967e9816012bbb7fb244b41a5d644ee4bac12c83d9d64319fff7e5c40fe91005ff3519e10ad18d28dc0bb6723a7ea94a76606f0d24fed27e621885e4b10
6
+ metadata.gz: 91568775807417de6cbe7c3e379bd4bc4ad9665939e4e1045128427cacbb0e7a0802f8a3e1e1430e4a873f053fa5e9e667b8b7ccf9038403666519d9134bed36
7
+ data.tar.gz: 4ba8d8cd483f3d04bf0230070de96290aefb36fd5f36d7ae031d707e4aae6e248728cd535f0801f8ceee3ff11da9ce28b3d9d326b522e8fd2f269849f07fe896
data/bin/slacktail CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'slacktail'
3
+ require 'pretty_trace/enable-trim'
3
4
 
4
5
  runner = MisterBin::Runner.new handler: Slacktail::Command
5
6
 
@@ -1,5 +1,7 @@
1
1
  module Slacktail
2
2
  class Base
3
+ include HasClient
4
+
3
5
  attr_reader :data
4
6
 
5
7
  def initialize(data)
@@ -20,6 +20,7 @@ module Slacktail
20
20
  say "Connecting... " if Client.can_connect?
21
21
 
22
22
  client.on :message do |data|
23
+ # File.write 'debug.yml', data.to_yaml
23
24
  @message = Message.new data
24
25
  @message.render unless skip?
25
26
  end
@@ -7,11 +7,30 @@ module Slacktail
7
7
  end
8
8
 
9
9
  def text!
10
- data.text ? data.text.gsub(/```\n?/, '').strip : ''
10
+ return '' unless data.text
11
+
12
+ result = data.text
13
+ result = sanitize_text result
14
+ result = evaluate_users result
15
+ result
11
16
  end
12
17
 
13
18
  def text_lines
14
19
  word_wrap(" #{text}").split("\n").map(&:strip)
15
20
  end
21
+
22
+ private
23
+
24
+ def sanitize_text(text)
25
+ data.text.gsub(/```\n?/, '').strip
26
+ end
27
+
28
+ def evaluate_users(text)
29
+ text.gsub(/<@([^>]+)>/) do
30
+ user = client.users[$1]&.name || "anonymous"
31
+ "@#{user}"
32
+ end
33
+ end
34
+
16
35
  end
17
36
  end
@@ -1,6 +1,6 @@
1
1
  module Slacktail
2
2
  class Message < Base
3
- include MessageView, HasText, HasClient
3
+ include MessageView, HasText
4
4
 
5
5
  def channel
6
6
  @channel ||= channel!
@@ -14,7 +14,7 @@ module Slacktail
14
14
  if attachments.any?
15
15
  attachments.first.color.to_colsole_color
16
16
  else
17
- :cyn
17
+ :rst
18
18
  end
19
19
  end
20
20
 
@@ -27,13 +27,13 @@ module Slacktail
27
27
  end
28
28
 
29
29
  def user
30
- if data.username
31
- data.username
30
+ result = if data.user
31
+ client.users[data.user]&.name
32
32
  elsif data.bot_id
33
- client.bots[data.bot_id].name
34
- else
35
- "anonymous"
33
+ client.bots[data.bot_id]&.name
36
34
  end
35
+
36
+ result || "anonymous"
37
37
  end
38
38
 
39
39
  def attachments
@@ -1,3 +1,3 @@
1
1
  module Slacktail
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/slacktail.rb CHANGED
@@ -5,9 +5,9 @@ require 'tty-markdown'
5
5
  require 'byebug' if ENV['BYEBUG']
6
6
 
7
7
  requires \
8
+ 'slacktail/has_client',
8
9
  'slacktail/base',
9
10
  'slacktail/message_view',
10
11
  'slacktail/has_text',
11
- 'slacktail/has_client',
12
12
  'slacktail'
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slacktail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit