给 Copilot 增加问答 token 限制
关键技术点
发送消息配置执行脚本
return 返回 true (继续发送消息), false(打断发送的消息)
具体搭建
内置数据库创建
copilot_token | |
user_id | text |
token | integer |
day | date |
页面搭建
MAX_TOKEN
{{10000 * 4 * 500}}
find_user_token
SELECT SUM(token) FROM copilot_token WHERE user_id = {{mobi.currentUser.id}} AND day = {{now_day.value}}::date
add_token
INSERT INTO copilot_token(user_id,token,day)
VALUES({{mobi.currentUser.id}},{{token}},{{now_day.value}}::date)
now_day
function formatDateTime(date = new Date()) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
const day = String(date.getDate()).padStart(2, '0');
// 返回你想要的格式,这里以 "YYYY-MM-DD HH:mm:ss" 为例
return `${year}-${month}-${day}`;
}
return formatDateTime();
发送消息事件
var token = await find_user_token.trigger();
if(token.data > MAX_TOKEN.value ){
mobi.showMessage("您今日Token数已用完")
return false;
}
return true;
该文章对您有帮助吗?
- 本页导读
- 关键技术点
- 具体搭建
- 内置数据库创建
- 页面搭建