chatgpt_assistant 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.env_sample +1 -1
  3. data/.rubocop.yml +3 -3
  4. data/Gemfile +19 -5
  5. data/Gemfile.lock +64 -50
  6. data/README.md +14 -13
  7. data/Rakefile +2 -0
  8. data/docker-compose.prod.yml +1 -1
  9. data/docker-compose.yml +18 -0
  10. data/exe/chatgpt_bot +3 -0
  11. data/lib/bots/application_bot.rb +15 -5
  12. data/lib/bots/discord_bot.rb +42 -15
  13. data/lib/bots/helpers/authentication_helper.rb +7 -6
  14. data/lib/bots/helpers/discord_helper.rb +29 -7
  15. data/lib/bots/helpers/discord_voice_helper.rb +1 -1
  16. data/lib/bots/helpers/messenger_helper.rb +35 -36
  17. data/lib/bots/helpers/search_helper.rb +3 -3
  18. data/lib/bots/helpers/telegram_helper.rb +19 -35
  19. data/lib/bots/helpers/telegram_voice_helper.rb +33 -0
  20. data/lib/bots/helpers/validation_helper.rb +9 -0
  21. data/lib/bots/helpers/visit_helper.rb +4 -0
  22. data/lib/bots/jobs/new_chat_job.rb +17 -0
  23. data/lib/bots/jobs/register_job.rb +16 -0
  24. data/lib/bots/jobs/voice_connect_job.rb +14 -0
  25. data/lib/bots/services/new_chat_service.rb +34 -0
  26. data/lib/bots/services/register_service.rb +36 -0
  27. data/lib/bots/services/voice_connect_service.rb +29 -0
  28. data/lib/bots/telegram_bot.rb +72 -54
  29. data/lib/chatgpt_assistant/chatter.rb +17 -6
  30. data/lib/chatgpt_assistant/config.rb +23 -3
  31. data/lib/chatgpt_assistant/default_messages.rb +72 -30
  32. data/lib/chatgpt_assistant/error.rb +219 -0
  33. data/lib/chatgpt_assistant/migrations.rb +3 -30
  34. data/lib/chatgpt_assistant/models.rb +24 -29
  35. data/lib/chatgpt_assistant/sidekiq.rb +7 -0
  36. data/lib/chatgpt_assistant/sidekiq.yml +10 -0
  37. data/lib/chatgpt_assistant/version.rb +1 -1
  38. data/lib/chatgpt_assistant.rb +4 -12
  39. data/prompts-data/awesome-en-prompts.csv +164 -0
  40. data/prompts-data/awesome-pt-prompts.csv +164 -0
  41. metadata +15 -4
  42. data/lib/bots/helpers/logger_action_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23b30dcd5724b3978f30a1ac8ebabce7c47b2013302282248a9a10e67904d631
4
- data.tar.gz: a4cb01e4548897b34152a63ca600eb1b9fa72c3a2131dbb950b95cb998328cc2
3
+ metadata.gz: 9317ab1f4742c358a91f3e8ec363d8ed72147c2a31e0a312ec6c5ad54215c8db
4
+ data.tar.gz: e3a6a3f6099a4dcb47b262fb388f5f783a2f48466b1946f2e140e1a1b4c25767
5
5
  SHA512:
6
- metadata.gz: 0f7d4daf964b6566c3a703b971090924b20d3d818b886533deae985eeac719860c40dfefef63983069f57cb991b4e02611e0f86f98fb7fdff9d288287f222513
7
- data.tar.gz: 228a9a7799d596c5da4e53e0a9f8a505587f15f99af4928fef1824a88449a7e0febc64289406c29f2c67a038440fb19e054ccb2a389eec6831be041031af5bf6
6
+ metadata.gz: 3ea5f6b13b7db43f7261d9a726257bdf9e37a45bda2d34149bf7c35c659eee8092aec29a3dc7db8dc3222c005c65941f10f6b24f589f20ab0786a91e69290f27
7
+ data.tar.gz: 46e7e83be3e53a7ece0fbaf0c59d67054270e05e0d6fad8b4fb09194f57a2de82d136203110fb9de20d11a1160c8b29dd2be19a026567528c898224a08452f67
data/.env_sample CHANGED
@@ -1,7 +1,7 @@
1
1
  ENV_TYPE=development
