mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
chore: improve code quality
This commit is contained in:
parent
970f1a98ec
commit
04b2a323a7
@ -2,8 +2,9 @@ import fs from 'fs'
|
||||
import path from 'node:path'
|
||||
import { getConfigUtil } from '../config'
|
||||
import { LOG_DIR } from '../globalVars'
|
||||
import { Dict } from 'cosmokit'
|
||||
|
||||
function truncateString(obj: any, maxLength = 500) {
|
||||
function truncateString(obj: Dict | null, maxLength = 500) {
|
||||
if (obj !== null && typeof obj === 'object') {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
if (typeof obj[key] === 'string') {
|
||||
@ -22,7 +23,7 @@ function truncateString(obj: any, maxLength = 500) {
|
||||
|
||||
export const logFileName = `llonebot-${new Date().toLocaleString('zh-CN')}.log`.replace(/\//g, '-').replace(/:/g, '-')
|
||||
|
||||
export function log(...msg: any[]) {
|
||||
export function log(...msg: unknown[]) {
|
||||
if (!getConfigUtil().getConfig().log) {
|
||||
return
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { QQLevel } from '@/ntqqapi/types'
|
||||
import { Dict } from 'cosmokit'
|
||||
|
||||
export function isNumeric(str: string) {
|
||||
return /^\d+$/.test(str)
|
||||
@ -16,7 +17,7 @@ export function getBuildVersion(): number {
|
||||
}
|
||||
|
||||
/** 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象 */
|
||||
export function mergeNewProperties(newObj: any, oldObj: any) {
|
||||
export function mergeNewProperties(newObj: Dict, oldObj: Dict) {
|
||||
Object.keys(newObj).forEach((key) => {
|
||||
// 如果老对象不存在当前属性,则直接复制
|
||||
if (!oldObj.hasOwnProperty(key)) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { User, UserDetailInfoListenerArg } from '@/ntqqapi/types'
|
||||
|
||||
interface IProfileListener {
|
||||
export interface IProfileListener {
|
||||
onProfileSimpleChanged(...args: unknown[]): void
|
||||
|
||||
onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void
|
||||
@ -13,32 +13,3 @@ interface IProfileListener {
|
||||
|
||||
onStrangerRemarkChanged(...args: unknown[]): void
|
||||
}
|
||||
|
||||
export interface NodeIKernelProfileListener extends IProfileListener {
|
||||
new(listener: IProfileListener): NodeIKernelProfileListener
|
||||
}
|
||||
|
||||
export class ProfileListener implements IProfileListener {
|
||||
onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void {
|
||||
|
||||
}
|
||||
onProfileSimpleChanged(...args: unknown[]) {
|
||||
|
||||
}
|
||||
|
||||
onProfileDetailInfoChanged(profile: User) {
|
||||
|
||||
}
|
||||
|
||||
onStatusUpdate(...args: unknown[]) {
|
||||
|
||||
}
|
||||
|
||||
onSelfStatusChanged(...args: unknown[]) {
|
||||
|
||||
}
|
||||
|
||||
onStrangerRemarkChanged(...args: unknown[]) {
|
||||
|
||||
}
|
||||
}
|
@ -9,10 +9,10 @@ export interface NodeIKernelProfileLikeService {
|
||||
setBuddyProfileLike(...args: unknown[]): { result: number, errMsg: string, succCounts: number }
|
||||
|
||||
getBuddyProfileLike(req: BuddyProfileLikeReq): Promise<GeneralCallResult & {
|
||||
'info': {
|
||||
'userLikeInfos': Array<any>,
|
||||
'friendMaxVotes': number,
|
||||
'start': number
|
||||
info: {
|
||||
userLikeInfos: Array<unknown>,
|
||||
friendMaxVotes: number,
|
||||
start: number
|
||||
}
|
||||
}>
|
||||
|
||||
|
@ -8,7 +8,7 @@ interface Payload {
|
||||
export class MarkMsgAsRead extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_MarkMsgAsRead
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
protected async _handle() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { ActionName } from '../types'
|
||||
export default class GetGuildList extends BaseAction<null, null> {
|
||||
actionName = ActionName.GetGuildList
|
||||
|
||||
protected async _handle(payload: null): Promise<null> {
|
||||
protected async _handle() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ interface Payload {
|
||||
is_dismiss: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupLeave extends BaseAction<Payload, any> {
|
||||
export default class SetGroupLeave extends BaseAction<Payload, void> {
|
||||
actionName = ActionName.SetGroupLeave
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
protected async _handle(payload: Payload) {
|
||||
try {
|
||||
await this.ctx.ntGroupApi.quitGroup(payload.group_id.toString())
|
||||
} catch (e) {
|
||||
|
@ -5,13 +5,15 @@ import { getConfigUtil } from '@/common/config'
|
||||
|
||||
export class GetConfigAction extends BaseAction<null, Config> {
|
||||
actionName = ActionName.GetConfig
|
||||
protected async _handle(payload: null): Promise<Config> {
|
||||
|
||||
protected async _handle(): Promise<Config> {
|
||||
return getConfigUtil().getConfig()
|
||||
}
|
||||
}
|
||||
|
||||
export class SetConfigAction extends BaseAction<Config, void> {
|
||||
actionName = ActionName.SetConfig
|
||||
|
||||
protected async _handle(payload: Config): Promise<void> {
|
||||
getConfigUtil().setConfig(payload)
|
||||
}
|
||||
|
@ -13,13 +13,14 @@ interface Payload {
|
||||
|
||||
export default class GetEvent extends BaseAction<Payload, PostEventType[]> {
|
||||
actionName = ActionName.GetEvent
|
||||
|
||||
protected async _handle(payload: Payload): Promise<PostEventType[]> {
|
||||
let key = ''
|
||||
if (payload.key) {
|
||||
key = payload.key
|
||||
}
|
||||
let timeout = parseInt(payload.timeout?.toString()) || 0
|
||||
let evts = await getHttpEvent(key, timeout)
|
||||
const timeout = parseInt(payload.timeout?.toString()) || 0
|
||||
const evts = await getHttpEvent(key, timeout)
|
||||
return evts
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ interface ReturnType {
|
||||
export default class CanSendRecord extends BaseAction<any, ReturnType> {
|
||||
actionName = ActionName.CanSendRecord
|
||||
|
||||
protected async _handle(payload: void): Promise<ReturnType> {
|
||||
protected async _handle() {
|
||||
return {
|
||||
yes: true,
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ import { OB11Version } from '../../types'
|
||||
import { ActionName } from '../types'
|
||||
import { version } from '../../../version'
|
||||
|
||||
export default class GetVersionInfo extends BaseAction<any, OB11Version> {
|
||||
export default class GetVersionInfo extends BaseAction<null, OB11Version> {
|
||||
actionName = ActionName.GetVersionInfo
|
||||
|
||||
protected async _handle(payload: any): Promise<OB11Version> {
|
||||
protected async _handle(): Promise<OB11Version> {
|
||||
return {
|
||||
app_name: 'LLOneBot',
|
||||
protocol_version: 'v11',
|
||||
|
@ -33,8 +33,8 @@ export async function getHttpEvent(userKey: string, timeout = 0) {
|
||||
|
||||
// 清除过时的user,5分钟没访问过的user将被删除
|
||||
const now = Date.now()
|
||||
for (let key in httpUser) {
|
||||
let user = httpUser[key]
|
||||
for (const key in httpUser) {
|
||||
const user = httpUser[key]
|
||||
if (now - user.lastAccessTime > 1000 * 60 * 5) {
|
||||
delete httpUser[key]
|
||||
}
|
||||
@ -55,7 +55,7 @@ export async function getHttpEvent(userKey: string, timeout = 0) {
|
||||
}
|
||||
// 取数据
|
||||
for (let i = 0; i < eventList.length; i++) {
|
||||
let evt = eventList[i]
|
||||
const evt = eventList[i]
|
||||
if (evt.seq > user.userSeq) {
|
||||
toRetEvent.push(evt.event)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user