mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: add core
into all event constructors
This commit is contained in:
parent
2c14281168
commit
6d954b2d5d
@ -1,4 +1,4 @@
|
||||
import { selfInfo } from '@/core/data';
|
||||
import { InstanceContext, NapCatCore } from '@/core';
|
||||
|
||||
export enum EventType {
|
||||
META = 'meta_event',
|
||||
@ -8,9 +8,12 @@ export enum EventType {
|
||||
MESSAGE_SENT = 'message_sent',
|
||||
}
|
||||
|
||||
|
||||
export abstract class OB11BaseEvent {
|
||||
time = Math.floor(Date.now() / 1000);
|
||||
self_id = parseInt(selfInfo.uin);
|
||||
post_type: EventType = EventType.META;
|
||||
self_id: number;
|
||||
abstract post_type: EventType;
|
||||
|
||||
constructor(core: NapCatCore) {
|
||||
this.self_id = parseInt(core.selfInfo.uin);
|
||||
}
|
||||
}
|
||||
|
@ -2,5 +2,5 @@ import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
|
||||
|
||||
export abstract class OB11BaseMetaEvent extends OB11BaseEvent {
|
||||
post_type = EventType.META;
|
||||
meta_event_type: string;
|
||||
}
|
||||
abstract meta_event_type: string;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11BaseMetaEvent } from './OB11BaseMetaEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
interface HeartbeatStatus {
|
||||
online: boolean | null,
|
||||
@ -10,8 +11,8 @@ export class OB11HeartbeatEvent extends OB11BaseMetaEvent {
|
||||
status: HeartbeatStatus;
|
||||
interval: number;
|
||||
|
||||
public constructor(isOnline: boolean, isGood: boolean, interval: number) {
|
||||
super();
|
||||
public constructor(core: NapCatCore, interval: number, isOnline: boolean | null, isGood: boolean) {
|
||||
super(core);
|
||||
this.interval = interval;
|
||||
this.status = {
|
||||
online: isOnline,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11BaseMetaEvent } from './OB11BaseMetaEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export enum LifeCycleSubType {
|
||||
ENABLE = 'enable',
|
||||
@ -10,8 +11,8 @@ export class OB11LifeCycleEvent extends OB11BaseMetaEvent {
|
||||
meta_event_type = 'lifecycle';
|
||||
sub_type: LifeCycleSubType;
|
||||
|
||||
public constructor(subType: LifeCycleSubType) {
|
||||
super();
|
||||
public constructor(core: NapCatCore, subType: LifeCycleSubType) {
|
||||
super(core);
|
||||
this.sub_type = subType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11FriendAddNoticeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'friend_add';
|
||||
user_id: number;
|
||||
|
||||
public constructor(user_Id: number) {
|
||||
super();
|
||||
this.user_id = user_Id;
|
||||
public constructor(core: NapCatCore, userId: number) {
|
||||
super(core);
|
||||
this.user_id = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11FriendRecallNoticeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'friend_recall';
|
||||
user_id: number;
|
||||
message_id: number;
|
||||
|
||||
public constructor(userId: number, messageId: number) {
|
||||
super();
|
||||
public constructor(core: NapCatCore, userId: number, messageId: number) {
|
||||
super(core);
|
||||
this.user_id = userId;
|
||||
this.message_id = messageId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_ban';
|
||||
@ -6,8 +7,8 @@ export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
|
||||
duration: number;
|
||||
sub_type: 'ban' | 'lift_ban';
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, duration: number, sub_type: 'ban' | 'lift_ban') {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, duration: number, sub_type: 'ban' | 'lift_ban') {
|
||||
super(core);
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_card';
|
||||
@ -6,8 +7,8 @@ export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
|
||||
card_old: string;
|
||||
|
||||
|
||||
constructor(groupId: number, userId: number, cardNew: string, cardOld: string) {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, cardNew: string, cardOld: string) {
|
||||
super(core);
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.card_new = cardNew;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export type GroupDecreaseSubType = 'leave' | 'kick' | 'kick_me';
|
||||
|
||||
@ -7,8 +8,8 @@ export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
||||
sub_type: GroupDecreaseSubType = 'leave'; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
||||
operator_id: number;
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
|
||||
super(core);
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
||||
this.user_id = userId;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11GroupEssenceEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'essence';
|
||||
@ -6,8 +7,8 @@ export class OB11GroupEssenceEvent extends OB11GroupNoticeEvent {
|
||||
sender_id: number;
|
||||
sub_type: 'add' | 'delete' = 'add';
|
||||
|
||||
constructor(groupId: number, message_id: number, sender_id: number) {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, message_id: number, sender_id: number) {
|
||||
super(core);
|
||||
this.group_id = groupId;
|
||||
this.message_id = message_id;
|
||||
this.sender_id = sender_id;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
type GroupIncreaseSubType = 'approve' | 'invite';
|
||||
|
||||
@ -7,8 +8,8 @@ export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
|
||||
operator_id: number;
|
||||
sub_type: GroupIncreaseSubType;
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = 'approve') {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = 'approve') {
|
||||
super(core);
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
|
@ -1,6 +1,13 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export abstract class OB11GroupNoticeEvent extends OB11BaseNoticeEvent {
|
||||
group_id: number = 0;
|
||||
user_id: number = 0;
|
||||
}
|
||||
group_id: number;
|
||||
user_id: number;
|
||||
|
||||
constructor(core: NapCatCore, group_id: number, user_id: number) {
|
||||
super(core);
|
||||
this.group_id = group_id;
|
||||
this.user_id = user_id;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
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();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, operatorId: number, messageId: number) {
|
||||
super(core, groupId, userId);
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.operator_id = operatorId;
|
||||
this.message_id = messageId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11GroupTitleEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'notify';
|
||||
sub_type = 'title';
|
||||
title: string;
|
||||
|
||||
|
||||
constructor(groupId: number, userId: number, title: string) {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, title: string) {
|
||||
super(core, groupId, userId);
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.title = title;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export interface GroupUploadFile {
|
||||
id: string,
|
||||
@ -11,8 +12,8 @@ export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_upload';
|
||||
file: GroupUploadFile;
|
||||
|
||||
constructor(groupId: number, userId: number, file: GroupUploadFile) {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, file: GroupUploadFile) {
|
||||
super(core, groupId, userId);
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.file = file;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
//输入状态事件 初步完成 Mlikio wa Todo 需要做一些过滤
|
||||
export class OB11InputStatusEvent extends OB11BaseNoticeEvent {
|
||||
@ -9,8 +10,8 @@ export class OB11InputStatusEvent extends OB11BaseNoticeEvent {
|
||||
user_id = 0;
|
||||
group_id = 0;
|
||||
|
||||
constructor(user_id: number, eventType: number, status_text: string) {
|
||||
super();
|
||||
constructor(core: NapCatCore, user_id: number, eventType: number, status_text: string) {
|
||||
super(core);
|
||||
this.user_id = user_id;
|
||||
this.eventType = eventType;
|
||||
this.status_text = status_text;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export interface MsgEmojiLike {
|
||||
emoji_id: string,
|
||||
@ -10,8 +11,8 @@ export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent {
|
||||
message_id: number;
|
||||
likes: MsgEmojiLike[];
|
||||
|
||||
constructor(groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
||||
super();
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
||||
super(core, groupId, userId);
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId; // 可为空,表示是对别人的消息操作,如果是对bot自己的消息则不为空
|
||||
this.message_id = messageId;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
class OB11PokeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'notify';
|
||||
@ -11,8 +12,8 @@ export class OB11FriendPokeEvent extends OB11PokeEvent {
|
||||
raw_info: any;
|
||||
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(user_id: number, target_id: number, raw_message: any) {
|
||||
super();
|
||||
constructor(core: NapCatCore, user_id: number, target_id: number, raw_message: any) {
|
||||
super(core);
|
||||
this.target_id = target_id;
|
||||
this.user_id = user_id;
|
||||
this.raw_info = raw_message;
|
||||
@ -24,8 +25,8 @@ export class OB11GroupPokeEvent extends OB11PokeEvent {
|
||||
raw_info: any;
|
||||
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(group_id: number, user_id: number = 0, target_id: number = 0, raw_message: any) {
|
||||
super();
|
||||
constructor(core: NapCatCore, group_id: number, user_id: number = 0, target_id: number = 0, raw_message: any) {
|
||||
super(core);
|
||||
this.group_id = group_id;
|
||||
this.target_id = target_id;
|
||||
this.user_id = user_id;
|
||||
|
@ -1,11 +1,19 @@
|
||||
import { OB11BaseNoticeEvent } from '../notice/OB11BaseNoticeEvent';
|
||||
import { EventType } from '../OB11BaseEvent';
|
||||
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11FriendRequestEvent extends OB11BaseNoticeEvent {
|
||||
post_type = EventType.REQUEST;
|
||||
user_id: number = 0;
|
||||
request_type = 'friend' as const;
|
||||
comment: string = '';
|
||||
flag: string = '';
|
||||
request_type = 'friend';
|
||||
|
||||
user_id: number;
|
||||
comment: string;
|
||||
flag: string;
|
||||
|
||||
constructor(core: NapCatCore, user_id: number, comment: string, flag: string) {
|
||||
super(core);
|
||||
this.user_id = user_id;
|
||||
this.comment = comment;
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
import { OB11GroupNoticeEvent } from '../notice/OB11GroupNoticeEvent';
|
||||
import { EventType } from '../OB11BaseEvent';
|
||||
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export class OB11GroupRequestEvent extends OB11GroupNoticeEvent {
|
||||
post_type = EventType.REQUEST;
|
||||
request_type = 'group' as const;
|
||||
sub_type: 'add' | 'invite' = 'add';
|
||||
comment: string = '';
|
||||
flag: string = '';
|
||||
request_type = 'group';
|
||||
|
||||
user_id: number;
|
||||
comment: string;
|
||||
flag: string;
|
||||
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, comment: string, flag: string) {
|
||||
super(core, groupId, userId);
|
||||
this.user_id = userId;
|
||||
this.comment = comment;
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user