2
2
  LANGUAGE=en # or pt currently
3
3
  MODE=aws # or ibm
4
- DISCORD_PREFIX=dgpt!
4
+ DISCORD_PREFIX=!!
5
5
 
6
6
  POSTGRES_DB=chatgpt_assistant_development # or your database
7
7
  POSTGRES_USER=postgres # or your user
data/.rubocop.yml CHANGED
@@ -11,16 +11,16 @@ Style/StringLiteralsInInterpolation:
11
11
  EnforcedStyle: double_quotes
12
12
 
13
13
  Layout/LineLength:
14
- Max: 160
14
+ Max: 200
15
15
 
16
16
  Metrics/ModuleLength:
17
17
  Max: 120
18
18
 
19
19
  Metrics/MethodLength:
20
- Max: 200
20
+ Max: 250
21
21
 
22
22
  Metrics/BlockLength:
23
- Max: 200
23
+ Max: 250
24
24
 
25
25
  Metrics/ClassLength:
26
26
  Max: 300
data/Gemfile CHANGED
@@ -6,15 +6,27 @@ gem "bcrypt"
6
6
 
7
7
  gem "rake", "~> 13.0"
8
8
 
9
- gem "rspec", "~> 3.0", group: :test
9
+ gem "rspec", "~> 3.12", group: :test
10
+
11
+ gem "rspec-rails", "~> 6.0", group: :test
10
12
 
11
13
  gem "simplecov", "~> 0.21", group: :test
12
14
 
13
15
  gem "vcr", "~> 6.0", group: :test
14
16
 
15
- gem "rubocop", "~> 1.49"
17
+ gem "shoulda-matchers", "~> 5.3", group: :test
18
+
19
+ gem "factory_bot_rails", "~> 6.0", group: :test
20
+
21
+ gem "faker", "~> 2.0", group: :test
22
+
23
+ gem "database_cleaner", "~> 2.0", group: :test
24
+
25
+ gem "dotenv", "~> 2.0", group: :test
16
26
 
17
- gem "rubocop-rspec", "~> 2.4"
27
+ gem "rubocop", "~> 1.50"
28
+
29
+ gem "rubocop-rspec", "~> 2.20"
18
30
 
19
31
  gem "telegram-bot-ruby", "~> 0.16"
20
32
 
@@ -28,8 +40,6 @@ gem "activerecord"
28
40
 
29
41
  gem "activesupport"
30
42
 
31
- gem "actionmailer"
32
-
33
43
  gem "redis"
34
44
 
35
45
  gem "sidekiq"
@@ -47,3 +57,7 @@ gem "lucy_dockerunner"
47
57
  gem "ibm_watson"
48
58
 
49
59
  gem "aws-sdk-polly"
60
+
61
+ gem "awesome_chatgpt_actors"
62
+
63
+ gem "sidekiq-expiring-jobs"
data/Gemfile.lock CHANGED
@@ -1,16 +1,6 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- actionmailer (7.0.4.3)
5
- actionpack (= 7.0.4.3)
6
- actionview (= 7.0.4.3)
7
- activejob (= 7.0.4.3)
8
- activesupport (= 7.0.4.3)
9
- mail (~> 2.5, >= 2.5.4)
10
- net-imap
11
- net-pop
12
- net-smtp
13
- rails-dom-testing (~> 2.0)
14
4
  actionpack (7.0.4.3)
15
5
  actionview (= 7.0.4.3)
16
6
  activesupport (= 7.0.4.3)
@@ -24,9 +14,6 @@ GEM
24
14
  erubi (~> 1.4)
25
15
  rails-dom-testing (~> 2.0)
26
16
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
27
- activejob (7.0.4.3)
28
- activesupport (= 7.0.4.3)
29
- globalid (>= 0.3.6)
30
17
  activemodel (7.0.4.3)
31
18
  activesupport (= 7.0.4.3)
32
19
  activerecord (7.0.4.3)
@@ -39,11 +26,13 @@ GEM
39
26
  i18n (>= 1.6, < 2)
40
27
  minitest (>= 5.1)
41
28
  tzinfo (~> 2.0)
