baez_slack 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 +7 -0
- data/lib/baez_slack.rb +25 -0
- data/lib/modules/console_slack.rb +25 -0
- data/lib/modules/message_slack.rb +68 -0
- data/lib/modules/read_slack.rb +29 -0
- data/lib/modules/search_slack.rb +76 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f2e8f3b4069bcd877f749545679cb5f71707d257cd80312f8cf9ef8ffee344f7
|
4
|
+
data.tar.gz: 0db262c0d34c2b3b48b139e99eb0c25a9ef8578ba0f8c4bac7f452cd726fd65c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 417e3e0820b09e413d8bd8d7085aee521457e3125ed1ad75738de35290872189026d280e7491acc6b93fc187425dd8fbf16e88749b67e92a2198067c5aa59e59
|
7
|
+
data.tar.gz: efde9e3488a9c7eae119ba80b808aebb20619ca424757c95662cc7ee56cc9cf6a5a93ac8c72b86809e82c27b308a5616cdd8536cab9426773d7712d0e2b84a22
|
data/lib/baez_slack.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
require_relative "modules/message_slack"
|
3
|
+
require_relative "modules/search_slack"
|
4
|
+
require_relative 'modules/read_slack'
|
5
|
+
|
6
|
+
|
7
|
+
# Groups client initialization with instance parameters
|
8
|
+
class BaezSlack
|
9
|
+
include MessageSlack
|
10
|
+
include SearchOnSlack
|
11
|
+
include ReadSlack
|
12
|
+
|
13
|
+
def initialize(name = '', image = '', token = nil)
|
14
|
+
Slack.configure do |config|
|
15
|
+
config.token = token.nil? ? @bot_token : token
|
16
|
+
config.raise 'Missing token' unless config.token
|
17
|
+
end
|
18
|
+
|
19
|
+
@bot_name = name unless name.empty?
|
20
|
+
@bot_icon = image unless image.empty?
|
21
|
+
|
22
|
+
@time_client ||= Slack::RealTime::Client.new
|
23
|
+
@web_client ||= Slack::Web::Client.new
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require_relative 'search_slack'
|
3
|
+
|
4
|
+
# Module to read data from Slack and show it on console
|
5
|
+
module ConsoleSlack
|
6
|
+
include SearchOnSlack
|
7
|
+
|
8
|
+
def format_new_message(data)
|
9
|
+
user_p = if data.subtype == 'bot_message'
|
10
|
+
data.username
|
11
|
+
else
|
12
|
+
user = get_user_info(data.user)
|
13
|
+
user.real_name
|
14
|
+
end
|
15
|
+
text = data.text
|
16
|
+
channel_p = conversation_info(data.channel)
|
17
|
+
if @current_channel == channel_p.id
|
18
|
+
print "\n#{user_p}: ".yellow + text.blue
|
19
|
+
else
|
20
|
+
print "\n--- #{channel_p.name} ---".green
|
21
|
+
print "\n#{user_p}: ".yellow + text.blue
|
22
|
+
end
|
23
|
+
@current_channel = channel_p.id
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative 'search_slack'
|
2
|
+
|
3
|
+
# Module for message interactions on Slack
|
4
|
+
module MessageSlack
|
5
|
+
include SearchOnSlack
|
6
|
+
|
7
|
+
def discern_end(data, ts = nil)
|
8
|
+
@thread = if data.respond_to? :thread_ts
|
9
|
+
data.ts
|
10
|
+
else
|
11
|
+
ts unless ts.nil?
|
12
|
+
end
|
13
|
+
@channel = if data.respond_to? :channel
|
14
|
+
data.channel
|
15
|
+
else
|
16
|
+
data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def attach_format(data, title, color = '#e93d94')
|
21
|
+
text = ''
|
22
|
+
data.each { |v| text << "#{v}\n" }
|
23
|
+
[{
|
24
|
+
"pretext": title,
|
25
|
+
"color": color,
|
26
|
+
"text": text
|
27
|
+
}]
|
28
|
+
end
|
29
|
+
|
30
|
+
def send_message(text, data, ts = nil)
|
31
|
+
discern_end(data, ts)
|
32
|
+
@web_client.chat_postMessage channel: @channel,
|
33
|
+
text: text,
|
34
|
+
icon_url: @bot_icon,
|
35
|
+
username: @bot_name,
|
36
|
+
thread_ts: @thread,
|
37
|
+
as_user: true
|
38
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
39
|
+
print e.message
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
def send_direct_message(text, channel)
|
44
|
+
dm = get_user_id(channel)
|
45
|
+
dm == false ? false : send_message(text, dm)
|
46
|
+
end
|
47
|
+
|
48
|
+
def send_attachment(attachment, data, ts = nil)
|
49
|
+
discern_end(data, ts)
|
50
|
+
@web_client.chat_postMessage channel: @channel,
|
51
|
+
attachments: attachment,
|
52
|
+
icon_url: @bot_icon,
|
53
|
+
username: @bot_name,
|
54
|
+
thread_ts: @thread,
|
55
|
+
as_user: true
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_reaction(icon, channel, thread)
|
59
|
+
@web_client.reactions_add channel: channel,
|
60
|
+
name: icon,
|
61
|
+
timestamp: thread,
|
62
|
+
icon_url: @bot_icon,
|
63
|
+
username: @bot_name
|
64
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
65
|
+
print e.message
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'message_slack'
|
2
|
+
require_relative 'console_slack'
|
3
|
+
# require './actions/modes'
|
4
|
+
|
5
|
+
# Module for reading chat incoming messages
|
6
|
+
module ReadSlack
|
7
|
+
include ConsoleSlack
|
8
|
+
# include DirectiveLookup
|
9
|
+
|
10
|
+
def share_message(data)
|
11
|
+
case @output
|
12
|
+
when 'slack'
|
13
|
+
check_type(data)
|
14
|
+
when 'console'
|
15
|
+
format_new_message(data)
|
16
|
+
else
|
17
|
+
format_new_message(data)
|
18
|
+
check_type(data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def single_client(output = 'console')
|
23
|
+
@output = output
|
24
|
+
@time_client.on :message do |data|
|
25
|
+
share_message(data)
|
26
|
+
end
|
27
|
+
@time_client.start!
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Module for searching content on Slack
|
2
|
+
module SearchOnSlack
|
3
|
+
|
4
|
+
def get_user_id(channel = @channel_id)
|
5
|
+
dm = @web_client.conversations_open users: channel
|
6
|
+
dm.channel.id
|
7
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
8
|
+
print e.message
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_user_info(user)
|
13
|
+
c = @web_client.users_info user: user
|
14
|
+
c.user
|
15
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
16
|
+
print e.message
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_user_list
|
21
|
+
@web_client.users_list
|
22
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
23
|
+
print e.message
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def verify_type
|
28
|
+
properties = {
|
29
|
+
'channel' => @properties.is_channel,
|
30
|
+
'group' => @properties.is_group,
|
31
|
+
'im' => @properties.is_im
|
32
|
+
}
|
33
|
+
check = ''
|
34
|
+
properties.each { |k, v| check = k if v == true }
|
35
|
+
check
|
36
|
+
end
|
37
|
+
|
38
|
+
def conversation_type(channel = @channel_id)
|
39
|
+
@channel_id = channel if @channel_id.nil?
|
40
|
+
result = conversation_info
|
41
|
+
if result == false
|
42
|
+
print 'Check if IM'
|
43
|
+
@channel_id = get_user_id
|
44
|
+
conversation_info == false ? false : verify_type
|
45
|
+
else
|
46
|
+
verify_type
|
47
|
+
end
|
48
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
49
|
+
print e.message
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def conversation_info(channel = @channel_id)
|
54
|
+
info = @web_client.conversations_info channel: channel
|
55
|
+
@properties = info.channel
|
56
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
57
|
+
print e.message
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
def conversation_list
|
62
|
+
@web_client.conversations_list.channels
|
63
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
64
|
+
print e.message
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def search_messages_on(channel, quantity = 5)
|
70
|
+
# type = conversation_type(channel)
|
71
|
+
@web_client.conversations_history channel: channel, count: quantity
|
72
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
73
|
+
print e.message
|
74
|
+
"Channel not found #{channel}"
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baez_slack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luciano Adonis
|
8
|
+
- Nicolas Noudia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-07-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: async-websocket
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.8.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.8.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: slack-ruby-client
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.14.5
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.14.5
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: colorize
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: The dream of enerbot
|
57
|
+
email: luciano.adonisv@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/baez_slack.rb
|
63
|
+
- lib/modules/console_slack.rb
|
64
|
+
- lib/modules/message_slack.rb
|
65
|
+
- lib/modules/read_slack.rb
|
66
|
+
- lib/modules/search_slack.rb
|
67
|
+
homepage: https://rubygems.org/gems/core_slack
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.7.6
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Core functions for any kind of interaction with Slack
|
91
|
+
test_files: []
|