mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
parent
029842ca08
commit
a66e48dfb0
@ -2,25 +2,27 @@ import { BaseAction, Schema } from '../BaseAction'
|
||||
import { OB11GroupMember } from '../../types'
|
||||
import { OB11Entities } from '../../entities'
|
||||
import { ActionName } from '../types'
|
||||
import { calcQQLevel } from '@/common/utils/misc'
|
||||
import { calcQQLevel, parseBool } from '@/common/utils/misc'
|
||||
|
||||
interface Payload {
|
||||
group_id: number | string
|
||||
user_id: number | string
|
||||
no_cache: boolean
|
||||
}
|
||||
|
||||
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||
actionName = ActionName.GetGroupMemberInfo
|
||||
payloadSchema = Schema.object({
|
||||
group_id: Schema.union([Number, String]).required(),
|
||||
user_id: Schema.union([Number, String]).required()
|
||||
user_id: Schema.union([Number, String]).required(),
|
||||
no_cache: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(false)
|
||||
})
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
const groupCode = payload.group_id.toString()
|
||||
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
|
||||
if (!uid) throw new Error('无法获取用户信息')
|
||||
const member = await this.ctx.ntGroupApi.getGroupMember(groupCode, uid)
|
||||
const member = await this.ctx.ntGroupApi.getGroupMember(groupCode, uid, payload.no_cache)
|
||||
if (member) {
|
||||
const ret = OB11Entities.groupMember(groupCode, member)
|
||||
const date = Math.round(Date.now() / 1000)
|
||||
|
@ -134,11 +134,13 @@ namespace OB11Http {
|
||||
|
||||
class OB11HttpPost {
|
||||
private disposeInterval?: () => void
|
||||
private activated = false
|
||||
|
||||
constructor(protected ctx: Context, public config: OB11HttpPost.Config) {
|
||||
}
|
||||
|
||||
public start() {
|
||||
this.activated = true
|
||||
if (this.config.enableHttpHeart && !this.disposeInterval) {
|
||||
this.disposeInterval = this.ctx.setInterval(() => {
|
||||
// ws的心跳是ws自己维护的
|
||||
@ -148,10 +150,14 @@ class OB11HttpPost {
|
||||
}
|
||||
|
||||
public stop() {
|
||||
this.activated = false
|
||||
this.disposeInterval?.()
|
||||
}
|
||||
|
||||
public async emitEvent(event: OB11BaseEvent | OB11Message) {
|
||||
if (!this.activated) {
|
||||
return
|
||||
}
|
||||
const msgStr = JSON.stringify(event)
|
||||
const headers: Dict = {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -8,9 +8,7 @@ import {
|
||||
CHANNEL_SET_CONFIG,
|
||||
CHANNEL_UPDATE,
|
||||
} from './common/channels'
|
||||
|
||||
const { contextBridge } = require('electron')
|
||||
const { ipcRenderer } = require('electron')
|
||||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
|
||||
const llonebot = {
|
||||
log: (data: unknown) => {
|
||||
|
@ -25,9 +25,6 @@ async function onSettingWindowCreated(view: Element) {
|
||||
} else {
|
||||
Object.assign(config, { [key]: value })
|
||||
}
|
||||
if (!['heartInterval', 'token', 'ffmpeg'].includes(key)) {
|
||||
window.llonebot.setConfig(false, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,15 @@ export class SatoriServer {
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
if (this.wsClients.length > 0) {
|
||||
for (const socket of this.wsClients) {
|
||||
try {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
socket.close(1000)
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
if (this.wsServer) {
|
||||
const close = promisify(this.wsServer.close)
|
||||
await close.call(this.wsServer)
|
||||
|
Loading…
x
Reference in New Issue
Block a user