42
- addressable (2.8.1)
29
+ addressable (2.8.4)
43
30
  public_suffix (>= 2.0.2, < 6.0)
44
31
  ast (2.4.2)
32
+ awesome_chatgpt_actors (0.1.3)
33
+ csv (~> 3.1)
45
34
  aws-eventstream (1.2.0)
46
- aws-partitions (1.735.0)
35
+ aws-partitions (1.748.0)
47
36
  aws-sdk-core (3.171.0)
48
37
  aws-eventstream (~> 1, >= 1.0.2)
49
38
  aws-partitions (~> 1, >= 1.651.0)
@@ -65,7 +54,13 @@ GEM
65
54
  concurrent-ruby (1.2.2)
66
55
  connection_pool (2.4.0)
67
56
  crass (1.0.6)
68
- date (3.3.3)
57
+ csv (3.2.6)
58
+ database_cleaner (2.0.2)
59
+ database_cleaner-active_record (>= 2, < 3)
60
+ database_cleaner-active_record (2.1.0)
61
+ activerecord (>= 5.a)
62
+ database_cleaner-core (~> 2.0.0)
63
+ database_cleaner-core (2.0.1)
69
64
  descendants_tracker (0.0.4)
70
65
  thread_safe (~> 0.3, >= 0.3.1)
71
66
  diff-lcs (1.5.0)
@@ -80,19 +75,27 @@ GEM
80
75
  docile (1.4.0)
81
76
  domain_name (0.5.20190701)
82
77
  unf (>= 0.0.5, < 1.0.0)
78
+ dotenv (2.8.1)
83
79
  dry-inflector (1.0.0)
84
80
  erubi (1.12.0)
85
81
  et-orbi (1.2.7)
86
82
  tzinfo
87
83
  event_emitter (0.2.6)
88
84
  eventmachine (1.2.7)
85
+ factory_bot (6.2.1)
86
+ activesupport (>= 5.0.0)
87
+ factory_bot_rails (6.2.0)
88
+ factory_bot (~> 6.2.0)
89
+ railties (>= 5.0.0)
90
+ faker (2.23.0)
91
+ i18n (>= 1.8.11, < 2)
89
92
  faraday (2.7.4)
90
93
  faraday-net_http (>= 2.0, < 3.1)
91
94
  ruby2_keywords (>= 0.0.4)
92
95
  faraday-multipart (1.0.4)
93
96
  multipart-post (~> 2)
94
97
  faraday-net_http (3.0.2)
95
- faye-websocket (0.11.1)
98
+ faye-websocket (0.11.2)
96
99
  eventmachine (>= 0.12.0)
97
100
  websocket-driver (>= 0.5.1)
98
101
  ffi (1.15.5)
@@ -102,8 +105,6 @@ GEM
102
105
  fugit (1.8.1)
103
106
  et-orbi (~> 1, >= 1.2.7)
104
107
  raabro (~> 1.4)
105
- globalid (1.1.0)
106
- activesupport (>= 5.0)
107
108
  http (4.4.1)
108
109
  addressable (~> 2.3)
109
110
  http-cookie (~> 1.0)
@@ -132,41 +133,27 @@ GEM
132
133
  jmespath (1.6.2)
133
134
  json (2.6.3)
134
135
  jwt (2.2.3)
135
- loofah (2.19.1)
136
+ loofah (2.20.0)
136
137
  crass (~> 1.0.2)
137
138
  nokogiri (>= 1.5.9)
138
139
  lucy_dockerunner (0.1.9)
139
- mail (2.8.1)
140
- mini_mime (>= 0.1.1)
141
- net-imap
142
- net-pop
143
- net-smtp
140
+ method_source (1.0.0)
144
141
  mime-types (3.4.1)
145
142
  mime-types-data (~> 3.2015)
146
143
  mime-types-data (3.2023.0218.1)
147
- mini_mime (1.1.2)
148
144
  mini_portile2 (2.8.1)
149
145
  minitest (5.18.0)
150
146
  multi_json (1.15.0)
151
147
  multipart-post (2.3.0)
152
- net-imap (0.3.4)
153
- date
154
- net-protocol
155
- net-pop (0.1.2)
156
- net-protocol
157
- net-protocol (0.2.1)
158
- timeout
159
- net-smtp (0.3.3)
160
- net-protocol
161
148
  netrc (0.11.0)
