-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf79ec5
commit e38e44f
Showing
9 changed files
with
528 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
logger | ||
script | ||
yarn.lock | ||
xuyue.memory-card.json | ||
xuyue.memory-card.json | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ This is an open-source WeChat robot project based on WechatY, Dify API services, | |
| USGC | 纽约黄金价格 |✅| | ||
| Inpainting | 机器人集群启动 |✅| | ||
| Websocket监听通信 | Websocket监听通信 |✅| | ||
| SQLite | 支持SQLite数据库 |✅| | ||
| Group Chat Export | 群聊天记录的导出 |✅| | ||
|
||
|
||
|
||
## Workflow | ||
|
||
|
@@ -45,7 +49,9 @@ This is an open-source WeChat robot project based on WechatY, Dify API services, | |
```bash | ||
# e.g. Ubuntu 22 | ||
sudo apt update | ||
# 启动语音识别功能需要安装ffmpeg | ||
sudo apt install ffmpeg | ||
# redis记录临时ID | ||
sudo apt install redis-server | ||
npm install -g pm2 | ||
``` | ||
|
@@ -101,3 +107,4 @@ [email protected] | |
https://tubex.chat | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import sqlite3 from 'sqlite3'; | ||
import moment from 'moment-timezone'; // Import moment-timezone for timezones | ||
|
||
// Set the default timezone to Beijing | ||
moment.tz.setDefault("Asia/Shanghai"); | ||
|
||
|
||
// 数据库文件名 | ||
const dbFile = 'chats.db'; | ||
|
||
// 创建数据库连接 | ||
let db = new sqlite3.Database(dbFile, (err) => { | ||
if (err) { | ||
console.error(err.message); | ||
} else { | ||
console.log('连接聊天记录数据库'); | ||
db.run(` | ||
CREATE TABLE IF NOT EXISTS chats ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
timestamp DATETIME DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), -- Use STRFTIME for timestamps | ||
name TEXT, | ||
message TEXT | ||
) | ||
`); | ||
} | ||
}); | ||
|
||
|
||
|
||
// 日志记录函数 | ||
export function chat(name, message) { | ||
|
||
// Limit message length to 200 characters | ||
// if(!message) return | ||
// const truncatedMessage = message.substring(0, 200); | ||
|
||
const timestamp = moment().format("YYYY-MM-DD HH:mm"); // Format timestamp with Beijing time | ||
db.run(`INSERT INTO chats (timestamp, name, message) VALUES (?, ?, ?)`, [timestamp, name, message], function (err) { | ||
if (err) { | ||
console.error(err.message); | ||
} | ||
}); | ||
|
||
|
||
// Keep only the latest 200 log entries | ||
db.run(`DELETE FROM chats WHERE id NOT IN (SELECT id FROM logs ORDER BY id DESC LIMIT 200)`); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
// 查询日志 | ||
export function getChats() { | ||
return new Promise((resolve, reject) => { | ||
db.all(`SELECT * FROM chats ORDER BY timestamp DESC`, [], (err, rows) => { | ||
if (err) { | ||
console.error(err.message); | ||
reject(err); | ||
} else { | ||
resolve(rows); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import sqlite3 from 'sqlite3'; | ||
import moment from 'moment-timezone'; // Import moment-timezone for timezones | ||
|
||
// Set the default timezone to Beijing | ||
moment.tz.setDefault("Asia/Shanghai"); | ||
|
||
|
||
// 数据库文件名 | ||
const dbFile = 'logs.db'; | ||
|
||
// 创建数据库连接 | ||
let db = new sqlite3.Database(dbFile, (err) => { | ||
if (err) { | ||
console.error(err.message); | ||
} else { | ||
console.log('连接日志数据库'); | ||
// 创建日志表(如果不存在) | ||
db.run(` | ||
CREATE TABLE IF NOT EXISTS logs ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
timestamp DATETIME DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), -- Use STRFTIME for timestamps | ||
level TEXT, | ||
message TEXT | ||
) | ||
`); | ||
} | ||
}); | ||
|
||
|
||
|
||
// 日志记录函数 | ||
export function log(level, message) { | ||
|
||
// Limit message length to 200 characters | ||
// if(!message) return | ||
// const truncatedMessage = message.substring(0, 200); | ||
|
||
const timestamp = moment().format("YYYY-MM-DD HH:mm"); // Format timestamp with Beijing time | ||
db.run(`INSERT INTO logs (timestamp, level, message) VALUES (?, ?, ?)`, [timestamp, level, message], function (err) { | ||
if (err) { | ||
console.error(err.message); | ||
} | ||
}); | ||
|
||
|
||
// Keep only the latest 200 log entries | ||
db.run(`DELETE FROM logs WHERE id NOT IN (SELECT id FROM logs ORDER BY id DESC LIMIT 200)`); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
// 查询日志 | ||
export function getLogs() { | ||
return new Promise((resolve, reject) => { | ||
db.all(`SELECT * FROM logs ORDER BY timestamp DESC`, [], (err, rows) => { // Order by timestamp descending | ||
if (err) { | ||
console.error(err.message); | ||
reject(err); | ||
} else { | ||
resolve(rows); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.