chatgpt_assistant 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.env_sample +17 -8
  3. data/.rubocop.yml +17 -6
  4. data/Dockerfile +11 -5
  5. data/Gemfile +36 -22
  6. data/Gemfile.lock +143 -102
  7. data/README.md +25 -27
  8. data/Rakefile +1 -0
  9. data/docker-compose.yml +25 -3
  10. data/exe/chatgpt_assistant +1 -1
  11. data/exe/chatgpt_bot +3 -0
  12. data/lib/{bots → chatgpt_assistant/bots}/application_bot.rb +15 -11
  13. data/lib/chatgpt_assistant/bots/discord/actions.rb +104 -0
  14. data/lib/chatgpt_assistant/bots/discord/auth.rb +36 -0
  15. data/lib/chatgpt_assistant/bots/discord/bot.rb +29 -0
  16. data/lib/chatgpt_assistant/bots/discord/chat_actions.rb +33 -0
  17. data/lib/chatgpt_assistant/bots/discord/events.rb +138 -0
  18. data/lib/chatgpt_assistant/bots/discord/validations.rb +38 -0
  19. data/lib/chatgpt_assistant/bots/discord/voice_actions.rb +33 -0
  20. data/lib/chatgpt_assistant/bots/discord/voice_checkers.rb +35 -0
  21. data/lib/chatgpt_assistant/bots/discord_bot.rb +42 -0
  22. data/lib/chatgpt_assistant/bots/helpers/messenger_helper.rb +16 -0
  23. data/lib/{bots → chatgpt_assistant/bots}/helpers/search_helper.rb +3 -3
  24. data/lib/chatgpt_assistant/bots/jobs/new_chat_job.rb +17 -0
  25. data/lib/chatgpt_assistant/bots/jobs/register_job.rb +16 -0
  26. data/lib/chatgpt_assistant/bots/jobs/voice_connect_job.rb +14 -0
  27. data/lib/chatgpt_assistant/bots/mailers/account_mailer.rb +30 -0
  28. data/lib/chatgpt_assistant/bots/mailers/application_mailer.rb +21 -0
  29. data/lib/chatgpt_assistant/bots/services/new_chat_service.rb +59 -0
  30. data/lib/chatgpt_assistant/bots/services/register_service.rb +45 -0
  31. data/lib/chatgpt_assistant/bots/services/voice_connect_service.rb +29 -0
  32. data/lib/chatgpt_assistant/bots/telegram/actions.rb +54 -0
  33. data/lib/chatgpt_assistant/bots/telegram/auth.rb +40 -0
  34. data/lib/chatgpt_assistant/bots/telegram/bot.rb +17 -0
  35. data/lib/chatgpt_assistant/bots/telegram/chat_actions.rb +30 -0
  36. data/lib/chatgpt_assistant/bots/telegram/events.rb +120 -0
  37. data/lib/chatgpt_assistant/bots/telegram/events_controller.rb +48 -0
  38. data/lib/chatgpt_assistant/bots/telegram/permissions.rb +48 -0
  39. data/lib/chatgpt_assistant/bots/telegram/validations.rb +55 -0
  40. data/lib/chatgpt_assistant/bots/telegram/voice_actions.rb +36 -0
  41. data/lib/chatgpt_assistant/bots/telegram_bot.rb +44 -0
  42. data/lib/chatgpt_assistant/chatter.rb +10 -2
  43. data/lib/chatgpt_assistant/config.rb +27 -2
  44. data/lib/chatgpt_assistant/default_messages.rb +79 -31
  45. data/lib/chatgpt_assistant/error.rb +228 -0
  46. data/lib/chatgpt_assistant/migrations.rb +5 -0
  47. data/lib/chatgpt_assistant/models.rb +38 -13
  48. data/lib/chatgpt_assistant/sidekiq.rb +7 -0
  49. data/lib/chatgpt_assistant/sidekiq.yml +10 -0
  50. data/lib/chatgpt_assistant/version.rb +1 -1
  51. data/lib/chatgpt_assistant.rb +8 -15
  52. data/prompts-data/{awesome-chatgpt-prompts.csv → awesome-en-prompts.csv} +164 -164
  53. data/prompts-data/awesome-pt-prompts.csv +164 -0
  54. metadata +40 -21
  55. data/.env_prod_sample +0 -18
  56. data/docker-compose.prod.yml +0 -34
  57. data/lib/bots/discord_bot.rb +0 -185
  58. data/lib/bots/helpers/authentication_helper.rb +0 -47
  59. data/lib/bots/helpers/discord_helper.rb +0 -124
  60. data/lib/bots/helpers/discord_voice_helper.rb +0 -50
  61. data/lib/bots/helpers/logger_action_helper.rb +0 -7
  62. data/lib/bots/helpers/messenger_helper.rb +0 -134
  63. data/lib/bots/helpers/telegram_helper.rb +0 -77
  64. data/lib/bots/helpers/telegram_voice_helper.rb +0 -33
  65. data/lib/bots/helpers/validation_helper.rb +0 -38
  66. data/lib/bots/helpers/visit_helper.rb +0 -24
  67. data/lib/bots/telegram_bot.rb +0 -149
  68. /data/lib/{bots → chatgpt_assistant/bots}/helpers/audio_helper.rb +0 -0
  69. /data/lib/{bots → chatgpt_assistant/bots}/helpers/file_helper.rb +0 -0
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ChatgptAssistant
4
- # This module is responsible for the validation of the bot actions
5
- module ValidationHelper
6
- def valid_for_list_action?
7
- not_logged_in_message if user.nil?
8
- chat_not_found_message if user.chats.count.zero?
9
- !user.nil? && user.chats.count.positive?
10
- end
11
-
12
- def chat_if_exists
13
- chat = Chat.find_by(user_id: user.id, id: user.current_chat_id)
14
- chat ? chat_success(chat.id) : no_chat_selected_message
15
- end
16
-
17
- def visitor_user?
18
- visitor&.tel_user.nil? && visitor&.dis_user.nil?
19
- end
20
-
21
- def discord_voice_bot_disconnected?
22
- user && evnt.user.voice_channel && !evnt.voice && !chat.nil?
23
- end
24
-
25
- def discord_voice_bot_connected?
26
- user && evnt.user.voice_channel && evnt.voice && !chat.nil?
27
- end
28
-
29
- def discord_next_action?
30
- return true if evnt.channel.type != 1
31
-
32
- %w[login register start help new_chat sl_chat ask list hist connect disconnect speak].each do |action|
33
- return true if evnt.message.content.include?("#{discord_prefix}#{action}")
34
- end
35
- false
36
- end
37
- end
38
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ChatgptAssistant
4
- # Helper for visit
5
- module VisitHelper
6
- def telegram_visited?(chat_id)
7
- visitor = Visitor.find_by(telegram_id: chat_id, name: msg.from.first_name)
8
- if visitor.nil?
9
- Visitor.create(telegram_id: chat_id, name: msg.from.first_name)
10
- else
11
- visitor
12
- end
13
- end
14
-
15
- def discord_visited?(user_id)
16
- visitor = Visitor.find_by(discord_id: user_id, name: evnt.user.name)
17
- if visitor.nil?
18
- Visitor.create(discord_id: user_id, name: evnt.user.name)
19
- else
20
- visitor
21
- end
22
- end
23
- end
24
- end
@@ -1,149 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "helpers/telegram_helper"
4
- require_relative "helpers/telegram_voice_helper"
5
-
6
- module ChatgptAssistant
7
- # This class is responsible for the telegram bot features
8
- class TelegramBot < ApplicationBot
9
- def start
10
- bot.listen do |message|
11
- next if message.chat.type != "private" # disable group and channel messages, we will enable it later
12
-
13
- @msg = message
14
- @visitor = telegram_visited?(@msg.chat.id)
15
- next unless telegram_text_or_audio?
16
-
17
- text_events if telegram_message_has_text?
18
- audio_event if telegram_message_has_audio?
19
- end
20
- rescue StandardError => e
21
- Error.create(message: e.message, backtrace: e.backtrace)
22
- retry
23
- end
24
-
25
- private
26
-
27
- include TelegramHelper
28
- include TelegramVoiceHelper
29
-
30
- attr_accessor :msg, :visitor, :chat, :chat_id
31
-
32
- def text_events
33
- case msg.text
34
- when "/start"
35
- start_event
36
- when "/help"
37
- help_event
38
- when "/hist"
39
- hist_event
40
- when "/list"
41
- list_event
42
- when "/stop"
43
- stop_event
44
- when nil
45
- nil_event
46
- else
47
- action_events
48
- end
49
- end
50
-
51
- def start_event
52
- telegram_send_start_message
53
- end
54
-
55
- def help_event
56
- help_messages.each { |m| send_message m, msg.chat.id }
57
- end
58
-
59
- def hist_event
60
- return not_logged_in_message unless user
61
- return no_chat_selected_message unless user.current_chat
62
- return no_messages_founded_message if user.current_chat.messages.count.zero?
63
-
64
- telegram_user_history.each do |m|
65
- send_message m, msg.chat.id
66
- end
67
- end
68
-
69
- def list_event
70
- return unless valid_for_list_action?
71
-
72
- send_message commom_messages[:chat_list], msg.chat.id
73
- chats_str = ""
74
- user.chats.each_with_index { |c, i| chats_str += "Chat #{i + 1} - #{c.title}\n" }
75
- send_message chats_str, msg.chat.id
76
- end
77
-
78
- def action_events
79
- return login_event if msg.text.include?("login/")
80
- return register_event if msg.text.include?("register/")
81
- return new_chat_event if msg.text.include?("new_chat/")
82
- return select_chat_event if msg.text.include?("sl_chat/")
83
- return telegram_chat_event unless telegram_actions?
84
-
85
- invalid_command_error_message
86
- end
87
-
88
- def login_event
89
- user_info = msg.text.split("/").last
90
- email, password = user_info.split(":")
91
- case telegram_user_auth(email, password, msg.chat.id)
92
- when "user not found"
93
- user_not_found_error_message
94
- when "wrong password"
95
- wrong_password_error_message
96
- when email
97
- user_logged_in_message
98
- end
99
- end
100
-
101
- def register_event
102
- user_info = msg.text.split("/").last
103
- email, password = user_info.split(":")
104
- registered_email = telegram_user_create visitor.id, email, password
105
- registered_email == email ? user_created_message : user_creation_error_message
106
- end
107
-
108
- def new_chat_event
109
- return not_logged_in_message unless user
110
-
111
- telegram_create_chat
112
- end
113
-
114
- def select_chat_event
115
- return not_logged_in_message unless user
116
-
117
- title = msg.text.split("/").last
118
- chat = user.chat_by_title(title)
119
- return chat_not_found_message unless chat
120
-
121
- user.update(current_chat_id: chat.id)
122
- send_message success_messages[:chat_selected], msg.chat.id
123
- end
124
-
125
- def stop_event
126
- send_message commom_messages[:stop], msg.chat.id
127
- bot.api.leave_chat(chat_id: msg.chat.id)
128
- end
129
-
130
- def nil_event
131
- send_message error_messages[:nil], msg.chat.id
132
- end
133
-
134
- def audio_event
135
- return not_logged_in_message unless user
136
- return no_chat_selected_message if user.current_chat_id.nil?
137
-
138
- user_audio = transcribe_file(telegram_audio_url)
139
- message = Message.new(content: user_audio[:text], chat_id: user.current_chat_id, role: "user")
140
- if message.save
141
- ai_response = telegram_process_ai_voice(user_audio[:file])
142
- telegram_send_voice_message(voice: ai_response[:voice], text: ai_response[:text])
143
- delete_file ai_response[:voice]
144
- else
145
- send_message error_messages[:message_creation_error], msg.chat.id
146
- end
147
- end
148
- end
149
- end