162
- nokogiri (1.14.2)
149
+ nokogiri (1.14.3)
163
150
  mini_portile2 (~> 2.8.0)
164
151
  racc (~> 1.4)
165
- nokogiri (1.14.2-x86_64-linux)
152
+ nokogiri (1.14.3-x86_64-linux)
166
153
  racc (~> 1.4)
167
154
  opus-ruby (1.0.1)
168
155
  ffi
169
- parallel (1.22.1)
156
+ parallel (1.23.0)
170
157
  parser (3.2.2.0)
171
158
  ast (~> 2.4.1)
172
159
  pg (1.4.6)
@@ -181,13 +168,20 @@ GEM
181
168
  nokogiri (>= 1.6)
182
169
  rails-html-sanitizer (1.5.0)
183
170
  loofah (~> 2.19, >= 2.19.1)
171
+ railties (7.0.4.3)
172
+ actionpack (= 7.0.4.3)
173
+ activesupport (= 7.0.4.3)
174
+ method_source
175
+ rake (>= 12.2)
176
+ thor (~> 1.0)
177
+ zeitwerk (~> 2.5)
184
178
  rainbow (3.1.1)
185
179
  rake (13.0.6)
186
180
  redis (5.0.6)
187
181
  redis-client (>= 0.9.0)
188
- redis-client (0.14.0)
182
+ redis-client (0.14.1)
189
183
  connection_pool
190
- regexp_parser (2.7.0)
184
+ regexp_parser (2.8.0)
191
185
  rest-client (2.1.0)
192
186
  http-accept (>= 1.7.0, < 2.0)
193
187
  http-cookie (>= 1.0.2, < 2.0)
@@ -203,11 +197,19 @@ GEM
203
197
  rspec-expectations (3.12.2)
204
198
  diff-lcs (>= 1.2.0, < 2.0)
205
199
  rspec-support (~> 3.12.0)
206
- rspec-mocks (3.12.3)
200
+ rspec-mocks (3.12.5)
207
201
  diff-lcs (>= 1.2.0, < 2.0)
208
202
  rspec-support (~> 3.12.0)
203
+ rspec-rails (6.0.1)
204
+ actionpack (>= 6.1)
205
+ activesupport (>= 6.1)
206
+ railties (>= 6.1)
207
+ rspec-core (~> 3.11)
208
+ rspec-expectations (~> 3.11)
209
+ rspec-mocks (~> 3.11)
210
+ rspec-support (~> 3.11)
209
211
  rspec-support (3.12.0)
210
- rubocop (1.49.0)
212
+ rubocop (1.50.2)
211
213
  json (~> 2.3)
212
214
  parallel (~> 1.10)
213
215
  parser (>= 3.2.0.0)
@@ -221,18 +223,22 @@ GEM
221
223
  parser (>= 3.2.1.0)
222
224
  rubocop-capybara (2.17.1)
223
225
  rubocop (~> 1.41)
224
- rubocop-rspec (2.19.0)
226
+ rubocop-rspec (2.20.0)
225
227
  rubocop (~> 1.33)
226
228
  rubocop-capybara (~> 2.17)
227
229
  ruby-progressbar (1.13.0)
228
230
  ruby2_keywords (0.0.5)
229
231
  rufus-scheduler (3.8.2)
230
232
  fugit (~> 1.1, >= 1.1.6)
231
- sidekiq (7.0.7)
233
+ shoulda-matchers (5.3.0)
234
+ activesupport (>= 5.2.0)
235
+ sidekiq (7.0.8)
232
236
  concurrent-ruby (< 2)
233
237
  connection_pool (>= 2.3.0)
234
238
  rack (>= 2.2.4)
235
239
  redis-client (>= 0.11.0)
240
+ sidekiq-expiring-jobs (0.1.0)
241
+ sidekiq (>= 6.0)
236
242
  sidekiq-scheduler (5.0.2)
237
243
  rufus-scheduler (~> 3.2)
238
244
  sidekiq (>= 6, < 8)
@@ -250,9 +256,9 @@ GEM
250
256
  faraday (~> 2.0)
