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
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChatgptAssistant
4
+ module Bots
5
+ module Telegram
6
+ module Permissions
7
+ def hist_allowed?
8
+ raise UserNotLoggedInError if user.nil?
9
+ raise AccountNotVerifiedError unless user.active?
10
+ raise NoChatSelectedError if user.current_chat.nil?
11
+ raise NoMessagesFoundedError if user.current_chat.messages.count.zero?
12
+ end
13
+
14
+ def list_allowed?
15
+ raise UserNotLoggedInError if user.nil?
16
+ raise AccountNotVerifiedError unless user.active?
17
+ raise NoChatsFoundedError if user.chats.count.zero?
18
+ end
19
+
20
+ def register_allowed?(user_info)
21
+ raise NoRegisterInfoError if user_info.nil?
22
+ raise UserLoggedInError if user
23
+
24
+ email, password = user_info.split(":")
25
+ raise NoRegisterEmailError if email.nil? || password.nil?
26
+
27
+ [email, password]
28
+ end
29
+
30
+ def common_allowed?
31
+ raise UserNotLoggedInError if user.nil?
32
+ raise AccountNotVerifiedError unless user.active?
33
+ end
34
+
35
+ def select_allowed?(chat)
36
+ raise ChatNotFoundError if chat.nil?
37
+ raise ChatNotFoundError unless user.update(current_chat_id: chat.id)
38
+ end
39
+
40
+ def audio_allowed?
41
+ raise UserNotLoggedInError if user.nil?
42
+ raise AccountNotVerifiedError unless user.active?
43
+ raise NoChatSelectedError if user.current_chat.nil?
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChatgptAssistant
4
+ module Bots
5
+ module Telegram
6
+ module Validations
7
+ def telegram_actions?
8
+ msg.text.include?("new_chat/") || msg.text.include?("sl_chat/") || msg.text.include?("login/") || msg.text.include?("register/")
9
+ end
10
+
11
+ def telegram_text_or_audio?
12
+ msg.respond_to?(:text) || msg.respond_to?(:audio) || msg.respond_to?(:voice)
13
+ end
14
+
15
+ def telegram_message_has_text?
16
+ msg.text.present?
17
+ end
18
+
19
+ def telegram_message_has_audio?
20
+ msg.audio.present? || msg.voice.present?
21
+ end
22
+
23
+ def telegram_visited?(chat_id)
24
+ return unless msg
25
+
26
+ visitor = Visitor.find_by(telegram_id: chat_id, name: msg.from.first_name)
27
+ if visitor.nil?
28
+ Visitor.create(telegram_id: chat_id, name: msg.from.first_name)
29
+ else
30
+ visitor
31
+ end
32
+ end
33
+
34
+ def visitor_user?
35
+ visitor&.tel_user.nil?
36
+ end
37
+
38
+ def valid_for_list_action?
39
+ send_message(chat_id: msg.chat.id, text: error_messages[:user_not_logged_in]) if user.nil?
40
+ send_message(chat_id: msg.chat.id, text: error_messages[:account_not_verified]) unless user.active?
41
+ send_message(chat_id: msg.chat.id, text: error_messages[:chat_not_found]) if user.chats.count.zero? && user.active?
42
+ !user.nil? && user.active? && user.chats.count.positive?
43
+ end
44
+
45
+ def auth_event?
46
+ msg.text.include?("login/") || msg.text.include?("register/") || msg.text.include?("sign_out/") || msg.text.include?("confirm/* ")
47
+ end
48
+
49
+ def user_confirmed?
50
+ user.name == name && user.confirm_account(token)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChatgptAssistant
4
+ module Bots
5
+ module Telegram
6
+ module VoiceActions
7
+ def telegram_audio_info
8
+ bot.api.get_file(file_id: telegram_audio.file_id)
9
+ end
10
+
11
+ def telegram_audio_url
12
+ "https://api.telegram.org/file/bot#{telegram_token}/#{telegram_audio_info["result"]["file_path"]}"
13
+ end
14
+
15
+ def telegram_audio
16
+ msg.audio || msg.voice
17
+ end
18
+
19
+ def telegram_process_ai_voice(user_audio)
20
+ ai_text = chatter.chat(user_audio["text"], user.current_chat_id, error_messages[:something_went_wrong])
21
+ ai_voice = synthesis.synthesize_text(ai_text)
22
+ {
23
+ voice: ai_voice,
24
+ text: ai_text
25
+ }
26
+ end
27
+
28
+ def telegram_send_voice_message(voice: nil, text: nil)
29
+ messages = parse_message text, 4096
30
+ bot.api.send_voice(chat_id: msg.chat.id, voice: Faraday::UploadIO.new(voice, "audio/mp3"))
31
+ messages.each { |message| send_message message, msg.chat.id }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "telegram/bot"
4
+ require_relative "telegram/auth"
5
+ require_relative "telegram/actions"
6
+ require_relative "telegram/events"
7
+ require_relative "telegram/chat_actions"
8
+ require_relative "telegram/validations"
9
+ require_relative "telegram/voice_actions"
10
+ require_relative "telegram/permissions"
11
+ require_relative "telegram/events_controller"
12
+
13
+ module ChatgptAssistant
14
+ # This class is responsible for the telegram bot features
15
+ class TelegramBot < ApplicationBot
16
+ def start
17
+ bot.listen do |message|
18
+ @msg = message
19
+ @visitor = telegram_visited?(@msg.chat.id)
20
+ next unless telegram_text_or_audio?
21
+
22
+ text_events if telegram_message_has_text?
23
+ audio_event if telegram_message_has_audio?
24
+ end
25
+ rescue StandardError => e
26
+ Error.create(message: e.message, backtrace: e.backtrace)
27
+ retry
28
+ end
29
+
30
+ private
31
+
32
+ attr_accessor :msg, :visitor, :chat, :chat_id
33
+
34
+ include Bots::Telegram::Bot
35
+ include Bots::Telegram::Auth
36
+ include Bots::Telegram::Actions
37
+ include Bots::Telegram::Events
38
+ include Bots::Telegram::ChatActions
39
+ include Bots::Telegram::Validations
40
+ include Bots::Telegram::VoiceActions
41
+ include Bots::Telegram::Permissions
42
+ include Bots::Telegram::EventsController
43
+ end
44
+ end
@@ -17,7 +17,7 @@ module ChatgptAssistant
17
17
  @response = request(message)
