slacktail 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90c2bc64c84bf955e31f8ffc852e30d84811d3e8efe62d55e1c18186215fd938
4
+ data.tar.gz: aed391d0419c87b308dd909eaa7d515e1c84cdd24374eb56e1b779a3e7dbabf3
5
+ SHA512:
6
+ metadata.gz: ea9f8f39ce1bf2c03fa72402f6feb06828de1674bb9d91aa57add31eefda72afb2a1c6243fd5a17c6d7884d3ff5752473a2b8907c729f4337d52a7e105da5445
7
+ data.tar.gz: fbe56116ee1b230ba647f3af890d3f962365b8d2e222f41c2130848d05c52e04717174861c36a2e41877c5b1ed6d082f45fe72cc0dedac3f844dc0d730cf4d59
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ Slacktail
2
+ ==================================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/slacktail.svg)](https://badge.fury.io/rb/slacktail)
5
+ [![Build Status](https://travis-ci.com/DannyBen/slacktail.svg?branch=master)](https://travis-ci.com/DannyBen/slacktail)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/.../maintainability)](https://codeclimate.com/github/DannyBen/slacktail/maintainability)
7
+
8
+ ---
9
+
10
+ Slacktail is a single-purpose command line utility for follwoing messages
11
+ sent to your Slack organization chat.
12
+
13
+ ---
14
+
15
+ Installation
16
+ --------------------------------------------------
17
+
18
+ $ gem install slacktail
19
+
20
+
21
+ Authorization
22
+ --------------------------------------------------
23
+
24
+
25
+ 1. Obtain an API key from Slack.
26
+ In your Slack settings, go to [Custom Integrations] and create a new
27
+ Bot Application. Then, find the API Token in the bot's configuration page.
28
+
29
+ 2. Set the `SLACK_API_TOKEN` environemnt variable to the API Token. This
30
+ should probably be set in your `~/.bashrc`, with
31
+ `export SLACK_API_TOKEN=<your token>`
32
+
33
+ 3. Invite your bot to any channel you want to monitor. Type
34
+ `/invite @<botname>` in any channel.
35
+
36
+
37
+ Usage
38
+ --------------------------------------------------
39
+
40
+ Follow all channels:
41
+
42
+ $ slacktail
43
+
44
+ Follow specific channels
45
+
46
+ $ slacktail general development lobby
47
+
48
+
49
+
50
+ ---
51
+
52
+ [Custom Integrations]: https://my.slack.com/apps/manage/custom-integrations
data/bin/slacktail ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'slacktail'
3
+
4
+ runner = MisterBin::Runner.new handler: Slacktail::Command
5
+
6
+ begin
7
+ exit runner.run ARGV
8
+ rescue => e
9
+ puts e.backtrace.reverse if ENV['DEBUG']
10
+ say! "!txtred!#{e.class}: #{e.message}"
11
+ exit 1
12
+ end
@@ -0,0 +1,18 @@
1
+ module Slacktail
2
+ class Attachment < Base
3
+ include HasText
4
+
5
+ def color
6
+ data.color || ''
7
+ end
8
+
9
+ def fields
10
+ @fields ||= fields!
11
+ end
12
+
13
+ def fields!
14
+ return [] unless data.fields
15
+ data.fields.map { |field| Field.new field }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Slacktail
2
+ class Base
3
+ attr_reader :data
4
+
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Slacktail
2
+ class Client
3
+ class << self
4
+ attr_writer :default
5
+
6
+ def default
7
+ @default ||= default!
8
+ end
9
+
10
+ def can_connect?
11
+ !!ENV['SLACK_API_TOKEN']
12
+ end
13
+
14
+ def default!
15
+ raise ArgumentError, 'Please set SLACK_API_TOKEN' unless can_connect?
16
+ Slack.configure { |c| c.token = ENV['SLACK_API_TOKEN'] }
17
+ Slack::RealTime::Client.new
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,43 @@
1
+ module Slacktail
2
+ class Command < MisterBin::Command
3
+ include HasClient
4
+
5
+ version VERSION
6
+ summary "Show and follow slack messages in real time"
7
+
8
+ usage "slacktail [CHANNELS...]"
9
+ usage "slacktail (-h|--help|--version)"
10
+
11
+ param "CHANNELS", "Channels to follow"
12
+
13
+ example "slacktail"
14
+ example "slacktail general debug"
15
+
16
+ def run(args = nil)
17
+ args ||= {}
18
+ @channels = args['CHANNELS'] || []
19
+
20
+ say "Connecting... " if Client.can_connect?
21
+
22
+ client.on :message do |data|
23
+ @message = Message.new data
24
+ @message.render unless skip?
25
+ end
26
+
27
+ client.on(:hello) { resay "!txtgrn!Ready\n" }
28
+ client.on(:closed) { |_data| say "Goodbye" }
29
+ client.start!
30
+ end
31
+
32
+ private
33
+
34
+ def skip?
35
+ return true if @message.empty?
36
+ return false if @channels.empty?
37
+ return false if @channels.include? @message.pure_channel
38
+ return true
39
+ end
40
+
41
+ end
42
+ end
43
+
@@ -0,0 +1,21 @@
1
+ class String
2
+ def to_markdown
3
+ TTY::Markdown.parse self
4
+ end
5
+
6
+ def to_colsole_color
7
+ color = {
8
+ '000000' => :wht,
9
+ 'ff0000' => :red,
10
+ '00ff00' => :grn,
11
+ '0000ff' => :blu,
12
+ 'ffff00' => :ylw,
13
+ 'ff00ff' => :pur,
14
+ '00ffff' => :cyn,
15
+ 'ffffff' => :blk,
16
+ }
17
+
18
+ key = self.downcase
19
+ color.keys.include?(key) ? color[key] : :rst
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Slacktail
2
+ class Field < Base
3
+ def key
4
+ data.title
5
+ end
6
+
7
+ def value
8
+ data.value
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Slacktail
2
+ module HasClient
3
+ attr_writer :client
4
+
5
+ def client
6
+ @client ||= Client.default
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Slacktail
2
+ module HasText
3
+ def text
4
+ @text ||= text!
5
+ end
6
+
7
+ def text!
8
+ data.text ? data.text.gsub(/```\n?/, '').strip : ''
9
+ end
10
+
11
+ def text_lines
12
+ text.split "\n"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,67 @@
1
+ module Slacktail
2
+ class Message < Base
3
+ include MessageView, HasText, HasClient
4
+
5
+ def channel
6
+ @channel ||= channel!
7
+ end
8
+
9
+ def pure_channel
10
+ channel.gsub '#', ''
11
+ end
12
+
13
+ def color
14
+ if attachments.any?
15
+ attachments.first.color.to_colsole_color
16
+ else
17
+ :cyn
18
+ end
19
+ end
20
+
21
+ def items
22
+ @items ||= items!
23
+ end
24
+
25
+ def empty?
26
+ items.empty?
27
+ end
28
+
29
+ def user
30
+ if data.username
31
+ data.username
32
+ elsif data.bot_id
33
+ client.bots[data.bot_id].name
34
+ else
35
+ "anonymous"
36
+ end
37
+ end
38
+
39
+ def attachments
40
+ @attachments ||= attachments!
41
+ end
42
+
43
+ private
44
+
45
+ def items!
46
+ result = text_lines
47
+ attachments.each do |attachment|
48
+ result += attachment.text_lines
49
+ result += attachment.fields
50
+ end
51
+ result
52
+ end
53
+
54
+ def channel!
55
+ channel = client.channels[data.channel]
56
+ channel ? "##{channel.name}" : "@private"
57
+ end
58
+
59
+ def attachments!
60
+ return [] unless data.attachments
61
+ data.attachments.map do |attachment|
62
+ Attachment.new attachment
63
+ end
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,22 @@
1
+ module Slacktail
2
+ module MessageView
3
+ include Colsole
4
+
5
+ def render
6
+ prefix = "!txt#{color}!▌!txtrst! "
7
+ now = Time.now.strftime "%H:%M"
8
+ say "#{prefix}!txtcyn!#{now} ➤ !bldcyn!@#{user}!txtcyn! ➤ #{channel}".strip
9
+
10
+ items.each do |line|
11
+ if line.is_a? String
12
+ say "#{prefix}#{line.to_markdown}".strip
13
+ elsif line.is_a? Field
14
+ say "#{prefix}!txtblu!#{line.key}!txtrst! : !txtgrn!#{line.value}".strip
15
+ end
16
+ end
17
+
18
+ say ""
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Slacktail
2
+ VERSION = "0.0.1"
3
+ end
data/lib/slacktail.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'requires'
2
+ require 'mister_bin'
3
+ require 'slack-ruby-client'
4
+ require 'tty-markdown'
5
+ require 'byebug' if ENV['BYEBUG']
6
+
7
+ requires \
8
+ 'slacktail/base',
9
+ 'slacktail/message_view',
10
+ 'slacktail/has_text',
11
+ 'slacktail/has_client',
12
+ 'slacktail'
13
+
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slacktail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-websocket
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mister_bin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: requires
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slack-ruby-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.13'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tty-markdown
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
83
+ description: Slacktail is a single-purpose command line utility for follwoing messages
84
+ sent to your Slack organization chat.
85
+ email: db@dannyben.com
86
+ executables:
87
+ - slacktail
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - bin/slacktail
93
+ - lib/slacktail.rb
94
+ - lib/slacktail/attachment.rb
95
+ - lib/slacktail/base.rb
96
+ - lib/slacktail/client.rb
97
+ - lib/slacktail/command.rb
98
+ - lib/slacktail/extensions/string.rb
99
+ - lib/slacktail/field.rb
100
+ - lib/slacktail/has_client.rb
101
+ - lib/slacktail/has_text.rb
102
+ - lib/slacktail/message.rb
103
+ - lib/slacktail/message_view.rb
104
+ - lib/slacktail/version.rb
105
+ homepage: https://github.com/dannyben/slacktail
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.4.0
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Command line tool for following slack messages in real time
129
+ test_files: []