251
257
  faraday-multipart (~> 1.0)
252
258
  virtus (~> 2.0)
259
+ thor (1.2.1)
253
260
  thread_safe (0.3.6)
254
261
  tilt (2.1.0)
255
- timeout (0.3.2)
256
262
  tzinfo (2.0.6)
257
263
  concurrent-ruby (~> 1.0)
258
264
  unf (0.1.4)
@@ -271,30 +277,38 @@ GEM
271
277
  websocket-driver (0.7.5)
272
278
  websocket-extensions (>= 0.1.0)
273
279
  websocket-extensions (0.1.5)
280
+ zeitwerk (2.6.7)
274
281
 
275
282
  PLATFORMS
276
283
  ruby
277
284
  x86_64-linux
278
285
 
279
286
  DEPENDENCIES
280
- actionmailer
281
287
  activemodel
282
288
  activerecord
283
289
  activerecord-import
284
290
  activesupport
291
+ awesome_chatgpt_actors
285
292
  aws-sdk-polly
286
293
  bcrypt
294
+ database_cleaner (~> 2.0)
287
295
  discordrb (~> 3.4)
296
+ dotenv (~> 2.0)
297
+ factory_bot_rails (~> 6.0)
298
+ faker (~> 2.0)
288
299
  faraday
289
300
  ibm_watson
290
301
  lucy_dockerunner
291
302
  pg
292
303
  rake (~> 13.0)
293
304
  redis
294
- rspec (~> 3.0)
295
- rubocop (~> 1.49)
296
- rubocop-rspec (~> 2.4)
305
+ rspec (~> 3.12)
306
+ rspec-rails (~> 6.0)
307
+ rubocop (~> 1.50)
308
+ rubocop-rspec (~> 2.20)
309
+ shoulda-matchers (~> 5.3)
297
310
  sidekiq
311
+ sidekiq-expiring-jobs
298
312
  sidekiq-scheduler
299
313
  simplecov (~> 0.21)
300
314
  streamio-ffmpeg
@@ -302,4 +316,4 @@ DEPENDENCIES
302
316
  vcr (~> 6.0)
303
317
 
304
318
  BUNDLED WITH
305
- 2.2.32
319
+ 2.4.10
data/README.md CHANGED
@@ -6,15 +6,14 @@
6
6
 
7
7
  This Ruby gem provides an easy way to initialize a client for Telegram and Discord bots using the ChatGPT API, audio transcription, IBM Cloud Text to Speech, and AWS Polly, creating an assistant that can answer questions in text and voice and have a conversation with the user.
8
8
 
9
- #### Languages supported currently: en, pt - contributions are welcome!
10
- You can contribute by adding your language to the DefaultMessages class in lib/chatgpt_assistant/default_messages.rb. You can also add your language to the list of languages in the README.md file.
11
- Pull request from language/YOUR_LANGUAGE to main, remember to name your pull request as "Add YOUR_LANGUAGE support".
9
+ #### Languages supported currently: en, pt
12
10
 
13
11
  Other contributions are welcome too!
14
12
  Remember to give a star to this repo if you like it!
15
13
  ## Requirements
16
14
 
17
- - Ruby > 2.6.0
15
+ - Ruby > 2.6.0 - for the gem who can create bots projects in your machine
16
+ - Ruby 3.2.2 - inside the docker contianer or for run the bots in your machine
18
17
  - Docker
19
18
  - Docker Compose
20
19
  - PostgreSQL
@@ -63,6 +62,11 @@ Remember to edit docker-compose.prod.yml when deploying to production.
63
62
  rake compose:up && sudo docker compose run --rm telegram exe/chatgpt_bot migrate