18
18
  @json = JSON.parse(response.body)
19
19
 
20
- return no_response_error if json["choices"].empty?
20
+ return no_response_error if json["choices"] && json["choices"].empty?
21
21
  return bot_offline_error if response.status != 200
22
22
 
23
23
  text = json["choices"][0]["message"]["content"]
@@ -57,7 +57,8 @@ module ChatgptAssistant
57
57
  end
58
58
 
59
59
  def request_params(message)
60
- messages = Message.where(chat_id: chat_id).order(id: :asc).last(10)
60
+ messages_from_chat = Message.where(chat_id: chat_id)
61
+ messages = messages_from_chat.order(id: :asc).last(10)
61
62
  messages = if messages.empty?
62
63
  [{ role: "user", content: message }]
63
64
  else
@@ -66,6 +67,13 @@ module ChatgptAssistant
66
67
  content: mess.content }
67
68
  end
68
69
  end
70
+
71
+ first_message = messages_from_chat.order(id: :asc).first
72
+ system_message = first_message if first_message&.role == "system"
73
+ if system_message && Message.where(chat_id: chat_id).count > 10
74
+ messages.unshift({ role: system_message.role,
75
+ content: system_message.content })
76
+ end
69
77
  {
70
78
  model: "gpt-3.5-turbo",
71
79
  messages: messages,
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "active_record"
4
4
  require "active_model"
5
+ require "action_mailer"
5
6
  require_relative "migrations"
6
7
  require "fileutils"
7
8
 
@@ -30,7 +31,9 @@ module ChatgptAssistant
30
31
 
31
32
  attr_reader :openai_api_key, :telegram_token, :discord_token, :ibm_api_key, :ibm_url,
32
33
  :aws_access_key_id, :aws_secret_access_key, :aws_region, :mode, :language,
33
- :discord_client_id, :discord_public_key, :env_type, :discord_prefix
34
+ :discord_client_id, :discord_public_key, :env_type, :discord_prefix,
35
+ :smtp_address, :smtp_port, :smtp_domain, :smtp_user_name, :smtp_password,
36
+ :smtp_authentication, :smtp_enable_starttls_auto
34
37
 
35
38
  def db_connection
36
39
  ActiveRecord::Base.establish_connection(
@@ -44,9 +47,25 @@ module ChatgptAssistant
44
47
  ActiveRecord::Base.logger = Logger.new($stdout) if ENV["ENV_TYPE"] == "development"
45
48
  end
46
49
 
50
+ def create_db
51
+ db_connection
52
+ return if database_exists?
53
+
54
+ ActiveRecord::Base.establish_connection(
55
+ adapter: "postgresql",
56
+ host: database_host,
57
+ port: 5432,
58
+ database: "postgres",
59
+ username: database_username,
60
+ password: database_password
61
+ )
62
+ ActiveRecord::Base.logger = Logger.new($stdout) if ENV["ENV_TYPE"] == "development"
63
+ ActiveRecord::Base.connection.create_database(database_name)
64
+ end
65
+
47
66
  def migrate
48
67
  db_connection
49
- ActiveRecord::Base.logger = Logger.new($stdout)
68
+ ActiveRecord::Base.logger = Logger.new($stdout) if ENV["ENV_TYPE"] == "development"
50
69
  VisitorMigration.new.migrate(:up)
51
70
  UserMigration.new.migrate(:up)
52
71
  ChatMigration.new.migrate(:up)
@@ -57,5 +76,11 @@ module ChatgptAssistant
57
76
  private
58
77
 
59
78
  attr_reader :database_host, :database_name, :database_username, :database_password
79
+
80
+ def database_exists?
81
+ ActiveRecord::Base.connection
82
+ rescue ActiveRecord::NoDatabaseError
83
+ false
84
+ end
60
85
  end
61
86
  end
@@ -3,15 +3,15 @@
3
3
  module ChatgptAssistant
4
4
  # This class is responsible for storing the default messages
5
5
  class DefaultMessages
6
- def initialize(language = "en")
6
+ def initialize(language = "en", _discord_prefix = "!")
7
7
  @language = language
8
8
  load_message_context
9
9
  end
10
10
 
11
- attr_reader :language, :commom_messages, :success_messages, :error_messages, :help_messages
11
+ attr_reader :language, :common_messages, :success_messages, :error_messages, :help_messages
12
12
 
13
13
  def load_message_context
14
- @commom_messages = send("commom_messages_#{language}")
14
+ @common_messages = send("common_messages_#{language}")
15
15
  @success_messages = send("success_messages_#{language}")
16
16
  @error_messages = send("error_messages_#{language}")
17
17
  @help_messages = send("help_messages_#{language}")
@@ -19,7 +19,7 @@ module ChatgptAssistant
19
19
 
20
20
  private
21
21
 
22
- def commom_messages_pt
22
+ def common_messages_pt
23
23
  {
24
24
  start: "Olá, eu sou o Chatgpt Assistant, um chatbot que usa a API da OpenAI para responder suas perguntas no Telegram e Discord.",
25
25
  stop: "Até mais!",
@@ -42,33 +42,45 @@ module ChatgptAssistant
42
42
  chat_created: "Chat criado com sucesso!",
43
43
  chat_selected: "Chat selecionado com sucesso!",
44
44
  user_logged_in: "Login realizado com sucesso!",
45
- voice_channel_connected: "O bot entrou no canal de voz com sucesso!"
45
+ user_logged_out: "Logout realizado com sucesso!",
46
+ voice_channel_connected: "O bot entrou no canal de voz com sucesso!",
47
+ account_confirmed: "Conta confirmada com sucesso!"
46
48
  }
47
49
  end
48
50
 
49
51
  def error_messages_pt
50
52
  {
51
53
  nil: "Não entendi o que você disse. Tente novamente",
52
- email: "O email que você digitou não é válido. Tente novamente",
53
- password: "A senha que você digitou não é válida. Tente novamente",
54
+ wrong_email: "O email que você digitou não é válido. Tente novamente",
54
55
  wrong_password: "A senha que você digitou não é válida. Tente novamente",
55
- user: "O usuário que você digitou não existe. Tente novamente",
56
- user_creation: "Erro ao criar usuário. Tente novamente",
56
+
57
57
  user_already_exists: "O usuário que você digitou já existe. Tente novamente",
58
- chat_creation: "Erro ao criar chat. Tente novamente",
59
- no_messages_founded: "Nenhuma mensagem encontrada",
58
+ chat_already_exists: "Você possui um chat com este titulo. Tente novamente",
59
+
60
+ no_register_info: "Você não digitou o email e a senha. Tente novamente",
61
+ sign_up_error: "Erro ao criar usuário. Tente novamente",
62
+ chat_not_created_error: "Erro ao criar chat. Tente novamente",
63
+ message_not_created_error: "Erro ao criar mensagem. Tente novamente",
60
64
  no_chat_selected: "Nenhum chat selecionado",
61
- chat_not_found: "Chat não encontrado",
65
+
66
+ no_messages_founded: "Nenhuma mensagem encontrada",
62
67
  no_chats_founded: "Nenhum chat encontrado",
68
+ chat_not_found: "Chat não encontrado",
69
+ user_not_found: "O usuário que você digitou não existe. Tente novamente",
70
+ user_not_registered: "O usuário não está registrado no sistema",
71
+ user_logged_in: "Usuário está logado no sistema, faça logout para continuar",
63
72
  user_not_logged_in: "Usuário não logado",
64
- user_not_found: "Usuário não encontrado",
65
- something_went_wrong: "Algo deu errado. Tente novamente mais tarde.",
66
- message_history_too_long: "O histórico mensagem é muito longo.",
67
- text_length: "O texto de resposta é muito longo. Tente diminuir a quantidade de respostas na mesma mensagem.",
73
+
68
74
  user_not_in_voice_channel: "Você não está em um canal de voz.",
69
75
  bot_not_in_voice_channel: "O bot não está em um canal de voz.",
76
+
77
+ message_history_too_long: "O histórico mensagem é muito longo.",
78
+ text_length_too_long: "O texto de resposta é muito longo. Tente diminuir a quantidade de respostas na mesma mensagem.",
79
+
70
80
  invalid_command: "Comando inválido. Tente novamente.",
71
- message_creation_error: "Erro ao criar mensagem. Tente novamente."
81
+ something_went_wrong: "Algo deu errado. Tente novamente mais tarde.",
82
+ account_not_verified: "Sua conta não foi verificada. Verifique sua caixa de email.",
83
+ account_not_confirmed: "Sua conta não foi confirmada. Verifique sua caixa de email."
72
84
  }
73
85
  end
74
86
 
@@ -83,7 +95,18 @@ module ChatgptAssistant
83
95
  "Para ver esta mensagem novamente, digite /help"]
84
96
  end
85
97
 
86
- def commom_messages_en
98
+ def help_message_discord_pt
99
+ ["Para começar a conversar comigo, digite #{discord_prefix}start",
100
+ "Para parar de conversar comigo, digite #{discord_prefix}stop",
101
+ "Para se registrar no sistema, digite #{discord_prefix}register email:senha (a senha deve ser um numero de 4 digitos ex: 1234)",
102
+ "Para fazer login no sistema, digite #{discord_prefix}login email:senha (a senha deve ser um numero de 4 digitos ex: 1234)",
103
+ "Para criar um novo chat, digite #{discord_prefix}new_chat nome do chat",
104
+ "Para selecionar um chat, digite #{discord_prefix}sl_chat nome do chat",
105
+ "Para listar os chats que você criou, digite #{discord_prefix}list",
106
+ "Para ver esta mensagem novamente, digite #{discord_prefix}help"]
107
+ end
108
+
109
+ def common_messages_en
87
110
  {
88
111
  start: "Hello, I'm the Chatgpt Assistant, a chatbot that uses the OpenAI API to answer your questions on Telegram and Discord.",
89
112
  stop: "See you later!",
@@ -105,32 +128,46 @@ module ChatgptAssistant
105
128
  user_created: "User created successfully!",
106
129
  chat_created: "Chat created successfully!",
107
130
  chat_selected: "Chat selected successfully!",
108
- user_logged_in: "Login successfully!"
131
+ user_logged_in: "Login successfully!",
132
+ user_logged_out: "Logout successfully!",
133
+ voice_channel_connected: "The bot entered the voice channel successfully!",
134
+ account_confirmed: "Your account has been verified!"
109
135
  }
110
136
  end
111
137
 
112
138
  def error_messages_en
113
139
  {
114
- nil: "I didn't understand what you said. Try again",
115
- email: "The email you typed is not valid. Try again",
116
- password: "The password you typed is not valid. Try again",
140
+ nil: "I don't understand what you said. Try again",
141
+ wrong_email: "The email you typed is not valid. Try again",
117
142
  wrong_password: "The password you typed is not valid. Try again",
118
- user: "The user you typed does not exist. Try again",
119
- user_creation: "Error creating user. Try again",
120
- chat_creation: "Error creating chat. Try again",
121
- no_messages_founded: "No messages found",
143
+
144
+ user_already_exists: "The user you typed already exists. Try again",
145
+ chat_already_exists: "You already have a chat with this title. Try again",
146
+
147
+ no_register_info: "You did not type the email and password. Try again",
148
+ sign_up_error: "Error creating user. Try again",
149
+ chat_not_created_error: "Error creating chat. Try again",
150
+ message_not_created_error: "Error creating message. Try again",
122
151
  no_chat_selected: "No chat selected",
152
+
153
+ no_messages_founded: "No messages found",
123
154
  no_chats_founded: "No chats found",
124
155
  chat_not_found: "Chat not found",
156
+ user_not_found: "The user you typed does not exist. Try again",
157
+ user_not_registered: "The user is not registered in the system",
158
+ user_logged_in: "User is logged in the system, do logout to continue",
125
159
  user_not_logged_in: "User not logged in",
126
- user_not_found: "User not found",
127
- something_went_wrong: "Something went wrong. Try again later.",
128
- message_history_too_long: "The message history is too long.",
129
- text_length: "The response text is too long. Try to reduce the number of answers in the same message.",
160
+
130
161
  user_not_in_voice_channel: "You are not in a voice channel.",
131
162
  bot_not_in_voice_channel: "The bot is not in a voice channel.",
163
+
164
+ message_history_too_long: "The message history is too long.",
165
+ text_length_too_long: "The response text is too long. Try to reduce the number of responses in the same message.",
166
+
132
167
  invalid_command: "Invalid command. Try again.",
133
- message_creation_error: "Error creating message. Try again."
168
+ something_went_wrong: "Something went wrong. Try again later.",
169
+ account_not_verified: "Your account is not verified. Please check your email and verify your account.",
170
+ account_not_confirmed: "Something went wrong. Please check your email and verify your account. Maybe you pass the wrong code."
134
171
  }
135
172
  end
136
173
 
@@ -144,5 +181,16 @@ module ChatgptAssistant
144
181
  "To list the chats you created, type /list",
145
182
  "To see this message again, type /help"]
