chatgpt_assistant 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c2a41c81a5e742715d9b0710ff7c5866ba40d718931c3a6f0caa470613b23cd
4
- data.tar.gz: 73d6d84ccabd93c017b776083689f799f78e7b81355f02ca33a552fba601cf89
3
+ metadata.gz: 23b30dcd5724b3978f30a1ac8ebabce7c47b2013302282248a9a10e67904d631
4
+ data.tar.gz: a4cb01e4548897b34152a63ca600eb1b9fa72c3a2131dbb950b95cb998328cc2
5
5
  SHA512:
6
- metadata.gz: e55c21e292cc6bb2ee86bf86dca5ed881a02e834e30b5bf982f028dd0e34cf23c6c1978274873a04c50a845f157034cc1132050104d13899dce97d3c62e808cd
7
- data.tar.gz: ca83c1370beed7b168375ed3f8ecfd168950d0fde50c72a12784e2c28a58660c5838de0c969528bd8a47ddca11b1bc6a121c825f370a20165a09dda5fec0d59e
6
+ metadata.gz: 0f7d4daf964b6566c3a703b971090924b20d3d818b886533deae985eeac719860c40dfefef63983069f57cb991b4e02611e0f86f98fb7fdff9d288287f222513
7
+ data.tar.gz: 228a9a7799d596c5da4e53e0a9f8a505587f15f99af4928fef1824a88449a7e0febc64289406c29f2c67a038440fb19e054ccb2a389eec6831be041031af5bf6
data/.env_prod_sample CHANGED
@@ -3,7 +3,7 @@ LANGUAGE=en # or pt currently
3
3
  MODE=aws # or ibm
4
4
  DISCORD_PREFIX=gpt!
5
5
 
6
- POSTGRES_DB=telegram_chatgpt_development # or your database
6
+ POSTGRES_DB=chatgpt_assistant_production # or your database
7
7
  POSTGRES_USER=postgres # or your user
8
8
  POSTGRES_PASSWORD=postgres # or your password
9
9
 
data/.env_sample CHANGED
@@ -3,7 +3,7 @@ LANGUAGE=en # or pt currently
3
3
  MODE=aws # or ibm
4
4
  DISCORD_PREFIX=dgpt!
5
5
 
6
- POSTGRES_DB=telegram_chatgpt_development # or your database
6
+ POSTGRES_DB=chatgpt_assistant_development # or your database
7
7
  POSTGRES_USER=postgres # or your user
8
8
  POSTGRES_PASSWORD=postgres # or your password
9
9
 
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ NewCops: enable
3
4
 
4
5
  Style/StringLiterals:
5
6
  Enabled: true
@@ -12,15 +13,26 @@ Style/StringLiteralsInInterpolation:
12
13
  Layout/LineLength:
13
14
  Max: 160
14
15
 
15
- # remove code length limit
16
+ Metrics/ModuleLength:
17
+ Max: 120
18
+
16
19
  Metrics/MethodLength:
17
20
  Max: 200
18
21
 
19
- # Metrics/BlockLength:
20
- # Enabled: false
22
+ Metrics/BlockLength:
23
+ Max: 200
21
24
 
22
25
  Metrics/ClassLength:
23
- Enabled: false
26
+ Max: 300
24
27
 
25
28
  Metrics/AbcSize:
26
- Max: 40
29
+ Max: 35
30
+
31
+ Layout/AccessModifierIndentation:
32
+ EnforcedStyle: indent
33
+
34
+ Layout/IndentationWidth:
35
+ Width: 2
36
+
37
+ Layout/IndentationConsistency:
38
+ EnforcedStyle: indented_internal_methods
data/Dockerfile CHANGED
@@ -1,15 +1,12 @@
1
- FROM ruby:3.2.0
1
+ FROM ruby:3.2.2
2
2
  RUN apt-get update -qq && apt-get install -y nodejs postgresql-client ffmpeg
3
3
  WORKDIR /chatgpt_assistant
4
4
  COPY Gemfile /chatgpt_assistant/Gemfile
5
5
  COPY Gemfile.lock /chatgpt_assistant/Gemfile.lock
6
6
  RUN bundle install
7
7
 
8
- # Opus Installation for voice messages
9
-
10
8
  RUN apt-get install -y wget
11
9
  RUN wget https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
12
10
  RUN tar -xvf opus-1.3.1.tar.gz
13
11
  RUN cd opus-1.3.1 && ./configure && make && make install
14
- RUN rm -rf opus-1.3.1.tar.gz opus-1.3.1
15
-
12
+ RUN rm -rf opus-1.3.1.tar.gz opus-1.3.1
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ gem "simplecov", "~> 0.21", group: :test
12
12
 
