File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
# name: discourse-chatbot
3
3
# about: a plugin that allows you to have a conversation with a configurable chatbot in Discourse Chat, Topics and Private Messages
4
- # version: 1.4.5
4
+ # version: 1.4.6
5
5
# authors: merefield
6
6
# url: https://github.com/merefield/discourse-chatbot
7
7
@@ -144,6 +144,16 @@ def progress_debug_message(message)
144
144
register_user_custom_field_type ( ::DiscourseChatbot ::CHATBOT_REMAINING_QUOTA_TOKENS_CUSTOM_FIELD , :integer )
145
145
register_user_custom_field_type ( ::DiscourseChatbot ::CHATBOT_QUERIES_QUOTA_REACH_ESCALATION_DATE_CUSTOM_FIELD , :date )
146
146
147
+ # Initialize Chatbot Quotas for all users as required
148
+ user_count = User . count
149
+ queries_field_count = UserCustomField . where ( name : ::DiscourseChatbot ::CHATBOT_REMAINING_QUOTA_QUERIES_CUSTOM_FIELD ) . count
150
+ token_field_count = UserCustomField . where ( name : ::DiscourseChatbot ::CHATBOT_REMAINING_QUOTA_TOKENS_CUSTOM_FIELD ) . count
151
+ pp "CHATBOT: Checking presence of Chatbot Custom Fields"
152
+ if user_count > queries_field_count * 2 || user_count > token_field_count * 2
153
+ pp "CHATBOT: Resetting Chatbot Quotas for all users as many users without required Chatbot Custom Fields"
154
+ ::DiscourseChatbot ::Bot . new . reset_all_quotas
155
+ end
156
+
147
157
add_to_serializer ( :current_user , :chatbot_access ) do
148
158
!::DiscourseChatbot ::EventEvaluation . new . trust_level ( object . id ) . blank?
149
159
end
You can’t perform that action at this time.
0 commit comments