Skip to content

Commit

Permalink
add time remaining to reset
Browse files Browse the repository at this point in the history
  • Loading branch information
merefield committed Oct 22, 2024
1 parent 1f2c480 commit 95d03f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module DiscourseChatbot
class RemainingBotTokenQuotaFunction < Function
QUOTA_RESET_JOB = "Jobs::ChatbotQuotaReset"

def name
'remaining_bot_quota'
Expand All @@ -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
Expand Down

0 comments on commit 95d03f8

Please sign in to comment.