Ok
Browse files- chatbot/plugins/chat.py +21 -15
chatbot/plugins/chat.py
CHANGED
@@ -695,37 +695,43 @@ async def reshch(client, callback):
|
|
695 |
async def closeed(client, callback):
|
696 |
await callback.message.delete()
|
697 |
|
698 |
-
@Client.on_callback_query(filters.regex("^memory_(\d+)$"))
|
699 |
async def memory_updated(client, callback):
|
700 |
-
user_id =
|
701 |
-
user_bl = await db.user_blacklists.find_one({"user_id": user_id})
|
702 |
if user_bl and user_bl.get("is_frozen", False):
|
703 |
await callback.answer("Sorry your account is disabled", True)
|
704 |
return
|
705 |
|
|
|
706 |
if message_memory_state.get(callback.message.id, False):
|
707 |
return await callback.answer("Memory already updated!", show_alert=False)
|
708 |
try:
|
709 |
if user_id == 0:
|
710 |
return await callback.answer("Server busy, try again later", show_alert=True)
|
711 |
|
712 |
-
data_tr = await db.backup_chatbot.find_one({"user_id": user_id})
|
713 |
if not data_tr:
|
714 |
return await callback.answer("User data not found", show_alert=True)
|
715 |
|
716 |
-
backup_chat = await db._get_chatbot_chat_from_db(user_id)
|
717 |
if not backup_chat:
|
718 |
backup_chat = []
|
719 |
|
720 |
-
|
721 |
-
|
722 |
-
|
|
|
|
|
|
|
|
|
|
|
723 |
backup_chat.append({
|
724 |
"role": "model",
|
725 |
-
"parts": [{"text":
|
726 |
})
|
727 |
await asyncio.gather(
|
728 |
-
db._update_chatbot_chat_in_db(user_id, backup_chat),
|
729 |
callback.answer("Memory updated successfully!")
|
730 |
)
|
731 |
message_memory_state[callback.message.id] = True
|
@@ -752,7 +758,6 @@ async def terjemahkan(client, callback):
|
|
752 |
return await callback.answer("translate history not found")
|
753 |
|
754 |
for translations in data_tr["translate_history"]:
|
755 |
-
LOGS.info(f"Update translation: {translations['uuid']}")
|
756 |
if translations.get("uuid") == uuidstr:
|
757 |
translate_result += translations.get("text", "no translation")
|
758 |
break
|
@@ -838,6 +843,9 @@ async def multiple_langagues(client, callback):
|
|
838 |
InlineKeyboardButton("π²πΎ", callback_data=f"tr_{int(user_id)}_ms_{uuidstr}"),
|
839 |
InlineKeyboardButton("π·πΊ", callback_data=f"tr_{int(user_id)}_ru_{uuidstr}"),
|
840 |
])
|
|
|
|
|
|
|
841 |
try:
|
842 |
await callback.edit_message_reply_markup(
|
843 |
reply_markup=InlineKeyboardMarkup(keyboard)
|
@@ -870,8 +878,6 @@ async def response_call(client, callback):
|
|
870 |
[
|
871 |
InlineKeyboardButton(f"ποΈ", callback_data=f"menutools_{int(user_id)}"),
|
872 |
InlineKeyboardButton(f"π", url=f"https://t.me/{chat}"),
|
873 |
-
InlineKeyboardButton(f"βΎοΈ", callback_data=f"trmulti_{int(user_id)}"),
|
874 |
-
InlineKeyboardButton(f"πΎ", callback_data=f"memory_{int(user_id)}"),
|
875 |
],
|
876 |
[
|
877 |
InlineKeyboardButton(f"π 0", callback_data="like"),
|
@@ -896,7 +902,7 @@ def create_keyboard(
|
|
896 |
InlineKeyboardButton(f"ποΈ", callback_data=f"menutools_{user_id}"),
|
897 |
InlineKeyboardButton(f"π", url=f"https://t.me/{chat}"),
|
898 |
InlineKeyboardButton(f"βΎοΈ", callback_data=f"trmulti_{user_id}_{uuid_str}"),
|
899 |
-
InlineKeyboardButton(f"πΎ", callback_data=f"memory_{user_id}"),
|
900 |
],
|
901 |
[
|
902 |
InlineKeyboardButton(f"π {likes}", callback_data="vote:like"),
|
@@ -911,7 +917,7 @@ def create_keyboard(
|
|
911 |
InlineKeyboardButton(f"ποΈ", callback_data=f"menutools_{user_id}"),
|
912 |
InlineKeyboardButton(f"βΎοΈ", callback_data=f"trmulti_{user_id}_{uuid_str}"),
|
913 |
InlineKeyboardButton(f"π", callback_data=f"refreshch"),
|
914 |
-
InlineKeyboardButton(f"πΎ", callback_data=f"memory_{user_id}")
|
915 |
],
|
916 |
[
|
917 |
InlineKeyboardButton(f"π {likes}", callback_data="vote:like"),
|
|
|
695 |
async def closeed(client, callback):
|
696 |
await callback.message.delete()
|
697 |
|
698 |
+
@Client.on_callback_query(filters.regex("^memory_(\d+)_([a-f0-9]{8})$"))
|
699 |
async def memory_updated(client, callback):
|
700 |
+
user_id, uuidstr = callback.matches[0].groups()
|
701 |
+
user_bl = await db.user_blacklists.find_one({"user_id": int(user_id)})
|
702 |
if user_bl and user_bl.get("is_frozen", False):
|
703 |
await callback.answer("Sorry your account is disabled", True)
|
704 |
return
|
705 |
|
706 |
+
translate_result = ""
|
707 |
if message_memory_state.get(callback.message.id, False):
|
708 |
return await callback.answer("Memory already updated!", show_alert=False)
|
709 |
try:
|
710 |
if user_id == 0:
|
711 |
return await callback.answer("Server busy, try again later", show_alert=True)
|
712 |
|
713 |
+
data_tr = await db.backup_chatbot.find_one({"user_id": int(user_id)})
|
714 |
if not data_tr:
|
715 |
return await callback.answer("User data not found", show_alert=True)
|
716 |
|
717 |
+
backup_chat = await db._get_chatbot_chat_from_db(int(user_id))
|
718 |
if not backup_chat:
|
719 |
backup_chat = []
|
720 |
|
721 |
+
if not data_tr or "translate_history" not in data_tr:
|
722 |
+
return await callback.answer("translate history not found")
|
723 |
+
|
724 |
+
for translations in data_tr["translate_history"]:
|
725 |
+
if translations.get("uuid") == uuidstr:
|
726 |
+
translate_result += translations.get("text", "no translation")
|
727 |
+
break
|
728 |
+
|
729 |
backup_chat.append({
|
730 |
"role": "model",
|
731 |
+
"parts": [{"text": translate_result}]
|
732 |
})
|
733 |
await asyncio.gather(
|
734 |
+
db._update_chatbot_chat_in_db(int(user_id), backup_chat),
|
735 |
callback.answer("Memory updated successfully!")
|
736 |
)
|
737 |
message_memory_state[callback.message.id] = True
|
|
|
758 |
return await callback.answer("translate history not found")
|
759 |
|
760 |
for translations in data_tr["translate_history"]:
|
|
|
761 |
if translations.get("uuid") == uuidstr:
|
762 |
translate_result += translations.get("text", "no translation")
|
763 |
break
|
|
|
843 |
InlineKeyboardButton("π²πΎ", callback_data=f"tr_{int(user_id)}_ms_{uuidstr}"),
|
844 |
InlineKeyboardButton("π·πΊ", callback_data=f"tr_{int(user_id)}_ru_{uuidstr}"),
|
845 |
])
|
846 |
+
keyboard.append([
|
847 |
+
InlineKeyboardButton("πΎ", callback_data=f"memory_{int(user_id)}_{uuidstr}")
|
848 |
+
])
|
849 |
try:
|
850 |
await callback.edit_message_reply_markup(
|
851 |
reply_markup=InlineKeyboardMarkup(keyboard)
|
|
|
878 |
[
|
879 |
InlineKeyboardButton(f"ποΈ", callback_data=f"menutools_{int(user_id)}"),
|
880 |
InlineKeyboardButton(f"π", url=f"https://t.me/{chat}"),
|
|
|
|
|
881 |
],
|
882 |
[
|
883 |
InlineKeyboardButton(f"π 0", callback_data="like"),
|
|
|
902 |
InlineKeyboardButton(f"ποΈ", callback_data=f"menutools_{user_id}"),
|
903 |
InlineKeyboardButton(f"π", url=f"https://t.me/{chat}"),
|
904 |
InlineKeyboardButton(f"βΎοΈ", callback_data=f"trmulti_{user_id}_{uuid_str}"),
|
905 |
+
InlineKeyboardButton(f"πΎ", callback_data=f"memory_{user_id}_{uuid_str}"),
|
906 |
],
|
907 |
[
|
908 |
InlineKeyboardButton(f"π {likes}", callback_data="vote:like"),
|
|
|
917 |
InlineKeyboardButton(f"ποΈ", callback_data=f"menutools_{user_id}"),
|
918 |
InlineKeyboardButton(f"βΎοΈ", callback_data=f"trmulti_{user_id}_{uuid_str}"),
|
919 |
InlineKeyboardButton(f"π", callback_data=f"refreshch"),
|
920 |
+
InlineKeyboardButton(f"πΎ", callback_data=f"memory_{user_id}_{uuid_str}")
|
921 |
],
|
922 |
[
|
923 |
InlineKeyboardButton(f"π {likes}", callback_data="vote:like"),
|