diff --git a/src/common/utils/LRUCache.ts b/src/common/utils/LRUCache.ts index 6e7f8343..1d947820 100644 --- a/src/common/utils/LRUCache.ts +++ b/src/common/utils/LRUCache.ts @@ -1,4 +1,4 @@ -import { logError, logDebug } from "@/common/utils/log"; +import { logError, logDebug } from '@/common/utils/log'; type group_id = number; type user_id = number; @@ -45,7 +45,7 @@ class LRU { // 移除LRU节点 private removeLRUNode(node: cacheNode) { logDebug( - "removeLRUNode", + 'removeLRUNode', node.groupId, node.userId, node.value, @@ -74,19 +74,19 @@ class LRU { if (!removeObject[current.groupId]) removeObject[current.groupId] = []; removeObject[current.groupId].push({ userId: current.userId, value: current.value }); // 删除LRU节点 - delete this.cache[current.groupId][current.userId] + delete this.cache[current.groupId][current.userId]; current = current.prev; totalNodeNum++; - this.currentSize-- + this.currentSize--; } if (!totalNodeNum) return; // 跟新链表指向 - if (current) { current.next = null } else { this.head = null } - this.tail = current + if (current) { current.next = null; } else { this.head = null; } + this.tail = current; - this.onFuncs.forEach(func => func(removeObject)) + this.onFuncs.forEach(func => func(removeObject)); } private addNode(node: cacheNode) { diff --git a/src/common/utils/db.ts b/src/common/utils/db.ts index c0fa6c2b..82ac9ada 100644 --- a/src/common/utils/db.ts +++ b/src/common/utils/db.ts @@ -124,45 +124,45 @@ class DBUtil extends DBUtilBase { Object.entries(nodeObject).forEach(async ([_groupId, datas]) => { const userIds = datas.map(v => v.userId); - const groupId = Number(_groupId) + const groupId = Number(_groupId); logDebug('插入发言时间', _groupId); await this.createGroupInfoTimeTableIfNotExist(groupId); const needCreatUsers = await this.getNeedCreatList(groupId, userIds); const updateList = needCreatUsers.length > 0 ? datas.filter(user => !needCreatUsers.includes(user.userId)) : datas; - const insertList = needCreatUsers.map(userId => datas.find(e => userId == e.userId)!) + const insertList = needCreatUsers.map(userId => datas.find(e => userId == e.userId)!); - logDebug(`updateList`, updateList); - logDebug(`insertList`, insertList) + logDebug('updateList', updateList); + logDebug('insertList', insertList); if (insertList.length) { - const insertSql = `INSERT INTO "${groupId}" (last_sent_time, user_id) VALUES ${insertList.map(() => '(?, ?)').join(', ')};` + const insertSql = `INSERT INTO "${groupId}" (last_sent_time, user_id) VALUES ${insertList.map(() => '(?, ?)').join(', ')};`; this.db!.all(insertSql, insertList.map(v => [v.value, v.userId]).flat(), err => { if (err) { - logError(`群 ${groupId} 插入失败`) - logError(`更新Sql : ${insertSql}`) + logError(`群 ${groupId} 插入失败`); + logError(`更新Sql : ${insertSql}`); } - }) + }); } if (updateList.length) { const updateSql = `UPDATE "${groupId}" SET last_sent_time = CASE ` + - updateList.map(v => `WHEN user_id = ${v.userId} THEN ${v.value}`).join(" ") + - " ELSE last_sent_time END WHERE user_id IN " + - `(${updateList.map(v => v.userId).join(", ")});` + updateList.map(v => `WHEN user_id = ${v.userId} THEN ${v.value}`).join(' ') + + ' ELSE last_sent_time END WHERE user_id IN ' + + `(${updateList.map(v => v.userId).join(', ')});`; this.db!.all(updateSql, [], err => { if (err) { - logError(`群 ${groupId} 跟新失败`) - logError(`更新Sql : ${updateSql}`) + logError(`群 ${groupId} 跟新失败`); + logError(`更新Sql : ${updateSql}`); } - }) + }); } - }) + }); }); @@ -187,14 +187,14 @@ class DBUtil extends DBUtilBase { const needCreatUsers = unhas.filter(userId => !has.includes(userId)); if (needCreatUsers.length == 0) { - logDebug('数据库全部命中') + logDebug('数据库全部命中'); } else { - logDebug('数据库未全部命中') + logDebug('数据库未全部命中'); } - resolve(needCreatUsers) - }) - }) + resolve(needCreatUsers); + }); + }); } @@ -439,7 +439,7 @@ class DBUtil extends DBUtilBase { logError('查询发言时间失败', groupId); return resolve(cache.map(e => ({ ...e, join_time: 0 }))); } - Object.assign(rows, cache) + Object.assign(rows, cache); logDebug('查询发言时间成功', groupId, rows); resolve(rows); }); @@ -465,8 +465,8 @@ class DBUtil extends DBUtilBase { (err) => { if (err) logError(err), - Promise.reject(), - logError('插入入群时间失败', userId, groupId); + Promise.reject(), + logError('插入入群时间失败', userId, groupId); } ); diff --git a/src/common/utils/request.ts b/src/common/utils/request.ts index a74337d8..b2653d38 100644 --- a/src/common/utils/request.ts +++ b/src/common/utils/request.ts @@ -7,7 +7,7 @@ export class RequestUtil { static async HttpsGetCookies(url: string): Promise<{ [key: string]: string }> { const client = url.startsWith('https') ? https : http; return new Promise((resolve, reject) => { - let req = client.get(url, (res) => { + const req = client.get(url, (res) => { let cookies: { [key: string]: string } = {}; const handleRedirect = (res: http.IncomingMessage) => { //console.log(res.headers.location); @@ -44,7 +44,7 @@ export class RequestUtil { }); } }); - req.on('error', (error: any) => { + req.on('error', (error: any) => { reject(error); }); }); diff --git a/src/core/src/data.ts b/src/core/src/data.ts index 5af23381..24965a3c 100644 --- a/src/core/src/data.ts +++ b/src/core/src/data.ts @@ -1,9 +1,9 @@ import { type Friend, type Group, - type GroupMember, GroupNotify, + type GroupMember, type SelfInfo, - BuddyCategoryType + type BuddyCategoryType } from './entities'; import { isNumeric } from '@/common/utils/helper'; import { NTQQGroupApi } from '@/core/apis'; diff --git a/src/onebot11/action/msg/SendMsg/index.ts b/src/onebot11/action/msg/SendMsg/index.ts index 0a943dba..3971a456 100644 --- a/src/onebot11/action/msg/SendMsg/index.ts +++ b/src/onebot11/action/msg/SendMsg/index.ts @@ -145,7 +145,7 @@ export class SendMsg extends BaseAction { } protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> { - let { peer, group } = await createContext(payload, this.contextMode); + const { peer, group } = await createContext(payload, this.contextMode); const messages = normalize( payload.message, diff --git a/src/onebot11/server/ws/ReverseWebsocket.ts b/src/onebot11/server/ws/ReverseWebsocket.ts index bd96a1b0..08792ce7 100644 --- a/src/onebot11/server/ws/ReverseWebsocket.ts +++ b/src/onebot11/server/ws/ReverseWebsocket.ts @@ -87,7 +87,7 @@ export class ReverseWebsocket { 'X-Self-ID': selfInfo.uin, 'Authorization': `Bearer ${token}`, 'x-client-role': 'Universal', // koishi-adapter-onebot 需要这个字段 - "User-Agent": "OneBot/11", + 'User-Agent': 'OneBot/11', } }); registerWsEventSender(this.websocket); diff --git a/src/onebot11/types/message.ts b/src/onebot11/types/message.ts index fd56458a..6cf19cff 100644 --- a/src/onebot11/types/message.ts +++ b/src/onebot11/types/message.ts @@ -60,7 +60,7 @@ export enum OB11MessageDataType { dice = 'dice', RPS = 'rps', miniapp = 'miniapp',//json类 - Location = "location" + Location = 'location' } export interface OB11MessageMFace {