@@ -159,14 +159,44 @@ async def help_group_chat_handle(update: Update, context: CallbackContext):
159
159
await update .message .reply_text (text , parse_mode = ParseMode .HTML )
160
160
await update .message .reply_video (config .help_group_chat_video_path )
161
161
162
+ #untested
163
+ #async def token_balance_preprocessor(update: Update, context: CallbackContext):
164
+ #user_id = update.effective_user.id
165
+
166
+ #if db.check_token_balance(user_id) >= 11: # Assuming 1 token is needed
167
+ #context.user_data['process_allowed'] = True
168
+ #else:
169
+ #context.user_data['process_allowed'] = False
170
+ #await update.message.reply_text("Insufficient tokens. Please top up to continue.")
171
+
172
+ #untested
173
+ async def token_balance_preprocessor (update : Update , context : CallbackContext ):
174
+ user_id = update .effective_user .id
175
+ current_balance = db .check_token_balance (user_id )
176
+
177
+ if db .check_token_balance (user_id ) < 1 : # Assuming 1 token is needed
178
+ context .user_data ['process_allowed' ] = False
179
+ await update .message .reply_text (
180
+ f"_Insufficient tokens. Please top up to continue._ \n \n Your current balance is { current_balance } " ,
181
+ parse_mode = 'Markdown'
182
+ )
183
+ return False
184
+ else :
185
+ context .user_data ['process_allowed' ] = True
186
+ return True
187
+
162
188
163
189
async def retry_handle (update : Update , context : CallbackContext ):
164
190
await register_user_if_not_exists (update , context , update .message .from_user )
165
191
if await is_previous_message_not_answered_yet (update , context ): return
166
-
192
+
167
193
user_id = update .message .from_user .id
168
194
db .set_user_attribute (user_id , "last_interaction" , datetime .now ())
169
195
196
+ #untested1
197
+ if not await token_balance_preprocessor (update , context ):
198
+ return
199
+
170
200
dialog_messages = db .get_dialog_messages (user_id , dialog_id = None )
171
201
if len (dialog_messages ) == 0 :
172
202
await update .message .reply_text ("No message to retry 🤷♂️" )
@@ -200,11 +230,16 @@ async def message_handle(update: Update, context: CallbackContext, message=None,
200
230
user_id = update .message .from_user .id
201
231
chat_mode = db .get_user_attribute (user_id , "current_chat_mode" )
202
232
233
+ #untested1
234
+ if not await token_balance_preprocessor (update , context ):
235
+ return
236
+
203
237
if chat_mode == "artist" :
204
238
await generate_image_handle (update , context , message = message )
205
239
return
206
240
207
241
async def message_handle_fn ():
242
+
208
243
# new dialog timeout
209
244
if use_new_dialog_timeout :
210
245
if (datetime .now () - db .get_user_attribute (user_id , "last_interaction" )).seconds > config .new_dialog_timeout and len (db .get_dialog_messages (user_id )) > 0 :
@@ -338,6 +373,10 @@ async def voice_message_handle(update: Update, context: CallbackContext):
338
373
user_id = update .message .from_user .id
339
374
db .set_user_attribute (user_id , "last_interaction" , datetime .now ())
340
375
376
+ #untested1
377
+ if not await token_balance_preprocessor (update , context ):
378
+ return
379
+
341
380
voice = update .message .voice
342
381
voice_file = await context .bot .get_file (voice .file_id )
343
382
@@ -606,6 +645,10 @@ async def show_balance_handle(update: Update, context: CallbackContext):
606
645
607
646
608
647
async def edited_message_handle (update : Update , context : CallbackContext ):
648
+
649
+ #untested
650
+
651
+
609
652
if update .edited_message .chat .type == "private" :
610
653
text = "🥲 Unfortunately, message <b>editing</b> is not supported"
611
654
await update .edited_message .reply_text (text , parse_mode = ParseMode .HTML )
0 commit comments