randydev commited on
Commit
b0cdcd4
Β·
1 Parent(s): 96872e8
Files changed (1) hide show
  1. akn/manage/callback.py +94 -92
akn/manage/callback.py CHANGED
@@ -66,7 +66,7 @@ Before making a fuss, make sure you understand the situation first. Answer prope
66
  CUSTOM_KEY = """
67
  Welcome to AkenoX API
68
 
69
- - You can use v1 free unlimited
70
  - Also V2 Premium 30 days Trial
71
 
72
  Below Click Button
@@ -274,25 +274,54 @@ async def cb_new_revokekey(client, query):
274
  user_id = query.from_user.id
275
  if not query.from_user.username:
276
  return await query.answer("Required username first", True)
277
- url = "https://randydev-ryu-js.hf.space/api/v1/key/revoked-key"
278
- response = requests.post(
279
- url,
280
- params={
281
- "user_id": user_id,
282
- "username": query.from_user.username
283
- },
284
- headers={"x-api-key": os.environ.get("AKENOX_KEY")}
285
- )
286
- if response.status_code != 200:
287
- return await query.answer("Error api try again", True)
288
- data_json = response.json()
 
 
289
  if data_json.get("is_banned", False):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  keyboard_back = InlineKeyboardMarkup(
291
  [
292
  [
293
  InlineKeyboardButton(
294
- "Support Group",
295
- url="https://t.me/AkenoXDevSupport"
 
 
 
 
296
  ),
297
  ],
298
  [
@@ -304,56 +333,31 @@ async def cb_new_revokekey(client, query):
304
  ]
305
  )
306
  return await query.edit_message_text(
307
- BANNED_APIKEY,
 
 
 
 
 
308
  reply_markup=keyboard_back
309
  )
310
- else:
311
- if data_json.get("apiKey", False):
312
- await query.answer(data_json["message"], True)
313
- keyboard_back = InlineKeyboardMarkup(
314
- [
315
- [
316
- InlineKeyboardButton(
317
- "API Key",
318
- copy_text=data_json["apiKey"]
319
- ),
320
- InlineKeyboardButton(
321
- "⚠️ Revoke Key",
322
- callback_data="revokedkey"
323
- ),
324
- ],
325
- [
326
- InlineKeyboardButton(
327
- "πŸ”™ Back",
328
- callback_data="contet"
329
- )
330
- ]
331
- ]
332
- )
333
- return await query.edit_message_text(
334
- YOU_KEY_TEXT.format(
335
- api_key=data_json["apiKey"],
336
- create_at=data_json.get("createdAt", ""),
337
- type=data_json.get("type", "Free"),
338
- ttn=data_json.get("expiresAt", "Unlimited")
339
- ),
340
- reply_markup=keyboard_back
341
- )
342
- else:
343
- return await query.answer("Error api try again", True)
344
 
345
  @ren.on_callback_query(filters.regex("createkeyprem"))
346
  async def cb_new_keyprem(client, query):
347
  user_id = query.from_user.id
348
- url = "https://randydev-ryu-js.hf.space/api/v2/key/generate-key"
349
- response = requests.post(
350
- url,
351
- params={"user_id": user_id},
352
- headers={"x-api-key": os.environ.get("AKENOX_KEY")}
353
- )
354
- if response.status_code != 200:
355
- return await query.answer("Error api try again", True)
356
- data_json = response.json()
 
 
 
357
  if data_json.get("is_banned", False):
358
  keyboard_back = InlineKeyboardMarkup(
359
  [
@@ -375,41 +379,39 @@ async def cb_new_keyprem(client, query):
375
  BANNED_APIKEY,
376
  reply_markup=keyboard_back
377
  )
378
- else:
379
- if data_json.get("apiKey", False):
380
- keyboard_back = InlineKeyboardMarkup(
 
 
 
 
 
 
 
 
 
 
 
 
381
  [
382
- [
383
- InlineKeyboardButton(
384
- "API Key",
385
- copy_text=data_json["apiKey"]
386
- )
387
- ],
388
- [
389
- InlineKeyboardButton(
390
- "Example Cohere",
391
- callback_data="example_cohere"
392
- )
393
- ],
394
- [
395
- InlineKeyboardButton(
396
- "πŸ”™ Back",
397
- callback_data="custom_key"
398
- )
399
- ]
400
  ]
401
- )
402
- return await query.edit_message_text(
403
- YOU_KEY_TEXT.format(
404
- api_key=data_json["apiKey"],
405
- create_at=data_json.get("createdAt", ""),
406
- type=data_json.get("type", "No"),
407
- ttn=data_json.get("expiresAt", "No")
408
- ),
409
- reply_markup=keyboard_back
410
- )
411
- else:
412
- return await query.answer("Error api try again", True)
413
 
414
  @ren.on_callback_query(filters.regex("createkey"))
415
  async def cb_new_key(client, query):
 
66
  CUSTOM_KEY = """
