bas 1.4.2 → 1.5.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/bas/bot/fetch_billing_from_digital_ocean.rb +1 -3
- data/lib/bas/bot/fetch_images_from_discord.rb +78 -0
- data/lib/bas/bot/review_domain_availability.rb +1 -6
- data/lib/bas/bot/review_media.rb +17 -15
- data/lib/bas/bot/{write_media_review_in_notion.rb → write_media_review_in_discord.rb} +19 -51
- data/lib/bas/bot/write_media_review_requests.rb +5 -20
- data/lib/bas/utils/discord/request.rb +55 -0
- data/lib/bas/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7973ce35f2f21618cec7a06ad45604419d1ef3523a63d451f7e21ec5034fe766
|
4
|
+
data.tar.gz: b4245c4f9adda76ce60e1638e812dd8efee15afe2643bb85c63f22bf3e27f516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e54fb58367965508444478928581d8822212def15cfe3b1d5b47ef75ef0a5126293d35295d8a54f43f828fb97a102f86c68d7a3eb057c66f82db435576be042e
|
7
|
+
data.tar.gz: 471ec1cff36b69d3e51468c0372a00b0fb1a1185977d82ab458a3afbfce6aeccd32bf4861dc93f67270f6c301aff1c6fea7c75aeacd933db10ce9e486b7b69b1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 1.5.0 (03.10.2024)
|
4
|
+
- [Add bots to fetch images from Discord](https://github.com/kommitters/bas/issues/103)
|
5
|
+
|
6
|
+
# 1.4.3 (06.09.2024)
|
7
|
+
- [Adjust website monitoring use case notifications](https://github.com/kommitters/bas/issues/99)
|
8
|
+
|
3
9
|
# 1.4.2 (28.08.2024)
|
4
10
|
- [Adjust digital ocean billing bots](https://github.com/kommitters/bas/issues/97)
|
5
11
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./base"
|
4
|
+
require_relative "../read/default"
|
5
|
+
require_relative "../utils/discord/request"
|
6
|
+
require_relative "../write/postgres"
|
7
|
+
|
8
|
+
module Bot
|
9
|
+
##
|
10
|
+
# The Bot::FetchImagesFromDiscord class serves as a bot implementation to read images
|
11
|
+
# from a any thread of Discord channel.
|
12
|
+
#
|
13
|
+
# <br>
|
14
|
+
# <b>Example</b>
|
15
|
+
#
|
16
|
+
# options = {
|
17
|
+
# process_options: {
|
18
|
+
# secret_token: "discord_bot_token"
|
19
|
+
# discord_channel: "discord_channel_id"
|
20
|
+
# },
|
21
|
+
# write_options: {
|
22
|
+
# connection: {
|
23
|
+
# host: "localhost",
|
24
|
+
# port: 5432,
|
25
|
+
# dbname: "bas",
|
26
|
+
# user: "postgres",
|
27
|
+
# password: "postgres"
|
28
|
+
# },
|
29
|
+
# db_table: "review_images",
|
30
|
+
# tag: "FetchImagesFromDiscord"
|
31
|
+
# }
|
32
|
+
# }
|
33
|
+
#
|
34
|
+
# bot = Bot::FetchImagesFromDiscord.new(options)
|
35
|
+
# bot.execute
|
36
|
+
#
|
37
|
+
class FetchImagesFromDiscord < Bot::Base
|
38
|
+
# read function to execute the Default Read component
|
39
|
+
#
|
40
|
+
def read
|
41
|
+
reader = Read::Default.new
|
42
|
+
|
43
|
+
reader.execute
|
44
|
+
end
|
45
|
+
|
46
|
+
# Process function to execute the Discord utility to fetch images from a discord channel threads
|
47
|
+
#
|
48
|
+
def process
|
49
|
+
response = Utils::Discord::Request.get_thread_messages(params)
|
50
|
+
|
51
|
+
if !response.nil?
|
52
|
+
{ success: { results: response } }
|
53
|
+
else
|
54
|
+
{ error: "response is empty" }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Write function to execute the PostgresDB write component
|
59
|
+
#
|
60
|
+
def write
|
61
|
+
write = Write::Postgres.new(write_options, process_response)
|
62
|
+
|
63
|
+
write.execute
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def params
|
69
|
+
{
|
70
|
+
endpoint: "channels/#{process_options[:discord_channel]}/messages",
|
71
|
+
channel_id: process_options[:discord_channel],
|
72
|
+
secret_token: process_options[:secret_token],
|
73
|
+
method: "get",
|
74
|
+
body: {}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -90,12 +90,7 @@ module Bot
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def notification(response)
|
93
|
-
data
|
94
|
-
domain: read_response.data["url"],
|
95
|
-
status_code: response.code
|
96
|
-
}
|
97
|
-
|
98
|
-
":warning: Domain is down: #{data}"
|
93
|
+
":warning: The Domain #{read_response.data["url"]} is down with an error code of #{response.code}"
|
99
94
|
end
|
100
95
|
end
|
101
96
|
end
|
data/lib/bas/bot/review_media.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "md_to_notion"
|
4
3
|
require "json"
|
5
4
|
|
6
5
|
require_relative "./base"
|
@@ -11,8 +10,8 @@ require_relative "../utils/openai/run_assistant"
|
|
11
10
|
module Bot
|
12
11
|
##
|
13
12
|
# The Bot::ReviewMedia class serves as a bot implementation to read from a postgres
|
14
|
-
# shared storage a
|
15
|
-
# be processed one by one.
|
13
|
+
# shared storage a images hash with a specific format and create single request
|
14
|
+
# on the shared storage to be processed one by one.
|
16
15
|
#
|
17
16
|
# <br>
|
18
17
|
# <b>Example</b>
|
@@ -32,7 +31,7 @@ module Bot
|
|
32
31
|
# process_options: {
|
33
32
|
# secret: "openai_secret",
|
34
33
|
# assistant_id: "openai_assistant_id",
|
35
|
-
# media_type: "
|
34
|
+
# media_type: "images"
|
36
35
|
# },
|
37
36
|
# write_options: {
|
38
37
|
# connection: {
|
@@ -72,7 +71,7 @@ module Bot
|
|
72
71
|
return error_response(response)
|
73
72
|
end
|
74
73
|
|
75
|
-
|
74
|
+
success_response(response)
|
76
75
|
end
|
77
76
|
|
78
77
|
# write function to execute the PostgresDB write component
|
@@ -115,19 +114,22 @@ module Bot
|
|
115
114
|
read_response.data["media"]
|
116
115
|
end
|
117
116
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
MdToNotion::Parser.markdown_to_notion_blocks(md_response).to_json
|
117
|
+
def success_response(response)
|
118
|
+
review = get_review(response)
|
119
|
+
{ success: media_hash.merge({ review: }) }
|
122
120
|
end
|
123
121
|
|
124
|
-
def
|
125
|
-
|
126
|
-
|
127
|
-
created_by = read_response.data["created_by"]
|
128
|
-
property = read_response.data["property"]
|
122
|
+
def get_review(response)
|
123
|
+
response.parsed_response["data"].first["content"].first["text"]["value"]
|
124
|
+
end
|
129
125
|
|
130
|
-
|
126
|
+
def media_hash
|
127
|
+
{
|
128
|
+
thread_id: read_response.data["thread_id"],
|
129
|
+
property: read_response.data["property"],
|
130
|
+
author: read_response.data["author"],
|
131
|
+
media_type: process_options[:media_type]
|
132
|
+
}
|
131
133
|
end
|
132
134
|
|
133
135
|
def error_response(response)
|
@@ -4,14 +4,13 @@ require "json"
|
|
4
4
|
|
5
5
|
require_relative "./base"
|
6
6
|
require_relative "../read/postgres"
|
7
|
-
require_relative "../utils/notion/request"
|
8
|
-
require_relative "../utils/notion/update_db_state"
|
9
7
|
require_relative "../write/postgres"
|
8
|
+
require_relative "../utils/discord/request"
|
10
9
|
|
11
10
|
module Bot
|
12
11
|
##
|
13
|
-
# The Bot::
|
14
|
-
# shared storage
|
12
|
+
# The Bot::WriteMediaReviewInDiscord class serves as a bot implementation to read from a postgres
|
13
|
+
# shared storage images object blocks and send them to a thread of Discord channel
|
15
14
|
#
|
16
15
|
# <br>
|
17
16
|
# <b>Example</b>
|
@@ -29,7 +28,7 @@ module Bot
|
|
29
28
|
# tag: "FormatMediaReview"
|
30
29
|
# },
|
31
30
|
# process_options: {
|
32
|
-
#
|
31
|
+
# secret_token: "discord_bot_token"
|
33
32
|
# },
|
34
33
|
# write_options: {
|
35
34
|
# connection: {
|
@@ -40,16 +39,14 @@ module Bot
|
|
40
39
|
# password: "postgres"
|
41
40
|
# },
|
42
41
|
# db_table: "review_media",
|
43
|
-
# tag: "
|
42
|
+
# tag: "WriteMediaReviewInDiscord"
|
44
43
|
# }
|
45
44
|
# }
|
46
45
|
#
|
47
|
-
# bot = Bot::
|
46
|
+
# bot = Bot::WriteMediaReviewInDiscord.new(options)
|
48
47
|
# bot.execute
|
49
48
|
#
|
50
|
-
class
|
51
|
-
READY_STATE = "ready"
|
52
|
-
|
49
|
+
class WriteMediaReviewInDiscord < Bot::Base
|
53
50
|
# read function to execute the PostgresDB Read component
|
54
51
|
#
|
55
52
|
def read
|
@@ -58,17 +55,15 @@ module Bot
|
|
58
55
|
reader.execute
|
59
56
|
end
|
60
57
|
|
61
|
-
# process function to execute the
|
58
|
+
# process function to execute the Discord utility to send image feedback to a thread of a Discord channel
|
62
59
|
#
|
63
60
|
def process
|
64
61
|
return { success: { review_added: nil } } if unprocessable_response
|
65
62
|
|
66
|
-
response = Utils::
|
63
|
+
response = Utils::Discord::Request.write_media_text(params)
|
67
64
|
|
68
65
|
if response.code == 200
|
69
|
-
|
70
|
-
|
71
|
-
{ success: { page_id: read_response.data["page_id"], property: read_response.data["property"] } }
|
66
|
+
{ success: { thread_id: read_response.data["thread_id"], property: read_response.data["property"] } }
|
72
67
|
else
|
73
68
|
{ error: { message: response.parsed_response, status_code: response.code } }
|
74
69
|
end
|
@@ -93,54 +88,27 @@ module Bot
|
|
93
88
|
|
94
89
|
def params
|
95
90
|
{
|
96
|
-
endpoint: "
|
97
|
-
|
98
|
-
method: "
|
91
|
+
endpoint: "channels/#{read_response.data["thread_id"]}/messages",
|
92
|
+
secret_token: process_options[:secret_token],
|
93
|
+
method: "post",
|
99
94
|
body:
|
100
95
|
}
|
101
96
|
end
|
102
97
|
|
103
98
|
def body
|
104
|
-
{
|
105
|
-
end
|
106
|
-
|
107
|
-
def toggle
|
108
|
-
{
|
109
|
-
rich_text: [{ type: "text", text: { content: toggle_title } }, mention],
|
110
|
-
children: toggle_childrens
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
def toggle_childrens
|
115
|
-
JSON.parse(read_response.data["review"])
|
99
|
+
{ content: "#{toggle_title}\n\n#{read_response.data["review"]}\n\n#{mention_content}" }
|
116
100
|
end
|
117
101
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
mention: {
|
122
|
-
type: "user",
|
123
|
-
user: { id: read_response.data["created_by"] }
|
124
|
-
}
|
125
|
-
}
|
102
|
+
def mention_content
|
103
|
+
author_name = read_response.data["author"]
|
104
|
+
"<@#{author_name}>"
|
126
105
|
end
|
127
106
|
|
128
107
|
def toggle_title
|
129
108
|
case read_response.data["media_type"]
|
130
|
-
when "images" then "Image review results
|
131
|
-
when "paragraph" then "Text review results
|
109
|
+
when "images" then "Image review results"
|
110
|
+
when "paragraph" then "Text review results"
|
132
111
|
end
|
133
112
|
end
|
134
|
-
|
135
|
-
def update_state
|
136
|
-
data = {
|
137
|
-
property: read_response.data["property"],
|
138
|
-
page_id: read_response.data["page_id"],
|
139
|
-
state: READY_STATE,
|
140
|
-
secret: process_options[:secret]
|
141
|
-
}
|
142
|
-
|
143
|
-
Utils::Notion::UpdateDbState.execute(data)
|
144
|
-
end
|
145
113
|
end
|
146
114
|
end
|
@@ -23,8 +23,8 @@ module Bot
|
|
23
23
|
# user: "postgres",
|
24
24
|
# password: "postgres"
|
25
25
|
# },
|
26
|
-
# db_table: "
|
27
|
-
# tag: "
|
26
|
+
# db_table: "review_images",
|
27
|
+
# tag: "FetchMediaFromDiscord"
|
28
28
|
# },
|
29
29
|
# process_options: {
|
30
30
|
# connection: {
|
@@ -34,7 +34,7 @@ module Bot
|
|
34
34
|
# user: "postgres",
|
35
35
|
# password: "postgres"
|
36
36
|
# },
|
37
|
-
# db_table: "
|
37
|
+
# db_table: "review_images",
|
38
38
|
# tag: "ReviewMediaRequest"
|
39
39
|
# },
|
40
40
|
# write_options: {
|
@@ -45,7 +45,7 @@ module Bot
|
|
45
45
|
# user: "postgres",
|
46
46
|
# password: "postgres"
|
47
47
|
# },
|
48
|
-
# db_table: "
|
48
|
+
# db_table: "review_images",
|
49
49
|
# tag: "WriteMediaReviewRequests"
|
50
50
|
# }
|
51
51
|
# }
|
@@ -54,8 +54,6 @@ module Bot
|
|
54
54
|
# bot.execute
|
55
55
|
#
|
56
56
|
class WriteMediaReviewRequests < Bot::Base
|
57
|
-
IN_PROCESS_STATE = "in process"
|
58
|
-
|
59
57
|
# read function to execute the PostgresDB Read component
|
60
58
|
#
|
61
59
|
def read
|
@@ -64,7 +62,7 @@ module Bot
|
|
64
62
|
reader.execute
|
65
63
|
end
|
66
64
|
|
67
|
-
# Process function to execute the
|
65
|
+
# Process function to execute the Discord utility create single review requests
|
68
66
|
#
|
69
67
|
def process
|
70
68
|
return { success: { created: nil } } if unprocessable_response
|
@@ -100,20 +98,7 @@ module Bot
|
|
100
98
|
def write_request(request)
|
101
99
|
return { error: request } if request["media"].empty? || !request["error"].nil?
|
102
100
|
|
103
|
-
update_state(request)
|
104
|
-
|
105
101
|
{ success: request }
|
106
102
|
end
|
107
|
-
|
108
|
-
def update_state(request)
|
109
|
-
data = {
|
110
|
-
property: request["property"],
|
111
|
-
page_id: request["page_id"],
|
112
|
-
state: IN_PROCESS_STATE,
|
113
|
-
secret: process_options[:secret]
|
114
|
-
}
|
115
|
-
|
116
|
-
Utils::Notion::UpdateDbState.execute(data)
|
117
|
-
end
|
118
103
|
end
|
119
104
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "uri"
|
5
|
+
require "httparty"
|
6
|
+
|
7
|
+
module Utils
|
8
|
+
module Discord
|
9
|
+
##
|
10
|
+
# This module is a Discord utility for obtain all images of any threads of a
|
11
|
+
# Discord channel.
|
12
|
+
#
|
13
|
+
module Request
|
14
|
+
DISCORD_BASE_URL = "https://discord.com/api/v10"
|
15
|
+
|
16
|
+
# Implements the request process logic to Discord.
|
17
|
+
#
|
18
|
+
# <br>
|
19
|
+
# <b>Params:</b>
|
20
|
+
# * <tt>method</tt> HTTP request method: post, get, put, etc.
|
21
|
+
# * <tt>body</tt> Request body (Hash).
|
22
|
+
# * <tt>endpoint</tt> Notion resource endpoint.
|
23
|
+
# * <tt>secret_token</tt> Discord Bot Token.
|
24
|
+
#
|
25
|
+
# <br>
|
26
|
+
#
|
27
|
+
#
|
28
|
+
|
29
|
+
def self.get_discord_images(message)
|
30
|
+
images_urls = message.attachments.map(&:url)
|
31
|
+
|
32
|
+
{
|
33
|
+
"media" => images_urls,
|
34
|
+
"thread_id" => message.id,
|
35
|
+
"author" => message.author.username,
|
36
|
+
"timestamp" => message.timestamp.to_s,
|
37
|
+
"property" => "images"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.write_media_text(params)
|
42
|
+
url = URI.parse("#{DISCORD_BASE_URL}/#{params[:endpoint]}")
|
43
|
+
headers = headers(params[:secret_token])
|
44
|
+
HTTParty.send(params[:method], url, { body: params[:body].to_json, headers: })
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.headers(secret_token)
|
48
|
+
{
|
49
|
+
"Authorization" => secret_token.to_s,
|
50
|
+
"Content-Type" => "application/json"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/bas/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kommitters Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gmail_xoauth
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- lib/bas/bot/fetch_domains_wip_limit_from_notion.rb
|
197
197
|
- lib/bas/bot/fetch_emails_from_imap.rb
|
198
198
|
- lib/bas/bot/fetch_github_issues.rb
|
199
|
+
- lib/bas/bot/fetch_images_from_discord.rb
|
199
200
|
- lib/bas/bot/fetch_media_from_notion.rb
|
200
201
|
- lib/bas/bot/fetch_next_week_birthdays_from_notion.rb
|
201
202
|
- lib/bas/bot/fetch_next_week_ptos_from_notion.rb
|
@@ -214,7 +215,7 @@ files:
|
|
214
215
|
- lib/bas/bot/update_work_item.rb
|
215
216
|
- lib/bas/bot/verify_issue_existance_in_notion.rb
|
216
217
|
- lib/bas/bot/write_domain_review_requests.rb
|
217
|
-
- lib/bas/bot/
|
218
|
+
- lib/bas/bot/write_media_review_in_discord.rb
|
218
219
|
- lib/bas/bot/write_media_review_requests.rb
|
219
220
|
- lib/bas/read/base.rb
|
220
221
|
- lib/bas/read/default.rb
|
@@ -222,6 +223,7 @@ files:
|
|
222
223
|
- lib/bas/read/types/response.rb
|
223
224
|
- lib/bas/utils/digital_ocean/request.rb
|
224
225
|
- lib/bas/utils/discord/integration.rb
|
226
|
+
- lib/bas/utils/discord/request.rb
|
225
227
|
- lib/bas/utils/exceptions/function_not_implemented.rb
|
226
228
|
- lib/bas/utils/exceptions/invalid_process_response.rb
|
227
229
|
- lib/bas/utils/github/octokit_client.rb
|
@@ -262,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
264
|
- !ruby/object:Gem::Version
|
263
265
|
version: '0'
|
264
266
|
requirements: []
|
265
|
-
rubygems_version: 3.5.
|
267
|
+
rubygems_version: 3.5.16
|
266
268
|
signing_key:
|
267
269
|
specification_version: 4
|
268
270
|
summary: BAS - Business automation system
|