energon-notify 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/credentials.rb +10 -0
- data/lib/energon_notify.rb +28 -0
- data/lib/modules/message_slack.rb +86 -0
- data/lib/modules/search_slack.rb +74 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 897c422987699d96e089a54ef4cdfa951f66bcbcee3f4bebc4628b755f98ba15
|
4
|
+
data.tar.gz: 82a2727d743281860f738e8d480381ab30531148075d22360f0b9a74db495b72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 347655b117abe5f2742ec26793d5bc5133af0a03d11e5d051e062358522dbf4652c9577c30a5e3bdae714881c36283d7dd5178f43e2092bc5e27d35b5702671d
|
7
|
+
data.tar.gz: 00e1f604e6d752ef9c7b8d7a5b7b6adf80576eb36bf3c36cf31e657b25c9f22cc210217c16ef67538d5c88a4420722d1372e2fcf2e4230b5a1ed60e5d1a2538e
|
data/lib/credentials.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'slack-ruby-client'
|
2
|
+
require_relative "modules/search_slack"
|
3
|
+
require_relative "modules/message_slack"
|
4
|
+
require_relative "modules/message_discord"
|
5
|
+
require_relative "credentials"
|
6
|
+
|
7
|
+
# Slack Set Up
|
8
|
+
class EnergonNotify < Credentials
|
9
|
+
include MessageSlack
|
10
|
+
include SearchOnSlack
|
11
|
+
include MessageDiscord
|
12
|
+
|
13
|
+
def initialize(name: '', image: '', token: nil, as_user: false)
|
14
|
+
set_credentials
|
15
|
+
|
16
|
+
Slack.configure do |config|
|
17
|
+
config.token = token.nil? ? @bot_token : token
|
18
|
+
config.raise 'Missing token' unless config.token
|
19
|
+
end
|
20
|
+
|
21
|
+
@bot_name = name unless name.empty?
|
22
|
+
@bot_icon = image unless image.empty?
|
23
|
+
@bot_user = as_user
|
24
|
+
|
25
|
+
@time_client ||= Slack::RealTime::Client.new
|
26
|
+
@web_client ||= Slack::Web::Client.new
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'search_slack'
|
4
|
+
|
5
|
+
# Module for message interactions on Slack
|
6
|
+
module MessageSlack
|
7
|
+
include SearchOnSlack
|
8
|
+
|
9
|
+
def discern_end(data, ts = nil)
|
10
|
+
@thread = if data.respond_to? :thread_ts
|
11
|
+
data.ts
|
12
|
+
else
|
13
|
+
ts unless ts.nil?
|
14
|
+
end
|
15
|
+
@channel = if data.respond_to? :channel
|
16
|
+
data.channel
|
17
|
+
else
|
18
|
+
data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def attach_format(data, title, color = '#e93d94')
|
23
|
+
text = ''
|
24
|
+
data.each { |v| text << "#{v}\n" }
|
25
|
+
[{
|
26
|
+
"pretext": title,
|
27
|
+
"color": color,
|
28
|
+
"text": text
|
29
|
+
}]
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_message(text, data, ts = nil)
|
33
|
+
discern_end(data, ts)
|
34
|
+
@web_client.chat_postMessage channel: @channel,
|
35
|
+
text: text,
|
36
|
+
icon_url: @bot_icon,
|
37
|
+
username: @bot_name,
|
38
|
+
thread_ts: @thread,
|
39
|
+
as_user: @bot_user
|
40
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
41
|
+
print e.message
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def send_direct_message(text, channel)
|
46
|
+
dm = get_user_id(channel)
|
47
|
+
dm == false ? false : send_message(text, dm)
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_attachment(attachment, data, ts = nil)
|
51
|
+
discern_end(data, ts)
|
52
|
+
@web_client.chat_postMessage channel: @channel,
|
53
|
+
attachments: attachment,
|
54
|
+
icon_url: @bot_icon,
|
55
|
+
username: @bot_name,
|
56
|
+
thread_ts: @thread,
|
57
|
+
as_user: @bot_user
|
58
|
+
end
|
59
|
+
|
60
|
+
def send_file(path, data, ts = nil)
|
61
|
+
file = path
|
62
|
+
discern_end(data, ts)
|
63
|
+
@web_client.files_upload channels: @channel,
|
64
|
+
icon_url: @bot_icon,
|
65
|
+
username: @bot_name,
|
66
|
+
thread_ts: @thread,
|
67
|
+
as_user: @bot_user,
|
68
|
+
file: Faraday::UploadIO.new(file, 'text'),
|
69
|
+
title: File.basename(file),
|
70
|
+
filename: File.basename(file)
|
71
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
72
|
+
print e.message
|
73
|
+
false
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_reaction(icon, channel, thread)
|
77
|
+
@web_client.reactions_add channel: channel,
|
78
|
+
name: icon,
|
79
|
+
timestamp: thread,
|
80
|
+
icon_url: @bot_icon,
|
81
|
+
username: @bot_name
|
82
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
83
|
+
print e.message
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Module for searching content on Slack
|
2
|
+
module SearchOnSlack
|
3
|
+
def get_user_id(channel = @channel_id)
|
4
|
+
dm = @web_client.conversations_open users: channel
|
5
|
+
dm.channel.id
|
6
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
7
|
+
print e.message
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_user_info(user)
|
12
|
+
c = @web_client.users_info user: user
|
13
|
+
c.user
|
14
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
15
|
+
print e.message
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_user_list
|
20
|
+
@web_client.users_list
|
21
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
22
|
+
print e.message
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def verify_type
|
27
|
+
properties = {
|
28
|
+
'channel' => @properties.is_channel,
|
29
|
+
'group' => @properties.is_group,
|
30
|
+
'im' => @properties.is_im
|
31
|
+
}
|
32
|
+
check = ''
|
33
|
+
properties.each { |k, v| check = k if v == true }
|
34
|
+
check
|
35
|
+
end
|
36
|
+
|
37
|
+
def conversation_type(channel = @channel_id)
|
38
|
+
@channel_id = channel if @channel_id.nil?
|
39
|
+
result = conversation_info
|
40
|
+
if result == false
|
41
|
+
print 'Check if IM'
|
42
|
+
@channel_id = get_user_id
|
43
|
+
conversation_info == false ? false : verify_type
|
44
|
+
else
|
45
|
+
verify_type
|
46
|
+
end
|
47
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
48
|
+
print e.message
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
def conversation_info(channel = @channel_id)
|
53
|
+
info = @web_client.conversations_info channel: channel
|
54
|
+
@properties = info.channel
|
55
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
56
|
+
print e.message
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
def conversation_list
|
61
|
+
@web_client.conversations_list.channels
|
62
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
63
|
+
print e.message
|
64
|
+
false
|
65
|
+
end
|
66
|
+
|
67
|
+
def search_messages_on(channel, quantity = 5)
|
68
|
+
# type = conversation_type(channel)
|
69
|
+
@web_client.conversations_history channel: channel, count: quantity
|
70
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
71
|
+
print e.message
|
72
|
+
"Channel not found #{channel}"
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: energon-notify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luciano Adonis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slack-ruby-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
description: Post message methods from Slack, Twitter, and Discord.
|
42
|
+
email: luciano.adonisv@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/credentials.rb
|
48
|
+
- lib/energon_notify.rb
|
49
|
+
- lib/modules/message_slack.rb
|
50
|
+
- lib/modules/search_slack.rb
|
51
|
+
homepage: https://rubygems.org/gems/core_slack
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.0.3
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Spam messages to our clients
|
74
|
+
test_files: []
|