67
  Welcome to AkenoX API
68
 
69
+ - You can use V1 free unlimited
70
  - Also V2 Premium 30 days Trial
71
 
72
  Below Click Button
 
274
  user_id = query.from_user.id
275
  if not query.from_user.username:
276
  return await query.answer("Required username first", True)
277
+ try:
278
+ url = "https://randydev-ryu-js.hf.space/api/v1/key/revoked-key"
279
+ response = requests.post(
280
+ url,
281
+ params={
282
+ "user_id": user_id,
283
+ "username": query.from_user.username
284
+ },
285
+ headers={"x-api-key": os.environ.get("AKENOX_KEY")}
286
+ )
287
+ response.raise_for_status()
288
+ data_json = response.json()
289
+ except requests.exceptions.RequestException:
290
+ return await query.answer("API request failed, please try again.", True)
291
  if data_json.get("is_banned", False):
292
+ keyboard_back = InlineKeyboardMarkup(
293
+ [
294
+ [InlineKeyboardButton("Support Group", url="https://t.me/AkenoXDevSupport")],
295
+ [InlineKeyboardButton("πŸ”™ Back", callback_data="custom_key")]
296
+ ]
297
+ )
298
+ return await query.edit_message_text(
299
+ BANNED_APIKEY,
300
+ reply_markup=keyboard_back
301
+ )
302
+ if data_json.get("is_deleted", False):
303
+ keyboard_back = InlineKeyboardMarkup(
304
+ [
305
+ [InlineKeyboardButton("Support Group", url="https://t.me/AkenoXDevSupport")],
306
+ [InlineKeyboardButton("πŸ”™ Back", callback_data="custom_key")]
307
+ ]
308
+ )
309
+ return await query.edit_message_text(
310
+ data_json.get("message", "Unknown error"),
311
+ reply_markup=keyboard_back
312
+ )
313
+ if api_key := data_json.get("apiKey", False):
314
+ await query.answer(data_json["message"], True)
315
  keyboard_back = InlineKeyboardMarkup(
316
  [
317
  [
318
  InlineKeyboardButton(
319
+ "API Key",
320
+ copy_text=api_key
321
+ ),
322
+ InlineKeyboardButton(
323
+ "⚠️ Revoke Key",
324
+ callback_data="revokedkey"
325
  ),
326
  ],
327
  [
 
333
  ]
334
  )
335
  return await query.edit_message_text(
336
+ YOU_KEY_TEXT.format(
337
+ api_key=api_key,
338
+ create_at=data_json.get("createdAt", ""),
339
+ type=data_json.get("type", "Free"),
340
+ ttn=data_json.get("expiresAt", "Unlimited")
341
+ ),
342
  reply_markup=keyboard_back
343
  )
344
+ return await query.answer("Error api try again", True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
 
346
  @ren.on_callback_query(filters.regex("createkeyprem"))
347
  async def cb_new_keyprem(client, query):
348
  user_id = query.from_user.id
349
+ try:
350
+ url = "https://randydev-ryu-js.hf.space/api/v2/key/generate-key"
351
+ response = requests.post(
352
+ url,
353
+ params={"user_id": user_id},
354
+ headers={"x-api-key": os.environ.get("AKENOX_KEY")}
355
+ )
356
+ response.raise_for_status()
357
+ data_json = response.json()
358
+ except requests.exceptions.RequestException:
359
+ return await query.answer("API request failed, please try again.", True)
360
+
361
  if data_json.get("is_banned", False):
362
  keyboard_back = InlineKeyboardMarkup(
363
  [
 
379
  BANNED_APIKEY,
380
  reply_markup=keyboard_back
381
  )
382
+ if api_key := data_json.get("apiKey", False):
383
+ keyboard_back = InlineKeyboardMarkup(
384
+ [
385
+ [
386
+ InlineKeyboardButton(
387
+ "API Key",
388
+ copy_text=api_key
389
+ )
390
+ ],
391
+ [
392
+ InlineKeyboardButton(
393
+ "Example Cohere",
394
+ callback_data="example_cohere"
395
+ )
396
+ ],
397
  [
398
+ InlineKeyboardButton(
399
+ "πŸ”™ Back",
400
+ callback_data="custom_key"
401
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  ]
403
+ ]
404
+ )
405
+ return await query.edit_message_text(
406
+ YOU_KEY_TEXT.format(
407
+ api_key=api_key,
408
+ create_at=data_json.get("createdAt", ""),
409
+ type=data_json.get("type", "No"),
410
+ ttn=data_json.get("expiresAt", "No")
411
+ ),
412
+ reply_markup=keyboard_back
413
+ )
414
+ return await query.answer("Error api try again", True)
415
 
416
  @ren.on_callback_query(filters.regex("createkey"))
417
  async def cb_new_key(client, query):