13
13
  gem "vcr", "~> 6.0", group: :test
14
14
 
15
- gem "rubocop", "~> 1.21"
15
+ gem "rubocop", "~> 1.49"
16
16
 
17
17
  gem "rubocop-rspec", "~> 2.4"
18
18
 
data/Gemfile.lock CHANGED
@@ -167,7 +167,7 @@ GEM
167
167
  opus-ruby (1.0.1)
168
168
  ffi
169
169
  parallel (1.22.1)
170
- parser (3.2.1.0)
170
+ parser (3.2.2.0)
171
171
  ast (~> 2.4.1)
172
172
  pg (1.4.6)
173
173
  public_suffix (5.0.1)
@@ -207,24 +207,24 @@ GEM
207
207
  diff-lcs (>= 1.2.0, < 2.0)
208
208
  rspec-support (~> 3.12.0)
209
209
  rspec-support (3.12.0)
210
- rubocop (1.45.1)
210
+ rubocop (1.49.0)
211
211
  json (~> 2.3)
212
212
  parallel (~> 1.10)
213
213
  parser (>= 3.2.0.0)
214
214
  rainbow (>= 2.2.2, < 4.0)
215
215
  regexp_parser (>= 1.8, < 3.0)
216
216
  rexml (>= 3.2.5, < 4.0)
217
- rubocop-ast (>= 1.24.1, < 2.0)
217
+ rubocop-ast (>= 1.28.0, < 2.0)
218
218
  ruby-progressbar (~> 1.7)
219
219
  unicode-display_width (>= 2.4.0, < 3.0)
220
- rubocop-ast (1.26.0)
220
+ rubocop-ast (1.28.0)
221
221
  parser (>= 3.2.1.0)
222
222
  rubocop-capybara (2.17.1)
223
223
  rubocop (~> 1.41)
224
224
  rubocop-rspec (2.19.0)
225
225
  rubocop (~> 1.33)
226
226
  rubocop-capybara (~> 2.17)
227
- ruby-progressbar (1.11.0)
227
+ ruby-progressbar (1.13.0)
228
228
  ruby2_keywords (0.0.5)
229
229
  rufus-scheduler (3.8.2)
230
230
  fugit (~> 1.1, >= 1.1.6)
@@ -292,7 +292,7 @@ DEPENDENCIES
292
292
  rake (~> 13.0)
293
293
  redis
294
294
  rspec (~> 3.0)
295
- rubocop (~> 1.21)
295
+ rubocop (~> 1.49)
296
296
  rubocop-rspec (~> 2.4)
297
297
  sidekiq
298
298
  sidekiq-scheduler
data/SECURITY.md ADDED
@@ -0,0 +1,15 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | ------------------ |
7
+ | 0.1.4 | :white_check_mark: |
8
+ | 0.1.3 | :x: |
9
+ | 0.1.2 | :x: |
10
+ | 0.1.1 | :x: |
11
+ | 0.1.0 | :x: |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ You can open an security vulnerability issue
@@ -31,7 +31,7 @@ end
31
31
  end
32
32
 
33
33
  %w[deploy_and_build.sh deploy.sh].each do |file|
34
- `cp #{gem_dir}/bin/#{file} #{path}`
34
+ `cp #{gem_dir}/#{file} #{path}`
35
35
  end
36
36
 