146
183
  end
184
+
185
+ def help_message_discord_en
186
+ ["To start talking to me, type #{discord_prefix}start",
187
+ "To stop talking to me, type #{discord_prefix}stop",
188
+ "To register in the system, type #{discord_prefix}register email:password (the password must be a 4 digit number ex: 1234)",
189
+ "To log in to the system, type #{discord_prefix}login email:password (the password must be a 4 digit number ex: 1234)",
190
+ "To create a new chat, type #{discord_prefix}new_chat chat name",
191
+ "To select a chat, type #{discord_prefix}sl_chat chat name",
192
+ "To list the chats you created, type #{discord_prefix}list",
193
+ "To see this message again, type #{discord_prefix}help"]
194
+ end
147
195
  end
148
196
  end
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChatgptAssistant
4
+ # Load Error
5
+ module LoadError
6
+ def load_error_context
7
+ language = ENV.fetch("LANGUAGE", "en")
8
+ discord_prefix = ENV.fetch("DISCORD_PREFIX", "!")
9
+ DefaultMessages.new(language, discord_prefix).error_messages
10
+ end
11
+ end
12
+
13
+ # No User Error
14
+ class NoRegisterInfoError < StandardError
15
+ def initialize(message = load_error_context[:no_register_info])
16
+ super(message)
17
+ end
18
+
19
+ include LoadError
20
+ end
21
+
22
+ # Nil Command Error
23
+ class NilError < StandardError
24
+ def initialize(message = load_error_context[:nil])
25
+ super(message)
26
+ end
27
+
28
+ include LoadError
29
+ end
30
+
31
+ # Wrong Email Error
32
+ class WrongEmailError < StandardError
33
+ def initialize(message = load_error_context[:wrong_email])
34
+ super(message)
35
+ end
36
+
37
+ include LoadError
38
+ end
39
+
40
+ # Wrong Password Error
41
+ class WrongPasswordError < StandardError
42
+ def initialize(message = load_error_context[:wrong_password])
43
+ super(message)
44
+ end
45
+
46
+ include LoadError
47
+ end
48
+
49
+ # User Already Exists Error
50
+ class UserAlreadyExistsError < StandardError
51
+ def initialize(message = load_error_context[:user_already_exists])
52
+ super(message)
53
+ end
54
+
55
+ include LoadError
56
+ end
57
+
58
+ # Chat Already Exists Error
59
+ class ChatAlreadyExistsError < StandardError
60
+ def initialize(message = load_error_context[:chat_already_exists])
61
+ super(message)
62
+ end
63
+
64
+ include LoadError
65
+ end
66
+
67
+ # Sign Up Error
68
+ class SignUpError < StandardError
69
+ def initialize(message = load_error_context[:sign_up_error])
70
+ super(message)
71
+ end
72
+
73
+ include LoadError
74
+ end
75
+
76
+ # Chat Not Created Error
77
+ class ChatNotCreatedError < StandardError
78
+ def initialize(message = load_error_context[:chat_not_created_error])
79
+ super(message)
80
+ end
81
+
82
+ include LoadError
83
+ end
84
+
85
+ # Message Not Created Error
86
+ class MessageNotCreatedError < StandardError
87
+ def initialize(message = load_error_context[:message_not_created_error])
88
+ super(message)
89
+ end
90
+
91
+ include LoadError
92
+ end
93
+
94
+ # No Chat Selected Error
95
+ class NoChatSelectedError < StandardError
96
+ def initialize(message = load_error_context[:no_chat_selected])
97
+ super(message)
98
+ end
99
+
100
+ include LoadError
101
+ end
102
+
103
+ # No Messages Founded Error
104
+ class NoMessagesFoundedError < StandardError
105
+ def initialize(message = load_error_context[:no_messages_founded])
106
+ super(message)
107
+ end
108
+
109
+ include LoadError
110
+ end
111
+
112
+ # No Chats Founded Error
113
+ class NoChatsFoundedError < StandardError
114
+ def initialize(message = load_error_context[:no_chats_founded])
115
+ super(message)
116
+ end
117
+
118
+ include LoadError
119
+ end
120
+
121
+ # Chat Not Found Error
122
+ class ChatNotFoundError < StandardError
123
+ def initialize(message = load_error_context[:chat_not_found])
124
+ super(message)
125
+ end
126
+
127
+ include LoadError
128
+ end
129
+
130
+ # User Not Found Error
131
+ class UserNotFoundError < StandardError
132
+ def initialize(message = load_error_context[:user_not_found])
133
+ super(message)
134
+ end
135
+
136
+ include LoadError
137
+ end
138
+
139
+ # User Not Registered Error
140
+ class UserNotRegisteredError < StandardError
141
+ def initialize(message = load_error_context[:user_not_registered])
142
+ super(message)
143
+ end
144
+
145
+ include LoadError
146
+ end
147
+
148
+ # User Logged In Error
149
+ class UserLoggedInError < StandardError
150
+ def initialize(message = load_error_context[:user_logged_in])
151
+ super(message)
152
+ end
153
+
154
+ include LoadError
155
+ end
156
+
157
+ # User Not Logged In Error
158
+ class UserNotLoggedInError < StandardError
159
+ def initialize(message = load_error_context[:user_not_logged_in])
160
+ super(message)
161
+ end
162
+
163
+ include LoadError
164
+ end
165
+
166
+ # User Not In Voice Channel Error
167
+ class UserNotInVoiceChannelError < StandardError
168
+ def initialize(message = load_error_context[:user_not_in_voice_channel])
169
+ super(message)
170
+ end
171
+
172
+ include LoadError
173
+ end
174
+
175
+ # Bot Not In Voice Channel Error
176
+ class BotNotInVoiceChannelError < StandardError
177
+ def initialize(message = load_error_context[:bot_not_in_voice_channel])
178
+ super(message)
179
+ end
180
+
181
+ include LoadError
182
+ end
183
+
184
+ # Message Not Found Error
185
+ class MessageHistoryTooLongError < StandardError
186
+ def initialize(message = load_error_context[:message_history_too_long])
187
+ super(message)
188
+ end
189
+
190
+ include LoadError
191
+ end
192
+
193
+ # Text Length Too Long Error
194
+ class TextLengthTooLongError < StandardError
195
+ def initialize(message = load_error_context[:text_length_too_long])
196
+ super(message)
197
+ end
198
+
199
+ include LoadError
200
+ end
201
+
202
+ # Invalid Command Error
203
+ class InvalidCommandError < StandardError
204
+ def initialize(message = load_error_context[:invalid_command])
205
+ super(message)
206
+ end
207
+
208
+ include LoadError
209
+ end
210
+
211
+ # Account Not Verified Error
212
+ class AccountNotVerifiedError < StandardError
213
+ def initialize(message = load_error_context[:account_not_verified])
214
+ super(message)
215
+ end
216
+
217
+ include LoadError
218
+ end
219
+
220
+ # Something Went Wrong Error
221
+ class SomethingWentWrongError < StandardError
222
+ def initialize(message = load_error_context[:something_went_wrong])
223
+ super(message)
224
+ end
225
+
226
+ include LoadError
227
+ end
228
+ end