notify-energon 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/modules/message_discord.rb +13 -0
- data/lib/modules/message_slack.rb +84 -0
- data/lib/modules/search_slack.rb +74 -0
- data/lib/notify-energon.rb +29 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 87228b7fd0882937434b74f2884b20ec6cc93f7732f206be27942173aa553675
|
4
|
+
data.tar.gz: 0d0228de19e9391845d707fb6c727c67901091cb6a53681320c86281c421d926
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b28c4f025ab961568686d027ee52efa961808e262cf6736039fa8c38f4ede0795fde79f228f361da8fd60446c8d0b525b3e1c7442dbc68190f387752e8d9a81
|
7
|
+
data.tar.gz: 4169e5d9426b9a6ec0a0f94b923749d036cf9a9c34b64be21fa097ce793b2884bd569d45bd098584c2ad1e3ac4e78148c47579ed23431b24e5b1c6e34cfb3b7a
|
data/lib/credentials.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
class Credentials
|
3
|
+
def set_credentials
|
4
|
+
@bot_token = ENV['SLACK_BOT_TOKEN']
|
5
|
+
@bot_name = ENV['SLACK_BOT_NAME']
|
6
|
+
@bot_icon = ENV['SLACK_BOT_ICON']
|
7
|
+
@bot_channel = ENV['SLACK_DEFAULT_CHANNEL']
|
8
|
+
@bot_default_output = ENV['SLACK_DEFAULT_OUTPUT']
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'discordrb/webhooks'
|
2
|
+
|
3
|
+
module MessageDiscord
|
4
|
+
def discord_event(text, web_hook = ENV['DISCORD_WEBHOOK'])
|
5
|
+
client = Discordrb::Webhooks::Client.new(url: web_hook)
|
6
|
+
client.execute do |builder|
|
7
|
+
builder.content = text
|
8
|
+
end
|
9
|
+
rescue StandardError => e
|
10
|
+
print "Discord: #{e.message}"
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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: @bot_user
|
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: @bot_user
|
56
|
+
end
|
57
|
+
|
58
|
+
def send_file(path, data, ts = nil)
|
59
|
+
file = path
|
60
|
+
discern_end(data, ts)
|
61
|
+
@web_client.files_upload channels: @channel,
|
62
|
+
icon_url: @bot_icon,
|
63
|
+
username: @bot_name,
|
64
|
+
thread_ts: @thread,
|
65
|
+
as_user: @bot_user,
|
66
|
+
file: Faraday::UploadIO.new(file, 'text'),
|
67
|
+
title: File.basename(file),
|
68
|
+
filename: File.basename(file)
|
69
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
70
|
+
print e.message
|
71
|
+
false
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_reaction(icon, channel, thread)
|
75
|
+
@web_client.reactions_add channel: channel,
|
76
|
+
name: icon,
|
77
|
+
timestamp: thread,
|
78
|
+
icon_url: @bot_icon,
|
79
|
+
username: @bot_name
|
80
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
81
|
+
print e.message
|
82
|
+
false
|
83
|
+
end
|
84
|
+
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
|
@@ -0,0 +1,29 @@
|
|
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: '', slack_enabled: false, slack_token: nil, slack_as_user: false)
|
14
|
+
set_credentials
|
15
|
+
if slack_enabled
|
16
|
+
Slack.configure do |config|
|
17
|
+
config.token = slack_token.nil? ? @bot_token : slack_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 = slack_as_user
|
24
|
+
|
25
|
+
@time_client ||= Slack::RealTime::Client.new
|
26
|
+
@web_client ||= Slack::Web::Client.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notify-energon
|
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: discordrb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: twitter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 7.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 7.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
description: Send notifications.
|
70
|
+
email: luciano.adonisv@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/credentials.rb
|
76
|
+
- lib/modules/message_discord.rb
|
77
|
+
- lib/modules/message_slack.rb
|
78
|
+
- lib/modules/search_slack.rb
|
79
|
+
- lib/notify-energon.rb
|
80
|
+
homepage: https://rubygems.org/gems/core_slack
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.0.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Spam messages to our clients
|
103
|
+
test_files: []
|