randydev commited on
Commit
83e7e39
Β·
verified Β·
1 Parent(s): ae22eff
Files changed (1) hide show
  1. chatbot/plugins/chat.py +108 -0
chatbot/plugins/chat.py CHANGED
@@ -37,6 +37,11 @@ from config import *
37
  from database import db, users_collection
38
  from logger import LOGS
39
 
 
 
 
 
 
40
  trans = SyncTranslator()
41
  js = AkenoXJs(DifferentAPIDefault()).connect()
42
 
@@ -264,6 +269,24 @@ async def coheresearch(client, callback):
264
  ])
265
  await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  def inline_error(text: str):
268
  return [
269
  InlineQueryResultArticle(
@@ -326,6 +349,38 @@ async def inline_search(client: Client, inline_query: InlineQuery):
326
  await inline_query.answer(inline_error("Internal error. Try again later."), cache_time=1)
327
  LOGS.error(f"[INLINE ERROR] {type(e).__name__}: {e}")
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  @Client.on_callback_query(filters.regex("^deeps_(on|off)_([a-f0-9]{8})$"))
330
  async def deepsearchmode(client, callback):
331
  user_id = callback.from_user.id
@@ -333,6 +388,10 @@ async def deepsearchmode(client, callback):
333
  if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
334
  await callback.answer("Sorry your account is frozen", True)
335
  return
 
 
 
 
336
  mode, uuidstr = callback.matches[0].groups()
337
  try:
338
  if mode not in ("on", "off"):
@@ -362,6 +421,9 @@ async def modelgeminimenu(client, callback):
362
  if check_is_system and check_is_system.get("is_deepsearch", False):
363
  await callback.answer(f"You can OFF in deep search", show_alert=True)
364
  return
 
 
 
365
  keyboard = []
366
  keyboard.append([
367
  InlineKeyboardButton("G Flash EXP", callback_data=f"us:gemini-2.0-flash-exp:{uuidstr}"),
@@ -838,6 +900,7 @@ def create_keyboard(
838
  InlineKeyboardButton(f"πŸ”’", callback_data=f"showchat"),
839
  InlineKeyboardButton(f"⛏️", callback_data=f"modelmenu:{uuid_str}"),
840
  InlineKeyboardButton(f"πŸ’‘", callback_data=f"comode:{uuid_str}"),
 
841
  InlineKeyboardButton(f"πŸ’Ύ", callback_data=f"memory_{uuid_str}")
842
  ],
843
  [
@@ -1535,6 +1598,51 @@ async def chatbot_talk(client: Client, message: Message):
1535
  )
1536
  return
1537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1538
  uuid_cohere = str(uuid.uuid4())[:8]
1539
  if check_is_system.get("is_deepsearch", False):
1540
  backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
 
37
  from database import db, users_collection
38
  from logger import LOGS
39
 
40
+ from Ryzenth import ApiKeyFrom, SmallConvertDot
41
+ from Ryzenth.types import RequestHumanizer
42
+
43
+ ryz = ApiKeyFrom(..., True)
44
+
45
  trans = SyncTranslator()
46
  js = AkenoXJs(DifferentAPIDefault()).connect()
47
 
 
269
  ])
270
  await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
271
 
272
+ @Client.on_callback_query(filters.regex("^human:([a-f0-9]{8})"))
273
+ async def _humancb(client, callback):
274
+ user_id = callback.from_user.id
275
+ uuidstr = callback.matches[0].group(1)
276
+ user_bl = await db.user_blacklists.find_one({"user_id": user_id})
277
+ if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
278
+ await callback.answer("Sorry your account is frozen", True)
279
+ return
280
+ keyboard = []
281
+ keyboard.append([
282
+ InlineKeyboardButton("Humanizer ON", callback_data=f"humanizer_on_{uuidstr}"),
283
+ InlineKeyboardButton("Humanizer OFF", callback_data=f"humanizer_off_{uuidstr}")
284
+ ])
285
+ keyboard.append([
286
+ InlineKeyboardButton("Back To Menu", callback_data=f"menu_back:{uuidstr}")
287
+ ])
288
+ await callback.edit_message_reply_markup(reply_markup=InlineKeyboardMarkup(keyboard))
289
+
290
  def inline_error(text: str):
291
  return [
292
  InlineQueryResultArticle(
 
349
  await inline_query.answer(inline_error("Internal error. Try again later."), cache_time=1)
350
  LOGS.error(f"[INLINE ERROR] {type(e).__name__}: {e}")
351
 
352
+ @Client.on_callback_query(filters.regex("^humanizer_(on|off)_([a-f0-9]{8})$"))
353
+ async def humanizermode(client, callback):
354
+ user_id = callback.from_user.id
355
+ user_bl = await db.user_blacklists.find_one({"user_id": user_id})
356
+ if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
357
+ await callback.answer("Sorry your account is frozen", True)
358
+ return
359
+ check_is_system = await db.backup_chatbot.find_one({"user_id": user_id})
360
+ if check_is_system and check_is_system.get("is_deepsearch", False):
361
+ await callback.answer(f"You can OFF in deep search", show_alert=True)
362
+ return
363
+ mode, uuidstr = callback.matches[0].groups()
364
+ try:
365
+ if mode not in ("on", "off"):
366
+ await callback.answer("Mode invalid", show_alert=True)
367
+ return
368
+ is_human = mode == "on"
369
+ await db.backup_chatbot.update_one(
370
+ {"user_id": user_id},
371
+ {"$set": {"is_humanizer": is_human}},
372
+ upsert=True
373
+ )
374
+ await callback.answer(f"Humanizer mode is set to {mode}.", show_alert=True)
375
+ keyboard = create_keyboard(
376
+ user_id=user_id,
377
+ uuid_str=uuidstr
378
+ )
379
+ await callback.edit_message_reply_markup(reply_markup=keyboard)
380
+ except Exception as e:
381
+ LOGS.error(f"Humanizer Error: {e}")
382
+ await callback.answer("Please try again later..", show_alert=True)
383
+
384
  @Client.on_callback_query(filters.regex("^deeps_(on|off)_([a-f0-9]{8})$"))
385
  async def deepsearchmode(client, callback):
386
  user_id = callback.from_user.id
 
388
  if user_bl and user_bl.get("is_frozen", False) and user_id not in [6477856957]:
389
  await callback.answer("Sorry your account is frozen", True)
390
  return
391
+ check_is_system = await db.backup_chatbot.find_one({"user_id": user_id})
392
+ if check_is_system and check_is_system.get("is_humanizer", False):
393
+ await callback.answer(f"You can OFF in humanizer", show_alert=True)
394
+ return
395
  mode, uuidstr = callback.matches[0].groups()
396
  try:
397
  if mode not in ("on", "off"):
 
421
  if check_is_system and check_is_system.get("is_deepsearch", False):
422
  await callback.answer(f"You can OFF in deep search", show_alert=True)
423
  return
424
+ if check_is_system and check_is_system.get("is_humanizer", False):
425
+ await callback.answer(f"You can OFF in humanizer", show_alert=True)
426
+ return
427
  keyboard = []
428
  keyboard.append([
429
  InlineKeyboardButton("G Flash EXP", callback_data=f"us:gemini-2.0-flash-exp:{uuidstr}"),
 
900
  InlineKeyboardButton(f"πŸ”’", callback_data=f"showchat"),
901
  InlineKeyboardButton(f"⛏️", callback_data=f"modelmenu:{uuid_str}"),
902
  InlineKeyboardButton(f"πŸ’‘", callback_data=f"comode:{uuid_str}"),
903
+ InlineKeyboardButton(f"πŸšΆβ€β™€οΈ", callback_data=f"human:{uuid_str}"),
904
  InlineKeyboardButton(f"πŸ’Ύ", callback_data=f"memory_{uuid_str}")
905
  ],
906
  [
 
1598
  )
1599
  return
1600
 
1601
+ uuid_human = str(uuid.uuid4())[:8]
1602
+ if check_is_system.get("is_humanizer", False):
1603
+ backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)
1604
+ backup_chat.append({"role": "user", "parts": [{"text": query_base}]})
1605
+ response = await ryz.aio.humanizer.rewrite(
1606
+ RequestHumanizer(
1607
+ text=str(query_base),
1608
+ writing_style="casual",
1609
+ author_id=str(message.from_user.id),
1610
+ timestamp=str(dt.now())
1611
+ ),
1612
+ pickle_json=True
1613
+ )
1614
+ data = SmallConvertDot(response).to_dot()
1615
+ if len(data.text) > 4096:
1616
+ text_parts = split_message(data.text)
1617
+ for part in text_parts:
1618
+ await message.reply_text(part)
1619
+ else:
1620
+ keyboard_like = create_keyboard(
1621
+ user_id=message.from_user.id,
1622
+ uuid_str=uuid_human
1623
+ )
1624
+ await message.reply_text(
1625
+ data.text,
1626
+ disable_web_page_preview=True,
1627
+ reply_markup=keyboard_like
1628
+ )
1629
+ translation_entry = {
1630
+ "uuid": uuid_cohere,
1631
+ "text": data.text,
1632
+ "timestamp": dt.now().isoformat()
1633
+ }
1634
+ await db.backup_chatbot.update_one(
1635
+ {"user_id": message.from_user.id},
1636
+ {"$push": {"translate_history": translation_entry}},
1637
+ upsert=True
1638
+ )
1639
+ backup_chat.append({"role": "model", "parts": [{"text": data.text}]})
1640
+ await db._update_chatbot_chat_in_db(message.from_user.id, backup_chat)
1641
+ LOGS.info(f"Response Humanizer: {message.from_user.first_name} | {message.from_user.id}\n\nText: {query_base}")
1642
+ await client.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
1643
+ return
1644
+
1645
+
1646
  uuid_cohere = str(uuid.uuid4())[:8]
1647
  if check_is_system.get("is_deepsearch", False):
1648
  backup_chat = await db._get_chatbot_chat_from_db(message.from_user.id)