37
37
  %w[/.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ /db_data /db_data/*
@@ -42,7 +42,7 @@ end
42
42
  `cd #{path} && git init`
43
43
 
44
44
  `mkdir -p #{path}/.github/workflows`
45
- `cp #{gem_dir}/.github/workflows/*.yml #{path}/.github/workflows`
45
+ `cp #{gem_dir}/workflows/*.yml #{path}/.github/workflows`
46
46
 
47
47
  puts "Done! Now you can run 'cd #{path} && bundle install'"
48
48
  puts "Build the docker image with 'rake compose:build'"
data/exe/chatgpt_bot CHANGED
@@ -5,7 +5,7 @@ require_relative "../lib/chatgpt_assistant"
5
5
 
6
6
  puts "Starting Chatgpt Assistant"
7
7
  puts "Bot Type: #{ARGV[0]}"
8
- puts "Mode: #{ENV["MODE"]}"
8
+ puts "Mode: #{ENV.fetch("MODE", nil)}"
9
9
  case ARGV[0]
10
10
  when "telegram"
11
11
  ChatgptAssistant::Main.new("telegram").start
@@ -1,8 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "helpers/messenger_helper"
4
+ require_relative "helpers/authentication_helper"
5
+ require_relative "helpers/visit_helper"
6
+ require_relative "helpers/audio_helper"
7
+ require_relative "helpers/logger_action_helper"
8
+ require_relative "helpers/search_helper"
9
+ require_relative "helpers/validation_helper"
10
+ require_relative "helpers/file_helper"
3
11
  module ChatgptAssistant
4
12
  # This class is responsible to contain the shared variables between the bot classes
5
13
  class ApplicationBot
14
+ include MessengerHelper
15
+ include AuthenticationHelper
16
+ include VisitHelper
17
+ include AudioHelper
18
+ include LoggerActionHelper
19
+ include SearchHelper
20
+ include ValidationHelper
21
+ include FileHelper
22
+
6
23
  def initialize(config)
7
24
  @config = config
8
25
  default_msg = DefaultMessages.new(@config.language)
@@ -19,100 +36,14 @@ module ChatgptAssistant
19
36
  @help_messages = default_msg.help_messages
20
37
  end
21
38
 
22
- def chatter
23
- @chatter ||= Chatter.new(openai_api_key)
24
- end
25
-
26
- def audio_recognition
27
- @audio_recognition ||= AudioRecognition.new(openai_api_key)
28
- end
29
-
30
- def audio_synthesis
31
- @audio_synthesis ||= AudioSynthesis.new(config)
32
- end
33
-
34
- def transcribed_text
35
- audio_recognition.transcribe_audio(audio_url)
36
- end
37
-
38
- def find_useremail(email)
39
- User.find_by(email: email)
40
- end
41
-
42
- def find_userdiscord(discord_id)
43
- User.find_by(discord_id: discord_id)
44
- end
45
-
46
- def find_usertelegram(telegram_id)
47
- User.find_by(telegram_id: telegram_id)
48
- end
49
-
50
- def valid_password?(user, password)
51
- return false if password.nil?
52
-
53
- salt = user.password_salt
54
- password_hash = user.password_hash
55
-
56
- BCrypt::Engine.hash_secret(password, salt) == password_hash
57
- end
58
-
59
- def auth_userdiscord(email, password, discord_id)
60
- user = find_useremail(email)
61
- return "user not found" unless user
62
- return "wrong password" if password.nil?
63
-
64
- valid_password?(user, password) ? user_disc_access(discord_id, user.email) : "wrong password"
65
- end
66
-
67
- def user_disc_access(discord_id, user_email)
68
- last_access = find_userdiscord(discord_id)
69
- new_access = find_useremail(user_email)
70
- last_acess.update(discord_id: nil) if last_access && (last_access != new_access)
71
- new_access.update(discord_id: discord_id)
72
- new_access
73
- end
74
-
75
- def discord_user_create(discord_id, email, password, name)
76
- user = User.new(discord_id: discord_id, email: email, password_hash: password, name: name)
77
- last_access = find_userdiscord(discord_id)
78
- last_access&.update(discord_id: nil)
79
- user.save
80
- end
81
-
82
- def auth_usertelegram(email, password, telegram_id)
83
- user = find_useremail(email)
84
- return "user not found" unless user
85
- return "wrong password" if password.nil?
86
-
87
- valid_password?(user, password) ? user_tele_access(telegram_id, user.email) : "wrong password"
88
- end
89
-
90
- def user_tele_access(telegram_id, user_email)
91
- last_access = find_usertelegram(telegram_id)
92
- new_access = find_useremail(user_email)
93
- last_acess.update(telegram_id: nil) if last_access && (last_access != new_access)
94
- new_access.update(telegram_id: telegram_id)
95
- new_access
96
- end
97
-
98
- def telegram_user_create(telegram_id, email, password, name)
99
- user = User.new(telegram_id: telegram_id, email: email, password_hash: password, name: name)
100
- last_access = find_usertelegram(telegram_id)
101
- last_access&.update(telegram_id: nil)
102
- user.save
103
- end
104
-
105
- def delete_all_voice_files
106
- Dir.glob("voice/*").each do |file|
107
- next if [".keep", "voice/.keep"].include?(file)
108
-
109
- File.delete(file)
110
- end
111
- end
112
-
113
39
  attr_reader :openai_api_key, :telegram_token, :database, :default_msg,
114
40
  :mode, :config, :discord_token, :discord_client_id,
115
41
  :discord_prefix, :commom_messages, :error_messages, :success_messages,
116
42
  :help_messages
43
+ attr_accessor :msg, :evnt, :bot, :audio_url, :visitor, :user, :chat, :chat_id
44
+
45
+ def chatter
46
+ @chatter ||= Chatter.new(openai_api_key)
47
+ end
117
48
  end
118
49
  end