diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 085f555..4540928 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -122,7 +122,7 @@ en: remaining_bot_quota: description: | Get the current number of tokens or queries you have left for use of the bot this week - answer: "The user has %{quota} bot %{units} left for use this week.\n\n" + answer: "The user has %{quota} bot %{units} left for use this week. There are %{days_remaining} before it resets!\n\n" error: "There was an error when trying to retrieve your remaining bot quota: '%{error}'" user_information: name: "user_information_for_%{user_field}" diff --git a/lib/discourse_chatbot/functions/remaining_bot_quota_function.rb b/lib/discourse_chatbot/functions/remaining_bot_quota_function.rb index e234edf..5a0a2a5 100644 --- a/lib/discourse_chatbot/functions/remaining_bot_quota_function.rb +++ b/lib/discourse_chatbot/functions/remaining_bot_quota_function.rb @@ -4,6 +4,7 @@ module DiscourseChatbot class RemainingBotTokenQuotaFunction < Function + QUOTA_RESET_JOB = "Jobs::ChatbotQuotaReset" def name 'remaining_bot_quota' @@ -29,8 +30,11 @@ def process(args, opts) remaining_quota_field_name = SiteSetting.chatbot_quota_basis == "queries" ? CHATBOT_REMAINING_QUOTA_QUERIES_CUSTOM_FIELD : CHATBOT_REMAINING_QUOTA_TOKENS_CUSTOM_FIELD remaining_quota = ::DiscourseChatbot::EventEvaluation.new.get_remaining_quota(user_id, remaining_quota_field_name) + reset_job = MiniScheduler::Manager.discover_schedules.find {|job| job.schedule_info.instance_variable_get(:@klass).to_s == QUOTA_RESET_JOB}.schedule_info + days_remaining = (Time.at(reset_job.instance_variable_get(:@next_run)).to_date - Time.zone.now.to_date).to_i + { - answer: I18n.t("chatbot.prompt.function.remaining_bot_quota.answer", quota: remaining_quota, units: SiteSetting.chatbot_quota_basis ), + answer: I18n.t("chatbot.prompt.function.remaining_bot_quota.answer", quota: remaining_quota, units: SiteSetting.chatbot_quota_basis, days_remaining: days_remaining), token_usage: 0 } rescue => e