This commit is contained in:
linyuchen
2024-04-15 00:09:08 +08:00
parent 0ef3e38d70
commit 356aba762c
218 changed files with 8465 additions and 5 deletions

View File

@@ -0,0 +1,16 @@
import { selfInfo } from '@/common/data';
export enum EventType {
META = 'meta_event',
REQUEST = 'request',
NOTICE = 'notice',
MESSAGE = 'message',
MESSAGE_SENT = 'message_sent',
}
export abstract class OB11BaseEvent {
time = Math.floor(Date.now() / 1000);
self_id = parseInt(selfInfo.uin);
post_type: EventType = EventType.META;
}

View File

@@ -0,0 +1,5 @@
import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
export abstract class OB11BaseMessageEvent extends OB11BaseEvent {
post_type = EventType.MESSAGE;
}

View File

@@ -0,0 +1,6 @@
import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
export abstract class OB11BaseMetaEvent extends OB11BaseEvent {
post_type = EventType.META;
meta_event_type: string;
}

View File

@@ -0,0 +1,21 @@
import { OB11BaseMetaEvent } from './OB11BaseMetaEvent';
interface HeartbeatStatus {
online: boolean | null,
good: boolean
}
export class OB11HeartbeatEvent extends OB11BaseMetaEvent {
meta_event_type = 'heartbeat';
status: HeartbeatStatus;
interval: number;
public constructor(isOnline: boolean, isGood: boolean, interval: number) {
super();
this.interval = interval;
this.status = {
online: isOnline,
good: isGood
};
}
}

View File

@@ -0,0 +1,17 @@
import { OB11BaseMetaEvent } from './OB11BaseMetaEvent';
export enum LifeCycleSubType {
ENABLE = 'enable',
DISABLE = 'disable',
CONNECT = 'connect'
}
export class OB11LifeCycleEvent extends OB11BaseMetaEvent {
meta_event_type = 'lifecycle';
sub_type: LifeCycleSubType;
public constructor(subType: LifeCycleSubType) {
super();
this.sub_type = subType;
}
}

View File

@@ -0,0 +1,5 @@
import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
export abstract class OB11BaseNoticeEvent extends OB11BaseEvent {
post_type = EventType.NOTICE;
}

View File

@@ -0,0 +1,13 @@
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
export class OB11FriendRecallNoticeEvent extends OB11BaseNoticeEvent {
notice_type = 'friend_recall';
user_id: number;
message_id: number;
public constructor(userId: number, messageId: number) {
super();
this.user_id = userId;
this.message_id = messageId;
}
}

View File

@@ -0,0 +1,6 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
notice_type = 'group_admin';
sub_type: 'set' | 'unset'; // "set" | "unset"
}

View File

@@ -0,0 +1,17 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
notice_type = 'group_ban';
operator_id: number;
duration: number;
sub_type: 'ban' | 'lift_ban';
constructor(groupId: number, userId: number, operatorId: number, duration: number, sub_type: 'ban' | 'lift_ban') {
super();
this.group_id = groupId;
this.operator_id = operatorId;
this.user_id = userId;
this.duration = duration;
this.sub_type = sub_type;
}
}

View File

@@ -0,0 +1,16 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
notice_type = 'group_card';
card_new: string;
card_old: string;
constructor(groupId: number, userId: number, cardNew: string, cardOld: string) {
super();
this.group_id = groupId;
this.user_id = userId;
this.card_new = cardNew;
this.card_old = cardOld;
}
}

View File

@@ -0,0 +1,17 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export type GroupDecreaseSubType = 'leave' | 'kick' | 'kick_me';
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
notice_type = 'group_decrease';
sub_type: GroupDecreaseSubType = 'leave'; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
operator_id: number;
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
super();
this.group_id = groupId;
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
this.user_id = userId;
this.sub_type = subType;
}
}

View File

@@ -0,0 +1,15 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
type GroupIncreaseSubType = 'approve' | 'invite';
export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
notice_type = 'group_increase';
operator_id: number;
sub_type: GroupIncreaseSubType;
constructor(groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = 'approve') {
super();
this.group_id = groupId;
this.operator_id = operatorId;
this.user_id = userId;
this.sub_type = subType;
}
}

View File

@@ -0,0 +1,6 @@
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
export abstract class OB11GroupNoticeEvent extends OB11BaseNoticeEvent {
group_id: number;
user_id: number;
}

View File

@@ -0,0 +1,15 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export class OB11GroupRecallNoticeEvent extends OB11GroupNoticeEvent {
notice_type = 'group_recall';
operator_id: number;
message_id: number;
constructor(groupId: number, userId: number, operatorId: number, messageId: number) {
super();
this.group_id = groupId;
this.user_id = userId;
this.operator_id = operatorId;
this.message_id = messageId;
}
}

View File

@@ -0,0 +1,15 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export class OB11GroupTitleEvent extends OB11GroupNoticeEvent {
notice_type = 'notify';
sub_type = 'title';
title: string;
constructor(groupId: number, userId: number, title: string) {
super();
this.group_id = groupId;
this.user_id = userId;
this.title = title;
}
}

View File

@@ -0,0 +1,20 @@
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
export interface GroupUploadFile{
id: string,
name: string,
size: number,
busid: number,
}
export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
notice_type = 'group_upload';
file: GroupUploadFile;
constructor(groupId: number, userId: number, file: GroupUploadFile) {
super();
this.group_id = groupId;
this.user_id = userId;
this.file = file;
}
}

View File

@@ -0,0 +1,30 @@
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
import { selfInfo } from '../../../common/data';
import { OB11BaseEvent } from '../OB11BaseEvent';
class OB11PokeEvent extends OB11BaseNoticeEvent{
notice_type = 'notify';
sub_type = 'poke';
target_id = parseInt(selfInfo.uin);
user_id: number;
}
export class OB11FriendPokeEvent extends OB11PokeEvent{
sender_id: number;
constructor(user_id: number) {
super();
this.user_id = user_id;
this.sender_id = user_id;
}
}
export class OB11GroupPokeEvent extends OB11PokeEvent{
group_id: number;
constructor(group_id: number, user_id: number=0) {
super();
this.group_id = group_id;
this.target_id = user_id;
this.user_id = user_id;
}
}

View File

@@ -0,0 +1,11 @@
import { OB11BaseNoticeEvent } from '../notice/OB11BaseNoticeEvent';
import { EventType } from '../OB11BaseEvent';
export class OB11FriendRequestEvent extends OB11BaseNoticeEvent {
post_type = EventType.REQUEST;
user_id: number = 0;
request_type = 'friend' as const;
comment: string = '';
flag: string = '';
}

View File

@@ -0,0 +1,11 @@
import { OB11GroupNoticeEvent } from '../notice/OB11GroupNoticeEvent';
import { EventType } from '../OB11BaseEvent';
export class OB11GroupRequestEvent extends OB11GroupNoticeEvent {
post_type = EventType.REQUEST;
request_type = 'group' as const;
sub_type: 'add' | 'invite' = 'add';
comment: string = '';
flag: string = '';
}