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 { OB11GroupMember } from '../../types'
|
||||||
import { OB11Entities } from '../../entities'
|
import { OB11Entities } from '../../entities'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { calcQQLevel } from '@/common/utils/misc'
|
import { calcQQLevel, parseBool } from '@/common/utils/misc'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number | string
|
group_id: number | string
|
||||||
user_id: number | string
|
user_id: number | string
|
||||||
|
no_cache: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||||
actionName = ActionName.GetGroupMemberInfo
|
actionName = ActionName.GetGroupMemberInfo
|
||||||
payloadSchema = Schema.object({
|
payloadSchema = Schema.object({
|
||||||
group_id: Schema.union([Number, String]).required(),
|
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) {
|
protected async _handle(payload: Payload) {
|
||||||
const groupCode = payload.group_id.toString()
|
const groupCode = payload.group_id.toString()
|
||||||
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
|
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
|
||||||
if (!uid) throw new Error('无法获取用户信息')
|
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) {
|
if (member) {
|
||||||
const ret = OB11Entities.groupMember(groupCode, member)
|
const ret = OB11Entities.groupMember(groupCode, member)
|
||||||
const date = Math.round(Date.now() / 1000)
|
const date = Math.round(Date.now() / 1000)
|
||||||
|
@ -134,11 +134,13 @@ namespace OB11Http {
|
|||||||
|
|
||||||
class OB11HttpPost {
|
class OB11HttpPost {
|
||||||
private disposeInterval?: () => void
|
private disposeInterval?: () => void
|
||||||
|
private activated = false
|
||||||
|
|
||||||
constructor(protected ctx: Context, public config: OB11HttpPost.Config) {
|
constructor(protected ctx: Context, public config: OB11HttpPost.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
|
this.activated = true
|
||||||
if (this.config.enableHttpHeart && !this.disposeInterval) {
|
if (this.config.enableHttpHeart && !this.disposeInterval) {
|
||||||
this.disposeInterval = this.ctx.setInterval(() => {
|
this.disposeInterval = this.ctx.setInterval(() => {
|
||||||
// ws的心跳是ws自己维护的
|
// ws的心跳是ws自己维护的
|
||||||
@ -148,10 +150,14 @@ class OB11HttpPost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public stop() {
|
public stop() {
|
||||||
|
this.activated = false
|
||||||
this.disposeInterval?.()
|
this.disposeInterval?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async emitEvent(event: OB11BaseEvent | OB11Message) {
|
public async emitEvent(event: OB11BaseEvent | OB11Message) {
|
||||||
|
if (!this.activated) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const msgStr = JSON.stringify(event)
|
const msgStr = JSON.stringify(event)
|
||||||
const headers: Dict = {
|
const headers: Dict = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -8,9 +8,7 @@ import {
|
|||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_UPDATE,
|
CHANNEL_UPDATE,
|
||||||
} from './common/channels'
|
} from './common/channels'
|
||||||
|
import { contextBridge, ipcRenderer } from 'electron'
|
||||||
const { contextBridge } = require('electron')
|
|
||||||
const { ipcRenderer } = require('electron')
|
|
||||||
|
|
||||||
const llonebot = {
|
const llonebot = {
|
||||||
log: (data: unknown) => {
|
log: (data: unknown) => {
|
||||||
|
@ -25,9 +25,6 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
} else {
|
} else {
|
||||||
Object.assign(config, { [key]: value })
|
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() {
|
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) {
|
if (this.wsServer) {
|
||||||
const close = promisify(this.wsServer.close)
|
const close = promisify(this.wsServer.close)
|
||||||
await close.call(this.wsServer)
|
await close.call(this.wsServer)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user