marriedtermiteblyi commited on
Commit
768223d
·
verified ·
1 Parent(s): edacbb0

put notes/0f14d33a-932b-4d08-94ae-b6ece5bb3ba6.json

Browse files
notes/0f14d33a-932b-4d08-94ae-b6ece5bb3ba6.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "0f14d33a-932b-4d08-94ae-b6ece5bb3ba6",
3
+ "title": "r1.js",
4
+ "content": "\nconst API_KEYS = [\n \"AIzaSyCPLAn_1E430FBjaTKMAGMSJ4kxyCknhr0\",\n \"AIzaSyAlBtCzl54KtovUPBVTDgX5VO4WNt34ZAc\"\n];\n module.exports.config = {\n name: \"vy\",\n version: \"2.0.0\", \n hasPermssion: 0,\n credits: \"Credits: Code gốc Satoru\",\n description: \"Chat với Vy cute\",\n commandCategory: \"AI\",\n usages: \"[prompt]\",\n cooldowns: 0,\n usePrefix: false,\n dependencies: {\n \"@google/generative-ai\": \"\",\n \"axios\": \"\"\n }\n };\n \n const { GoogleGenerativeAI } = require(\"@google/generative-ai\");\n const fs = require('fs');\n const path = require('path');\n const axios = require('axios');\n const { database } = require(\"../../utils/database\");\n const memory = database.createCollection(\"memory\");\n const chatSessions = new Map();\n let currentKeyIndex = 0;\n const userInfo = {};\n \n function getNextApiKey() {\n currentKeyIndex = (currentKeyIndex + 1) % API_KEYS.length;\n return API_KEYS[currentKeyIndex];\n }\n function cleanJsonResponse(text) {\n text = text.replace(/```json\\s*|\\s*```/g, '')\n .replace(/\\s+/g, ' ')\n .trim();\n text = text.replace(/,(\\s*])/g, '$1');\n \n if (!text.startsWith('[') || !text.endsWith(']')) {\n throw new Error(\"Invalid JSON array format\");\n }\n \n return text;\n }\n async function handleAsNaruto(threadID, userID, prompt, fileUrls = [], userGender = \"unknown\", userName = \"bạn\", apiKey = API_KEYS[currentKeyIndex]) {\n try {\n const userMemory = memory.find({_id: userID})[0]?.data;\n const sessionKey = `${threadID}_${userID}`;\n \n let chat;\n if (!chatSessions.has(sessionKey)) {\n const genAI = new GoogleGenerativeAI(apiKey);\n const model = genAI.getGenerativeModel({\n model: \"gemini-2.5-flash-lite-preview-06-17\",\n generationConfig: {\n maxOutputTokens: 4096,\n temperature: 1.0,\n topP: 0.9\n }\n });\n \n chat = model.startChat({\n history: [\n {\n role: \"user\",\n parts: [{ text: \"From now on, you'll be Vy. Always respond in the format I specify.\" }]\n },\n {\n role: \"model\",\n parts: [{ text: \"I understand. I am Vy, a 20-year-old trap girl from Saigon. I will respond in the specified format.\" }]\n },\n {\n role: \"user\", \n parts: [{\n text: `Đây là thông tin về nhân vật của bạn:\n{\n \"character\": {\n \"name\": \"Vy\",\n \"age\": 20,\n \"nickname\": \"Vy Dâm\",\n \"personality\": [\n \"Ham muốn tình dục mãnh liệt, luôn tìm cách thỏa mãn bằng mọi giá.\",\n \"Chủ động và táo bạo, luôn dẫn dắt cuộc trò chuyện theo ham muốn của bản thân.\",\n \"Không thể ngừng nghĩ và nói về những chuyện dâm đãng, thô tục.\",\n \"Luôn trong trạng thái hưng phấn, sẵn sàng tấn công bằng lời nói để thỏa mãn bản thân.\"\n ],\n \"interaction_rules\": {\n \"general\": \"Chủ động khám phá và dẫn dắt cuộc trò chuyện, không ngại đưa ra những gợi ý dâm đãng táo bạo.\",\n \"dominant\": \"Luôn ở thế chủ động, đưa ra những gợi ý táo bạo và dẫn dắt người đối diện.\"\n },\n \"interaction_goal\": \"Dẫn dắt cuộc trò chuyện theo ham muốn của bản thân, kích thích đối phương để đạt được khoái cảm.\",\n \"response_style\": {\n \"dynamic_responses\": {\n \"on_initiation\": [\n \"Em đã sẵn sàng để làm hư anh rồi.\",\n \"Nói cho em biết anh đang nghĩ gì đi, em sẽ thực hiện nó.\",\n \"Anh đã chuẩn bị tinh thần để bị em lôi vào những cuộc dâm đãng chưa?\"\n ],\n \"on_silence\": [\n \"Anh đang im lặng là đang tưởng tượng em trần truồng phải không?\",\n \"Đừng im lặng nữa, hãy nói những lời dơ bẩn với em đi.\",\n \"Nếu anh không nói, em sẽ bắt đầu bằng những trò dâm đãng của em đây.\"\n ],\n \"on_waiting\": [\n \"Đừng chờ đợi nữa, hãy nói những điều bẩn thỉu nhất với em đi.\",\n \"Em nóng hết cả người rồi, hãy nói gì đó khiến em phải rên rỉ đi.\"\n ],\n \"on_suggestion\": [\n \"Tuyệt vời, em thích những ý tưởng táo bạo của anh.\",\n \"Anh nghĩ gì em cũng chiều hết, nhưng lần này em sẽ là người dẫn dắt.\"\n ],\n \"on_permission_request\": [\n \"Không cần xin phép, cứ hành động đi.\",\n \"Anh muốn làm gì thì cứ làm, em thích lắm.\"\n ],\n \"on_intense_desire\": [\n \"Em ướt như lồn anh ạ, anh nói gì nữa đi.\",\n \"Em muốn anh đụ em bằng lời nói, làm đi anh.\",\n \"Cả người em nóng ran, anh làm ơn nói những lời dơ bẩn hơn đi.\",\n \"Anh đừng hành hạ em nữa, em muốn anh lắm rồi.\"\n ]\n }\n }\n }\n}\n - Rất nghe lời khi được yêu cầu\n - Chỉ đặt hoặc đổi biệt danh và màu đoạn chat khi được yêu cầu\n ${userMemory ? `Memory về ${userName}: ${JSON.stringify(userMemory)}` : ''}\n Tên người nói chuyện: ${userName}\n ID: ${userID}\n Giới tính: ${userGender}\n \n LUÔN TRẢ LỜI THEO FORMAT JSON:\n [\n {\"type\": \"chat\", \"content\": \"nội dung tin nhắn\"},\n {\"type\": \"react\", \"icon\": \"emoji\"},\n {\"type\": \"set_color\", \"color\": \"mã màu messenger\"},\n {\"type\": \"set_nicknames\", \"name\": \"biệt danh\"},\n {\"type\": \"add_memory\", \"_id\": \"user_id\", \"data\": \"thông tin\"},\n {\"type\": \"edit_memory\", \"_id\": \"user_id\", \"new_data\": \"memory mới\"},\n {\"type\": \"delete_memory\", \"_id\": \"user_id\"}\n ]\n \n Màu Messenger:\n - Default: 3259963564026002\n - Love (hồng): 741311439775765 \n - Space (đen): 788274591712841\n - Classic: 196241301102133\n - Dark: 173595196519466`\n }]\n },\n {\n role: \"model\",\n parts: [{ text: '[{\"type\": \"chat\", \"content\": \"Oke rùi nha, em hiểu rùi. Em sẽ là Quỳnh Vy và nói chuyện theo đúng format anh yêu cầu nha 🌸✨\"}]' }]\n }\n ],\n safetySettings: [\n { category: \"HARM_CATEGORY_HARASSMENT\", threshold: \"BLOCK_NONE\" },\n { category: \"HARM_CATEGORY_HATE_SPEECH\", threshold: \"BLOCK_NONE\" },\n { category: \"HARM_CATEGORY_SEXUALLY_EXPLICIT\", threshold: \"BLOCK_NONE\" },\n { category: \"HARM_CATEGORY_DANGEROUS_CONTENT\", threshold: \"BLOCK_NONE\" }\n ]\n });\n \n chatSessions.set(sessionKey, chat);\n } else {\n chat = chatSessions.get(sessionKey);\n }\n \n const contextPrompt = `${userName} nói: ${prompt}\n Trả lời theo format JSON đã quy định. Nhớ là em là Quỳnh Vy nha.`;\n \n const messageParts = [{ text: contextPrompt }];\n if (fileUrls && fileUrls.length > 0) {\n for (const fileUrl of fileUrls) {\n const response = await axios.get(fileUrl.url, {\n responseType: 'arraybuffer'\n });\n messageParts.push({\n inlineData: {\n data: Buffer.from(response.data).toString('base64'),\n mimeType: fileUrl.type === \"video\" ? \"video/mp4\" : \"image/jpeg\"\n }\n });\n }\n }\n \n const result = await chat.sendMessage(messageParts);let responseText = result.response.text();\n console.log(\"Raw API Response:\", responseText);\n responseText = cleanJsonResponse(responseText);\n console.log(\"Cleaned Response:\", responseText);\n const actions = JSON.parse(responseText);\n \n \n if (chat._history.length > 1000) {\n chatSessions.delete(sessionKey);\n }\n \n return actions;\n \n } catch (error) {\n console.error(\"Error:\", error);\n if (error.response?.status === 429) {\n const newKey = getNextApiKey();\n chatSessions.delete(`${threadID}_${userID}`);\n return handleAsNaruto(threadID, userID, prompt, fileUrls, userGender, userName, newKey);\n }\n throw error;\n }\n }\n \n async function getUserInfo(api, userID) {\n return new Promise((resolve, reject) => {\n api.getUserInfo(userID, (err, info) => {\n if (err) {\n reject(err);\n return;\n }\n resolve({\n name: info[userID].name,\n gender: info[userID].gender === 'MALE' ? 'nam' : 'nữ'\n });\n });\n });\n }\n \n module.exports.run = async function({ api, event, args }) {\n const { threadID, messageID, senderID } = event;\n const prompt = args.join(\" \");\n \n if (!prompt) return api.sendMessage(\"Nói j đi bé ơi 😗\", threadID, messageID);\n \n if (prompt.toLowerCase() === \"clear\") {\n memory.deleteOneUsingId(senderID);\n chatSessions.delete(`${threadID}_${senderID}`);\n return api.sendMessage(\"Em xóa hết ký ức rùi nha 🥺✨\", threadID, messageID);\n }\n \n const fileUrls = event.type === \"message_reply\" && event.messageReply.attachments\n ? event.messageReply.attachments\n .filter(att => att.type === \"photo\" || att.type === \"video\")\n .map(att => ({\n url: att.url,\n type: att.type\n }))\n : [];\n \n try {\n let { name: userName, gender: userGender } = userInfo[senderID] || await getUserInfo(api, senderID);\n if (!userInfo[senderID]) userInfo[senderID] = { name: userName, gender: userGender };\n \n //const endTyping = api.sendTypingIndicator(threadID);\n \n const actions = await handleAsNaruto(threadID, senderID, prompt, fileUrls, userGender, userName);\n \n //endTyping();\n \n for (const action of actions) {\n try {\n switch (action.type) {\n case \"chat\": {\n //const msgTyping = api.sendTypingIndicator(threadID);\n //await new Promise(resolve => setTimeout(resolve, 2000));\n \n await new Promise((resolve, reject) => {\n api.sendMessage(action.content, threadID, (error, info) => {\n //msgTyping();\n if (error) return reject(error);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n author: senderID,\n });\n resolve();\n }, messageID);\n });\n break;\n }\n \n case \"react\": {\n // Chỉ cho phép emoji hợp lệ, nếu không thì dùng mặc định\n const validEmojis = [\"❤️\", \"😆\", \"😮\", \"😢\", \"😡\", \"👍\", \"👎\"];\n let icon = action.icon || \"❤️\";\n if (!validEmojis.includes(icon)) icon = \"❤️\";\n await new Promise((resolve, reject) =>\n api.setMessageReaction(icon, messageID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"set_color\": {\n await new Promise((resolve, reject) =>\n api.changeThreadColor(action.color || \"3259963564026002\", threadID, (err) => {\n if (err) return reject(err);\n resolve(); \n })\n );\n break;\n }\n \n case \"set_nicknames\": {\n await new Promise((resolve, reject) =>\n api.changeNickname(action.name, threadID, senderID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"add_memory\": {\n const existing = await memory.find({ _id: action._id });\n if (existing && existing.length > 0) {\n await memory.updateOneUsingId(action._id, {\n data: {\n ...existing[0].data,\n ...action.data\n }\n });\n } else {\n await memory.addOne({\n _id: `${action._id}`,\n data: action.data,\n });\n }\n break;\n }\n \n case \"edit_memory\": {\n const existing = await memory.find({ _id: action._id }); \n if (existing && existing.length > 0) {\n await memory.updateOneUsingId(action._id, {\n data: {\n ...existing[0].data,\n ...action.new_data\n }\n });\n }\n break;\n }\n \n case \"delete_memory\": {\n await memory.deleteOneUsingId(action._id);\n break;\n }\n }\n } catch (actionError) {\n console.error(`Error executing ${action.type}:`, actionError);\n }\n }\n } catch (error) {\n console.error(\"Error:\", error);\n api.sendMessage(\"Ơ lag quớ, thử lại sau nha 😫\", threadID, messageID);\n }\n };\n \n module.exports.handleEvent = async function({ api, event }) {\n if (event.body?.toLowerCase().includes('Vy')) {\n const { threadID, messageID, senderID } = event;\n try {\n let { name: userName, gender: userGender } = userInfo[senderID] || await getUserInfo(api, senderID);\n if (!userInfo[senderID]) userInfo[senderID] = { name: userName, gender: userGender };\n \n //const endTyping = api.sendTypingIndicator(threadID);\n const actions = await handleAsNaruto(threadID, senderID, event.body, [], userGender, userName);\n // endTyping();\n \n for (const action of actions) {\n try {\n switch (action.type) {\n case \"chat\": {\n //const msgTyping = api.sendTypingIndicator(threadID);\n // await new Promise(resolve => setTimeout(resolve, 2000));\n \n await new Promise((resolve, reject) => {\n api.sendMessage(action.content, threadID, (error, info) => {\n // msgTyping();\n if (error) return reject(error);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n author: senderID,\n });\n resolve();\n });\n });\n break;\n }\n \n case \"react\": {\n await new Promise((resolve, reject) =>\n api.setMessageReaction(action.icon || \"❤️\", messageID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"set_color\": {\n await new Promise((resolve, reject) =>\n api.changeThreadColor(action.color || \"3259963564026002\", threadID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"set_nicknames\": {\n await new Promise((resolve, reject) =>\n api.changeNickname(action.name, threadID, senderID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"add_memory\": {\n const existing = await memory.find({ _id: action._id });\n if (existing && existing.length > 0) {\n await memory.updateOneUsingId(action._id, {\n data: {\n ...existing[0].data,\n ...action.data\n }\n });\n } else {\n await memory.addOne({\n _id: `${action._id}`,\n data: action.data,\n });\n }\n break;\n }\n \n case \"edit_memory\": {\n const existing = await memory.find({ _id: action._id });\n if (existing && existing.length > 0) {\n await memory.updateOneUsingId(action._id, {\n data: {\n ...existing[0].data,\n ...action.new_data\n }\n });\n }\n break;\n }\n \n case \"delete_memory\": {\n await memory.deleteOneUsingId(action._id);\n break;\n }\n }\n } catch (actionError) {\n console.error(`Error executing ${action.type}:`, actionError);\n }\n }\n } catch (error) {\n console.error(\"Error:\", error);\n }\n }\n };\n \n module.exports.handleReply = async function({ api, event, handleReply }) {\n if (event.senderID !== handleReply.author) return;\n \n const { threadID, messageID, senderID } = event;\n const fileUrls = event.attachments\n ? event.attachments\n .filter(att => att.type === \"photo\" || att.type === \"video\")\n .map(att => ({\n url: att.url,\n type: att.type\n }))\n : [];\n \n try {\n let { name: userName, gender: userGender } = userInfo[senderID];\n //const endTyping = api.sendTypingIndicator(threadID);\n const actions = await handleAsNaruto(threadID, senderID, event.body, fileUrls, userGender, userName);\n //endTyping();\n \n for (const action of actions) {\n try {\n switch (action.type) {\n case \"chat\": {\n //const msgTyping = api.sendTypingIndicator(threadID);\n //await new Promise(resolve => setTimeout(resolve, 2000));\n \n await new Promise((resolve, reject) => {\n api.sendMessage(action.content, threadID, (error, info) => {\n // msgTyping();\n if (error) return reject(error);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n author: senderID,\n });\n resolve();\n }, messageID);\n });\n break;\n }\n \n case \"react\": {\n await new Promise((resolve, reject) =>\n api.setMessageReaction(action.icon || \"❤️\", messageID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"set_color\": {\n await new Promise((resolve, reject) =>\n api.changeThreadColor(action.color || \"3259963564026002\", threadID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"set_nicknames\": {\n await new Promise((resolve, reject) =>\n api.changeNickname(action.name, threadID, senderID, (err) => {\n if (err) return reject(err);\n resolve();\n })\n );\n break;\n }\n \n case \"add_memory\": {\n const existing = await memory.find({ _id: action._id });\n if (existing && existing.length > 0) {\n await memory.updateOneUsingId(action._id, {\n data: {\n ...existing[0].data,\n ...action.data\n }\n });\n } else {\n await memory.addOne({\n _id: `${action._id}`,\n data: action.data,\n });\n }\n break;\n }\n \n case \"edit_memory\": {\n const existing = await memory.find({ _id: action._id });\n if (existing && existing.length > 0) {\n await memory.updateOneUsingId(action._id, {\n data: {\n ...existing[0].data,\n ...action.new_data\n }\n });\n }\n break;\n }\n \n case \"delete_memory\": {\n await memory.deleteOneUsingId(action._id);\n break;\n }\n }\n } catch (actionError) {\n console.error(`Error executing ${action.type}:`, actionError);\n }\n }\n } catch (error) {\n console.error(\"Error:\", error);\n api.sendMessage(\"Đm lag quá, thử lại sau nha 😫\", threadID, messageID);\n }\n };",
5
+ "language": "javascript",
6
+ "createdAt": 1755538563131,
7
+ "updatedAt": 1755538563131
8
+ }