feat: /get_online_clients

This commit is contained in:
手瓜一十雪 2024-05-25 13:09:47 +08:00
parent 12ab6d4a7d
commit db93a8eed2
6 changed files with 535 additions and 10 deletions

View File

@ -6,6 +6,6 @@ QQ Version: Windows 9.9.10-23873 / Linux 3.2.7-23361
## 新增与调整
* 支持空间Cookies获取
* 新增API /get_online_clients
新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)

View File

@ -1,9 +0,0 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
export class GetOnlineClient extends BaseAction<void, Array<any>> {
actionName = ActionName.GetOnlineClient;
protected async _handle(payload: void) {
}
}

View File

@ -0,0 +1,19 @@
import { DeviceList } from '@/onebot11/main';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
no_cache: { type: 'boolean' },
}
} as const satisfies JSONSchema;
export class GetOnlineClient extends BaseAction<void, Array<any>> {
actionName = ActionName.GetOnlineClient;
protected async _handle(payload: void) {
return DeviceList;
}
}

View File

@ -32,10 +32,22 @@ import { logMessage, logNotice, logRequest } from '@/onebot11/log';
import { OB11Message } from '@/onebot11/types';
import { OB11LifeCycleEvent } from './event/meta/OB11LifeCycleEvent';
import { Data as SysData } from '@/proto/SysMessage';
import { Data as DeviceData } from '@/proto/SysMessage.DeviceChange';
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from './event/notice/OB11PokeEvent';
import { isEqual } from '@/common/utils/helper';
//下面几个其实应该移进Core-Data 缓存实现 但是现在在这里方便
//
export interface LineDevice {
app_id: string;
device_name: string;
device_kind: string;
}
export let DeviceList = new Array<LineDevice>();
//peer->cached(boolen)
const PokeCache = new Map<string, boolean>();
export class NapCatOnebot11 {
private bootTime: number = Date.now() / 1000; // 秒
@ -129,6 +141,18 @@ export class NapCatOnebot11 {
postOB11Event(pokeEvent);
}
}
if (MsgType == 528 && subType0 == 349) {
const sysDeviceMsg = DeviceData.fromBinary(Buffer.from(protobufData));
DeviceList = [];
sysDeviceMsg.event[0].content[0].devices.forEach(device => {
DeviceList.push({
app_id: '0',
device_name: device.deviceName,
device_kind: 'none'
})
// log('[设备列表] 设备名称: ' + device.deviceName);
});
}
// 未区分增加与减少
// if (MsgType == 34 && subType0 == 0) {
// const role = (await getGroupMember(peeruin, selfInfo.uin))?.role;

View File

