mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor: log dir
This commit is contained in:
parent
95b4b11f02
commit
b314e2f3a0
@ -6,7 +6,7 @@ import path from "node:path";
|
|||||||
import {selfInfo} from "./data";
|
import {selfInfo} from "./data";
|
||||||
import {DATA_DIR} from "./utils";
|
import {DATA_DIR} from "./utils";
|
||||||
|
|
||||||
export const HOOK_LOG = false;
|
export const HOOK_LOG = true;
|
||||||
|
|
||||||
export const ALLOW_SEND_TEMP_MSG = false;
|
export const ALLOW_SEND_TEMP_MSG = false;
|
||||||
|
|
||||||
|
@ -4,16 +4,18 @@ import path from "node:path";
|
|||||||
import {DATA_DIR, truncateString} from "./index";
|
import {DATA_DIR, truncateString} from "./index";
|
||||||
import {getConfigUtil} from "../config";
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const logFileName = `llonebot-${date.toLocaleString("zh-CN")}.log`.replace(/\//g, "-").replace(/:/g, "-");
|
||||||
|
const logDir = path.join(DATA_DIR, "logs");
|
||||||
|
if (!fs.existsSync(logDir)) {
|
||||||
|
fs.mkdirSync(logDir, {recursive: true});
|
||||||
|
}
|
||||||
|
|
||||||
export function log(...msg: any[]) {
|
export function log(...msg: any[]) {
|
||||||
if (!getConfigUtil().getConfig().log) {
|
if (!getConfigUtil().getConfig().log) {
|
||||||
return //console.log(...msg);
|
return //console.log(...msg);
|
||||||
}
|
}
|
||||||
let currentDateTime = new Date().toLocaleString();
|
|
||||||
const date = new Date();
|
|
||||||
const year = date.getFullYear();
|
|
||||||
const month = date.getMonth() + 1;
|
|
||||||
const day = date.getDate();
|
|
||||||
const currentDate = `${year}-${month}-${day}`;
|
|
||||||
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
||||||
let logMsg = "";
|
let logMsg = "";
|
||||||
for (let msgItem of msg) {
|
for (let msgItem of msg) {
|
||||||
@ -25,10 +27,11 @@ export function log(...msg: any[]) {
|
|||||||
}
|
}
|
||||||
logMsg += msgItem + " ";
|
logMsg += msgItem + " ";
|
||||||
}
|
}
|
||||||
|
let currentDateTime = new Date().toLocaleString();
|
||||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||||
// sendLog(...msg);
|
// sendLog(...msg);
|
||||||
// console.log(msg)
|
// console.log(msg)
|
||||||
fs.appendFile(path.join(DATA_DIR, `llonebot-${currentDate}.log`), logMsg, (err: any) => {
|
fs.appendFile(path.join(logDir, logFileName), logMsg, (err: any) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -389,24 +389,29 @@ function onLoad() {
|
|||||||
selfInfo.nick = selfInfo.uin;
|
selfInfo.nick = selfInfo.uin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("retry get self info", e);
|
log("retry get self info", e);
|
||||||
|
selfInfo.uin = globalThis.authData?.uin;
|
||||||
|
selfInfo.uid = globalThis.authData?.uid;
|
||||||
|
selfInfo.nick = selfInfo.uin;
|
||||||
}
|
}
|
||||||
log("self info", selfInfo);
|
log("self info", selfInfo, globalThis.authData);
|
||||||
if (selfInfo.uin) {
|
if (selfInfo.uin) {
|
||||||
|
async function getUserNick(){
|
||||||
try {
|
try {
|
||||||
|
getSelfNickCount++;
|
||||||
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||||
log("self info", userInfo);
|
log("self info", userInfo);
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
selfInfo.nick = userInfo.nick;
|
selfInfo.nick = userInfo.nick;
|
||||||
} else {
|
return
|
||||||
getSelfNickCount++;
|
|
||||||
if (getSelfNickCount < 10) {
|
|
||||||
return setTimeout(init, 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("get self nickname failed", e.toString());
|
log("get self nickname failed", e.stack);
|
||||||
return setTimeout(init, 1000);
|
|
||||||
}
|
}
|
||||||
|
if (getSelfNickCount < 10) {
|
||||||
|
return setTimeout(getUserNick, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getUserNick().then()
|
||||||
start().then();
|
start().then();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(init, 1000)
|
setTimeout(init, 1000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user