From 2a0115ea17615973f7bb91f492ca738211df0ff2 Mon Sep 17 00:00:00 2001 From: feie9454 Date: Sat, 28 Jun 2025 20:34:33 +0800 Subject: [PATCH] feat: add qq push --- .env.example | 5 +++++ lib/push.ts | 12 ++++++++---- lib/push/qq.ts | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 lib/push/qq.ts diff --git a/.env.example b/.env.example index 5465708..1904db7 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,8 @@ MINIO_USE_SSL=false MINIO_ACCESS_KEY=your_access_key MINIO_SECRET_KEY=your_secret_key MINIO_BUCKET_NAME=winupdate + +# QQ Bot URL +QQ_BOT_URL=http://localhost:30000/send_private_msg +# QQ Bot Target ID +QQ_BOT_TARGET_ID=1234567890 \ No newline at end of file diff --git a/lib/push.ts b/lib/push.ts index bfa5460..290fc66 100644 --- a/lib/push.ts +++ b/lib/push.ts @@ -1,8 +1,12 @@ -// Simple notification/logging function -// In production, you might want to integrate with actual push notification service +import { sendMsg } from "./push/qq"; + export function push(message: string) { console.log(`[NOTIFICATION] ${new Date().toISOString()}: ${message}`) - // Here you could add actual push notification logic - // For example, sending to webhook, email, or push notification service + const msg = `[WinUpdate] ${new Date().toLocaleString()}\n${message}`; + + if (process.env.QQ_BOT_URL && process.env.QQ_BOT_TARGET_ID) { + sendMsg(msg, process.env.QQ_BOT_TARGET_ID, process.env.QQ_BOT_URL); + } } + diff --git a/lib/push/qq.ts b/lib/push/qq.ts new file mode 100644 index 0000000..78fb99a --- /dev/null +++ b/lib/push/qq.ts @@ -0,0 +1,21 @@ +export function sendMsg(msg: string, target_id: string, bot_url: string): Promise { + const replyMessage = { + user_id: String(target_id), + message: [ + { + type: "text", + data: { + text: msg + } + } + ] + } + + return fetch(bot_url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(replyMessage) + }); +}