64
63
  ```
65
64
 
65
+ ## Install [Awesome Chatgpt Actors](https://github.com/JesusGautamah/awesome-chatgpt-actors)
66
+ ```bash
67
+ rake chatgpt_actors:install
68
+ ```
69
+
66
70
  ## Usage
67
71
 
68
72
  You can start the Docker Compose services required for the gem using the rake tasks provided by the Lucy Dockerunner gem. These tasks include compose:up, compose:down, compose:status, compose:shell, compose:restart, and others listed previously.
@@ -87,26 +91,23 @@ After starting the Docker Compose services, you can use the features of the gem
87
91
  ## Discord Bot Commands
88
92
 
89
93
  The discord commands prefix can be changed in the .env file.
90
- The default prefix is dgpt!
94
+ The default prefix is !!
91
95
 
92
96
  - dgpt!start - shows the welcome message
93
97
  - dgpt!help - shows the help message
94
- - dgpt!login email:password - logs in the user
95
- - dgpt!register email:password - registers a new user
98
+ - dgpt!login email:password - logs in the user. Remember to use private messages to register or login and share a server with right permissions with the bot to message it.
99
+ - dgpt!register email:password - registers a new user, email is not verfied yet, so you can use any email, the password is encrypted with bcrypt and stored in the database with salt.
96
100
  - dgpt!list - lists the user created chatbots
97
101
  - dgpt!sl_chat CHAT TITLE - starts a chat with the chatbot with the given title
98
102
  - dgpt!new_chat CHAT TITLE - creates a new chatbot with the given title
99
103
  - dgpt!ask TEXT - sends a text to the chatbot
100
- - dgpt!connect - connects the chat bot to the current channel
101
- - dgpt!disconnect - disconnects the chat bot from the current channel
102
- - dgpt!speak TEXT - sends a text to the chatbot and gets the response in voice
103
104
 
104
105
  ## Telegram Bot Commands
105
106
 
106
107
  - /start - shows the welcome message
107
108
  - /help - shows the help message
108
- - login/email:password - logs in the user
109
- - register/email:password - registers a new user
109
+ - login/email:password - logs in the user. Remember to use private messages to register or login.
110
+ - register/email:password - registers a new user, email is not verfied yet, so you can use any email, the password is encrypted with bcrypt and stored in the database with salt. Remember to use private messages to register or login.
110
111
  - list - lists the user created chatbots
111
112
  - sl_chat/CHAT TITLE - starts a chat with the chatbot with the given title
112
113
  - new_chat/CHAT TITLE - creates a new chatbot with the given title
@@ -146,4 +147,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
146
147
 
147
148
  ## Code of Conduct
148
149
 
149
- Everyone interacting in the ChatgptAssistant project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JesusGautamah/chatgpt_assistant/blob/master/CODE_OF_CONDUCT.md).
150
+ Everyone interacting in the ChatgptAssistant project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JesusGautamah/chatgpt_assistant/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -3,6 +3,7 @@
3
3
  # require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
  require "lucy_dockerunner"
6
+ require "awesome_chatgpt_actors"
6
7
 
7
8
  RSpec::Core::RakeTask.new(:spec)
8
9
 
@@ -13,3 +14,4 @@ RuboCop::RakeTask.new
13
14
  task default: %i[spec rubocop]
14
15
 
15
16
  LucyDockerunner.load_tasks
17
+ AwesomeChatgptActors.load_tasks
@@ -7,7 +7,7 @@ services:
7
7
  volumes:
8
8
  - ./db_data:/var/lib/postgresql/data
9
9
  env_file:
10
- - .env
10
+ - .env_prod
11
11
  telegram:
12
12
  build: .
13
13
  command: bash -c "exe/chatgpt_bot telegram"
data/docker-compose.yml CHANGED
@@ -1,5 +1,11 @@
1
1
  version: "3.3"
2
2
  services:
3
+ redis:
4
+ image: redis:6-alpine
5
+ ports:
6
+ - "6379:6379"
7
+ volumes:
8
+ - ./redis_data:/data
3
9
  db:
4
10
  image: postgres:12.2
5
11
  ports:
@@ -30,5 +36,17 @@ services:
30
36
  - .env
31
37
  depends_on:
32
38
  - db
39
+ sidekiq:
40
+ build: .
41
+ command: bash -c "exe/chatgpt_bot sidekiq"
42
+ volumes:
43
+ - .:/chatgpt_assistant
44
+ environment:
45
+ POSTGRES_HOST: db
46
+ env_file:
47
+ - .env
48
+ depends_on:
49
+ - db
50
+ - redis
33
51
  volumes:
34
52
  postgres:
data/exe/chatgpt_bot CHANGED
@@ -11,6 +11,9 @@ when "telegram"
11
11
  ChatgptAssistant::Main.new("telegram").start
12
12
  when "discord"
13
13
  ChatgptAssistant::Main.new("discord").start
14
+ when "sidekiq"
15
+ # start sidekiq with the lib/chatgpt_assistant/sidekiq.rb
16
+ system "bundle exec sidekiq -r ./lib/chatgpt_assistant/sidekiq.rb -C ./lib/chatgpt_assistant/sidekiq.yml"
14
17
  when "migrate"
15
18
  ChatgptAssistant::Config.new.migrate
16
19
  end
@@ -1,21 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # helpers
3
4
  require_relative "helpers/messenger_helper"
4
5
  require_relative "helpers/authentication_helper"
5
6
  require_relative "helpers/visit_helper"
6
7
  require_relative "helpers/audio_helper"
7
- require_relative "helpers/logger_action_helper"
8
8
  require_relative "helpers/search_helper"
9
9
  require_relative "helpers/validation_helper"
10
10
  require_relative "helpers/file_helper"
11
+
12
+ # jobs
13
+ require_relative "jobs/register_job"
14
+ require_relative "jobs/new_chat_job"
15
+ require_relative "jobs/voice_connect_job"
16
+
17
+ # services
18
+ require_relative "services/register_service"
19
+ require_relative "services/new_chat_service"
20
+ require_relative "services/voice_connect_service"
21
+
11
22
  module ChatgptAssistant
12
- # This class is responsible to contain the shared variables between the bot classes
23
+ # This class is responsible to contain the shared attributes and methods
13
24
  class ApplicationBot
14
25
  include MessengerHelper
15
26
  include AuthenticationHelper
16
27
  include VisitHelper
17
28
  include AudioHelper
18
- include LoggerActionHelper
19
29
  include SearchHelper
20
30
  include ValidationHelper
21
31
  include FileHelper
@@ -30,7 +40,7 @@ module ChatgptAssistant
30
40
  @discord_prefix = @config.discord_prefix
31
41
  @database = @config.db_connection
32
42
  @mode = @config.mode
33
- @commom_messages = default_msg.commom_messages
43
+ @common_messages = default_msg.common_messages
34
44
  @error_messages = default_msg.error_messages
35
45
  @success_messages = default_msg.success_messages
36
46
  @help_messages = default_msg.help_messages
@@ -38,7 +48,7 @@ module ChatgptAssistant
38
48
 
39
49
  attr_reader :openai_api_key, :telegram_token, :database, :default_msg,
40
50
  :mode, :config, :discord_token, :discord_client_id,
41
- :discord_prefix, :commom_messages, :error_messages, :success_messages,
51
+ :discord_prefix, :common_messages, :error_messages, :success_messages,
42
52
  :help_messages
43
53
  attr_accessor :msg, :evnt, :bot, :audio_url, :visitor, :user, :chat, :chat_id
44
54
 
@@ -16,9 +16,7 @@ module ChatgptAssistant
16
16
  new_chat_event
17
17
  sl_chat_event
18
18
  ask_event
19
- voice_connect_event
20
- disconnect_event
21
- speak_event
19
+ private_message_event
22
20
  bot_init
23
21
  end
24
22
 
@@ -35,6 +33,7 @@ module ChatgptAssistant
35
33
  @evnt = event
36
34
  @user = event.user
37
35
  start_action
36
+ "Ok"
38
37
  end
39
38
  end
40
39
 
@@ -42,7 +41,8 @@ module ChatgptAssistant
42
41
  bot.command :login do |event|
43
42
  @message = event.message.content.split[1]
44
43
  @evnt = event
45
- message.nil? ? event.respond(commom_messages[:login]) : login_action
44
+ message.nil? ? event.respond(common_messages[:login]) : login_action
45
+ "OK"
46
46
  end
47
47
  end
48
48
 
@@ -50,7 +50,8 @@ module ChatgptAssistant
50
50
  bot.command :register do |event|
51
51
  @message = event.message.content.split[1]
52
52
  @evnt = event
53
- message.nil? ? event.respond(commom_messages[:register]) : register_action
53
+ message.nil? ? event.respond(common_messages[:register]) : register_action
54
+ "OK"
54
55
  end
55
56
  end
56
57
 
@@ -58,20 +59,19 @@ module ChatgptAssistant
58
59
  bot.command :list do |event|
59
60
  @evnt = event
60
61
  @user = find_user(discord_id: event.user.id)
61
- event.respond error_messages[:user_not_logged_in] if user.nil?
62
- event.respond error_messages[:chat_not_found] if user.chats.empty? && user
63
- list_action if user && !user.chats.empty?
62
+ valid_for_list_action? ? list_action : ""
63
+ "OK"
64
64
  end
65
65
  end
66
66
 
67
67
  def hist_event
68
68
  bot.command :hist do |event|
69
69
  @evnt = event
70
- event.respond error_messages[:user_not_logged_in] if user.nil?
71
- title = event.message.content.split[1..].join(" ")
72
- @chat = user.chat_by_title(title)
70
+ @user = find_user(discord_id: event.user.id)
71
+ @chat = user.current_chat
73
72
  event.respond error_messages[:chat_not_found] if chat.nil? && user
74
73
  hist_action if user && chat
74
+ "OK"
75
75
  end
76
76
  end
77
77
 
@@ -79,6 +79,7 @@ module ChatgptAssistant
79
79
  bot.command :help do |event|
80
80
  @evnt = event
81
81
  help_action
82
+ "OK"
82
83
  end
83
84
  end
84
85
 
@@ -88,6 +89,7 @@ module ChatgptAssistant
88
89
  @user = find_user(discord_id: event.user.id)
89
90
  event.respond error_messages[:user_not_logged_in] if user.nil?
90
91
  create_chat_action if user
92
+ "OK"
91
93
  end
92
94
  end
93
95
 
@@ -99,6 +101,7 @@ module ChatgptAssistant
99
101
  event.respond error_messages[:user_not_logged_in] if user.nil?
100
102
 
101
103
  sl_chat_action(chat_to_select) if user
104
+ "OK"
102
105
  end
103
106
  end
104
107
 
@@ -109,6 +112,7 @@ module ChatgptAssistant
109
112
  @user = find_user(discord_id: event.user.id)
110
113
  event.respond error_messages[:user_not_logged_in] if user.nil?
111
114
  ask_action if user
115
+ "OK"
112
116
  end
113
117
  end
114
118
 
@@ -116,10 +120,17 @@ module ChatgptAssistant
116
120
  bot.command :connect do |event|
117
121
  @evnt = event
118
122
  @user = find_user(discord_id: event.user.id)
119
- @chat = Chat.where(id: user.current_chat_id).last
120
- voice_connect_checker_action
121
- voice_connection_checker_action
122
- discord_voice_bot_connect
123
+ if user&.current_chat_id.nil?
124
+ event.respond error_messages[:no_chat_selected]
125
+ elsif user&.current_chat_id
126
+ @chat = Chat.where(id: user.current_chat_id).last
127
+ voice_connect_checker_action
128
+ voice_connection_checker_action
129
+ VoiceConnectJob.perform_async(event.user.voice_channel.id)
130
+ else
131
+ event.respond error_messages[:user_not_logged_in]
132
+ end
133
+ "OK"
123
134
  end
124
135
  end
125
136
 
@@ -129,6 +140,7 @@ module ChatgptAssistant
129
140
  @user = find_user(discord_id: event.user.id)
130
141
  disconnect_checker_action
131
142
  disconnect_action if user && event.user.voice_channel && event.voice
143
+ "OK"
132
144
  end
133
145
  end
134
146
 
@@ -141,6 +153,21 @@ module ChatgptAssistant
141
153
  speak_connect_checker_action
142
154
  speak_connection_checker_action
143
155
  ask_to_speak_action if user && event.user.voice_channel && event.voice && !chat.nil?
156
+ "OK"
157
+ end
158
+ end
159
+
160
+ def private_message_event
161
+ bot.message do |event|
162
+ @evnt = event
163
+ @visitor = discord_visited?(@evnt.user.id)
164
+ next if discord_next_action?
165
+
166
+ @message = event.message.content
167
+ @user = find_user(discord_id: event.user.id)
168
+ @chat = user.current_chat if user
169
+ private_message_action if user && !chat.nil?
170
+ "OK"
144
171
  end
145
172
  end
146
173