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 {DATA_DIR} from "./utils";
|
||||
|
||||
export const HOOK_LOG = false;
|
||||
export const HOOK_LOG = true;
|
||||
|
||||
export const ALLOW_SEND_TEMP_MSG = false;
|
||||
|
||||
|
@ -4,16 +4,18 @@ import path from "node:path";
|
||||
import {DATA_DIR, truncateString} from "./index";
|
||||
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[]) {
|
||||
if (!getConfigUtil().getConfig().log) {
|
||||
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})` : ""
|
||||
let logMsg = "";
|
||||
for (let msgItem of msg) {
|
||||
@ -25,10 +27,11 @@ export function log(...msg: any[]) {
|
||||
}
|
||||
logMsg += msgItem + " ";
|
||||
}
|
||||
let currentDateTime = new Date().toLocaleString();
|
||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||
// sendLog(...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;
|
||||
} catch (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) {
|
||||
async function getUserNick(){
|
||||
try {
|
||||
getSelfNickCount++;
|
||||
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||
log("self info", userInfo);
|
||||
if (userInfo) {
|
||||
selfInfo.nick = userInfo.nick;
|
||||
} else {
|
||||
getSelfNickCount++;
|
||||
if (getSelfNickCount < 10) {
|
||||
return setTimeout(init, 1000);
|
||||
}
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
log("get self nickname failed", e.toString());
|
||||
return setTimeout(init, 1000);
|
||||
log("get self nickname failed", e.stack);
|
||||
}
|
||||
if (getSelfNickCount < 10) {
|
||||
return setTimeout(getUserNick, 1000);
|
||||
}
|
||||
}
|
||||
getUserNick().then()
|
||||
start().then();
|
||||
} else {
|
||||
setTimeout(init, 1000)
|
||||
|
Loading…
x
Reference in New Issue
Block a user