@ -0,0 +1,491 @@
// @generated by protobuf-ts 2.9.4
// @generated from protobuf file "SysMessage.DeviceChange.proto" (package "SysMessage", syntax proto3)
// tslint:disable
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
import type { IBinaryWriter } from "@protobuf-ts/runtime";
import { WireType } from "@protobuf-ts/runtime";
import type { BinaryReadOptions } from "@protobuf-ts/runtime";
import type { IBinaryReader } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import type { PartialMessage } from "@protobuf-ts/runtime";
import { reflectionMergePartial } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
/**
* @generated from protobuf message SysMessage.Data
*/
export interface Data {
/**
* @generated from protobuf field: repeated SysMessage.Header header = 1;
*/
header: Header[];
/**
* @generated from protobuf field: repeated SysMessage.Body body = 2;
*/
body: Body[];
/**
* @generated from protobuf field: repeated SysMessage.Event event = 3;
*/
event: Event[];
}
/**
* @generated from protobuf message SysMessage.Event
*/
export interface Event {
/**
* @generated from protobuf field: repeated SysMessage.Content content = 2;
*/
content: Content[];
}
/**
* @generated from protobuf message SysMessage.Devices
*/
export interface Devices {
/**
* @generated from protobuf field: string deviceName = 5;
*/
deviceName: string;
/**
* @generated from protobuf field: string appname = 9;
*/
appname: string;
}
/**
* @generated from protobuf message SysMessage.Content
*/
export interface Content {
/**
* @generated from protobuf field: repeated SysMessage.Devices devices = 5;
*/
devices: Devices[];
}
/**
* @generated from protobuf message SysMessage.Header
*/
export interface Header {
/**
* @generated from protobuf field: uint32 PeerNumber = 1 [json_name = "PeerNumber"];
*/
peerNumber: number;
/**
* @generated from protobuf field: string PeerString = 2 [json_name = "PeerString"];
*/
peerString: string;
/**
* @generated from protobuf field: uint32 Uin = 5 [json_name = "Uin"];
*/
uin: number;
/**
* @generated from protobuf field: optional string Uid = 6 [json_name = "Uid"];
*/
uid?: string;
}
/**
* @generated from protobuf message SysMessage.Body
*/
export interface Body {
/**
* @generated from protobuf field: uint32 MsgType = 1 [json_name = "MsgType"];
*/
msgType: number;
/**
* @generated from protobuf field: uint32 SubType_0 = 2 [json_name = "SubType0"];
*/
subType0: number;
/**
* @generated from protobuf field: uint32 SubType_1 = 3 [json_name = "SubType1"];
*/
subType1: number;
/**
* @generated from protobuf field: uint32 MsgSeq = 5 [json_name = "MsgSeq"];
*/
msgSeq: number;
/**
* @generated from protobuf field: uint32 Time = 6 [json_name = "Time"];
*/
time: number;
/**
* @generated from protobuf field: uint64 MsgID = 12 [json_name = "MsgID"];
*/
msgID: bigint;
/**
* @generated from protobuf field: uint32 Other = 13 [json_name = "Other"];
*/
other: number;
}
// @generated message type with reflection information, may provide speed optimized methods
class Data$Type extends MessageType<Data> {
constructor() {
super("SysMessage.Data", [
{ no: 1, name: "header", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => Header },
{ no: 2, name: "body", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => Body },
{ no: 3, name: "event", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => Event }
]);
}
create(value?: PartialMessage<Data>): Data {
const message = globalThis.Object.create((this.messagePrototype!));
message.header = [];
message.body = [];
message.event = [];
if (value !== undefined)
reflectionMergePartial<Data>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Data): Data {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* repeated SysMessage.Header header */ 1:
message.header.push(Header.internalBinaryRead(reader, reader.uint32(), options));
break;
case /* repeated SysMessage.Body body */ 2:
message.body.push(Body.internalBinaryRead(reader, reader.uint32(), options));
break;
case /* repeated SysMessage.Event event */ 3:
message.event.push(Event.internalBinaryRead(reader, reader.uint32(), options));
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Data, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* repeated SysMessage.Header header = 1; */
for (let i = 0; i < message.header.length; i++)
Header.internalBinaryWrite(message.header[i], writer.tag(1, WireType.LengthDelimited).fork(), options).join();
/* repeated SysMessage.Body body = 2; */
for (let i = 0; i < message.body.length; i++)
Body.internalBinaryWrite(message.body[i], writer.tag(2, WireType.LengthDelimited).fork(), options).join();
/* repeated SysMessage.Event event = 3; */
for (let i = 0; i < message.event.length; i++)
Event.internalBinaryWrite(message.event[i], writer.tag(3, WireType.LengthDelimited).fork(), options).join();
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message SysMessage.Data
*/
export const Data = new Data$Type();
// @generated message type with reflection information, may provide speed optimized methods
class Event$Type extends MessageType<Event> {
constructor() {
super("SysMessage.Event", [
{ no: 2, name: "content", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => Content }
]);
}
create(value?: PartialMessage<Event>): Event {
const message = globalThis.Object.create((this.messagePrototype!));
message.content = [];
if (value !== undefined)
reflectionMergePartial<Event>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Event): Event {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* repeated SysMessage.Content content */ 2:
message.content.push(Content.internalBinaryRead(reader, reader.uint32(), options));
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Event, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* repeated SysMessage.Content content = 2; */
for (let i = 0; i < message.content.length; i++)
Content.internalBinaryWrite(message.content[i], writer.tag(2, WireType.LengthDelimited).fork(), options).join();
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message SysMessage.Event
*/
export const Event = new Event$Type();
// @generated message type with reflection information, may provide speed optimized methods
class Devices$Type extends MessageType<Devices> {
constructor() {
super("SysMessage.Devices", [
{ no: 5, name: "deviceName", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
{ no: 9, name: "appname", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
]);
}
create(value?: PartialMessage<Devices>): Devices {
const message = globalThis.Object.create((this.messagePrototype!));
message.deviceName = "";
message.appname = "";
if (value !== undefined)
reflectionMergePartial<Devices>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Devices): Devices {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* string deviceName */ 5:
message.deviceName = reader.string();
break;
case /* string appname */ 9:
message.appname = reader.string();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Devices, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* string deviceName = 5; */
if (message.deviceName !== "")
writer.tag(5, WireType.LengthDelimited).string(message.deviceName);
/* string appname = 9; */
if (message.appname !== "")
writer.tag(9, WireType.LengthDelimited).string(message.appname);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message SysMessage.Devices
*/
export const Devices = new Devices$Type();
// @generated message type with reflection information, may provide speed optimized methods
class Content$Type extends MessageType<Content> {
constructor() {
super("SysMessage.Content", [
{ no: 5, name: "devices", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => Devices }
]);
}
create(value?: PartialMessage<Content>): Content {
const message = globalThis.Object.create((this.messagePrototype!));
message.devices = [];
if (value !== undefined)
reflectionMergePartial<Content>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Content): Content {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* repeated SysMessage.Devices devices */ 5:
message.devices.push(Devices.internalBinaryRead(reader, reader.uint32(), options));
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Content, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* repeated SysMessage.Devices devices = 5; */
for (let i = 0; i < message.devices.length; i++)
Devices.internalBinaryWrite(message.devices[i], writer.tag(5, WireType.LengthDelimited).fork(), options).join();
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message SysMessage.Content
*/
export const Content = new Content$Type();
// @generated message type with reflection information, may provide speed optimized methods
class Header$Type extends MessageType<Header> {
constructor() {
super("SysMessage.Header", [
{ no: 1, name: "PeerNumber", kind: "scalar", jsonName: "PeerNumber", T: 13 /*ScalarType.UINT32*/ },
{ no: 2, name: "PeerString", kind: "scalar", jsonName: "PeerString", T: 9 /*ScalarType.STRING*/ },
{ no: 5, name: "Uin", kind: "scalar", jsonName: "Uin", T: 13 /*ScalarType.UINT32*/ },
{ no: 6, name: "Uid", kind: "scalar", jsonName: "Uid", opt: true, T: 9 /*ScalarType.STRING*/ }
]);
}
create(value?: PartialMessage<Header>): Header {
const message = globalThis.Object.create((this.messagePrototype!));
message.peerNumber = 0;
message.peerString = "";
message.uin = 0;
if (value !== undefined)
reflectionMergePartial<Header>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Header): Header {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* uint32 PeerNumber = 1 [json_name = "PeerNumber"];*/ 1:
message.peerNumber = reader.uint32();
break;
case /* string PeerString = 2 [json_name = "PeerString"];*/ 2:
message.peerString = reader.string();
break;
case /* uint32 Uin = 5 [json_name = "Uin"];*/ 5:
message.uin = reader.uint32();
break;
case /* optional string Uid = 6 [json_name = "Uid"];*/ 6:
message.uid = reader.string();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Header, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* uint32 PeerNumber = 1 [json_name = "PeerNumber"]; */
if (message.peerNumber !== 0)
writer.tag(1, WireType.Varint).uint32(message.peerNumber);
/* string PeerString = 2 [json_name = "PeerString"]; */
if (message.peerString !== "")
writer.tag(2, WireType.LengthDelimited).string(message.peerString);
/* uint32 Uin = 5 [json_name = "Uin"]; */
if (message.uin !== 0)
writer.tag(5, WireType.Varint).uint32(message.uin);
/* optional string Uid = 6 [json_name = "Uid"]; */
if (message.uid !== undefined)
writer.tag(6, WireType.LengthDelimited).string(message.uid);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message SysMessage.Header
*/
export const Header = new Header$Type();
// @generated message type with reflection information, may provide speed optimized methods
class Body$Type extends MessageType<Body> {
constructor() {
super("SysMessage.Body", [
{ no: 1, name: "MsgType", kind: "scalar", jsonName: "MsgType", T: 13 /*ScalarType.UINT32*/ },
{ no: 2, name: "SubType_0", kind: "scalar", jsonName: "SubType0", T: 13 /*ScalarType.UINT32*/ },
{ no: 3, name: "SubType_1", kind: "scalar", jsonName: "SubType1", T: 13 /*ScalarType.UINT32*/ },
{ no: 5, name: "MsgSeq", kind: "scalar", jsonName: "MsgSeq", T: 13 /*ScalarType.UINT32*/ },
{ no: 6, name: "Time", kind: "scalar", jsonName: "Time", T: 13 /*ScalarType.UINT32*/ },
{ no: 12, name: "MsgID", kind: "scalar", jsonName: "MsgID", T: 4 /*ScalarType.UINT64*/, L: 0 /*LongType.BIGINT*/ },
{ no: 13, name: "Other", kind: "scalar", jsonName: "Other", T: 13 /*ScalarType.UINT32*/ }
]);
}
create(value?: PartialMessage<Body>): Body {
const message = globalThis.Object.create((this.messagePrototype!));
message.msgType = 0;
message.subType0 = 0;
message.subType1 = 0;
message.msgSeq = 0;
message.time = 0;
message.msgID = 0n;
message.other = 0;
if (value !== undefined)
reflectionMergePartial<Body>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Body): Body {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* uint32 MsgType = 1 [json_name = "MsgType"];*/ 1:
message.msgType = reader.uint32();
break;
case /* uint32 SubType_0 = 2 [json_name = "SubType0"];*/ 2:
message.subType0 = reader.uint32();
break;
case /* uint32 SubType_1 = 3 [json_name = "SubType1"];*/ 3:
message.subType1 = reader.uint32();
break;
case /* uint32 MsgSeq = 5 [json_name = "MsgSeq"];*/ 5:
message.msgSeq = reader.uint32();
break;
case /* uint32 Time = 6 [json_name = "Time"];*/ 6:
message.time = reader.uint32();
break;
case /* uint64 MsgID = 12 [json_name = "MsgID"];*/ 12:
message.msgID = reader.uint64().toBigInt();
break;
case /* uint32 Other = 13 [json_name = "Other"];*/ 13:
message.other = reader.uint32();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Body, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* uint32 MsgType = 1 [json_name = "MsgType"]; */
if (message.msgType !== 0)
writer.tag(1, WireType.Varint).uint32(message.msgType);
/* uint32 SubType_0 = 2 [json_name = "SubType0"]; */
if (message.subType0 !== 0)
writer.tag(2, WireType.Varint).uint32(message.subType0);
/* uint32 SubType_1 = 3 [json_name = "SubType1"]; */
if (message.subType1 !== 0)
writer.tag(3, WireType.Varint).uint32(message.subType1);
/* uint32 MsgSeq = 5 [json_name = "MsgSeq"]; */
if (message.msgSeq !== 0)
writer.tag(5, WireType.Varint).uint32(message.msgSeq);
/* uint32 Time = 6 [json_name = "Time"]; */
if (message.time !== 0)
writer.tag(6, WireType.Varint).uint32(message.time);
/* uint64 MsgID = 12 [json_name = "MsgID"]; */
if (message.msgID !== 0n)
writer.tag(12, WireType.Varint).uint64(message.msgID);
/* uint32 Other = 13 [json_name = "Other"]; */
if (message.other !== 0)
writer.tag(13, WireType.Varint).uint32(message.other);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message SysMessage.Body
*/
export const Body = new Body$Type();