Skip to content

Commit

Permalink
add quick methods for memberJoinRequest event
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeanN committed Oct 11, 2021
1 parent e4b8226 commit 5da7a1f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class NodeMirai {
* @property { number } qq bot 的 qq 号
* @property { boolean } [enableWebsocket] 使用 ws 来获取消息和事件推送
* @property { boolean } [wsOnly] 完全使用 ws 来收发消息,为 true 时覆盖 enableWebsocket 且无需调用 verify
* @property { number } [syncId] wsOnly 模式下用于标记 server 主动推送的消息
* @property { number } [interval] 拉取消息的周期(ms), 默认为200
* @property { string } [authKey] (Deprecated) http-api 1.x 版本的authKey
*/
Expand Down Expand Up @@ -134,7 +135,7 @@ class NodeMirai {
* @type { string[] }
*/
this.types = [];
// TODO: support wsOnly mode #32

this.wsOnly = wsOnly;
this.syncId = syncId;
this.enableWebsocket = wsOnly || enableWebsocket;
Expand Down Expand Up @@ -785,6 +786,7 @@ class NodeMirai {
message,
host: this.host,
sessionKey: this.sessionKey,
wsOnly: this.wsOnly,
});
}

Expand Down Expand Up @@ -1196,7 +1198,7 @@ class NodeMirai {
}
}
else if (message.type in events) {
if (message.type === 'NewFriendRequestEvent' || message.type === 'BotInvitedJoinGroupEvent') {
if (['NewFriendRequestEvent', 'BotInvitedJoinGroupEvent', 'MemberJoinRequestEvent'].includes(message.type)) {
const self = this;
const args = [message.eventId, message.fromId, message.groupId];
const methods = {
Expand All @@ -1207,12 +1209,19 @@ class NodeMirai {
return self.handleNewFriendRequest(...args, 1, msg);
},
rejectAndBlock: null,
ignore: null,
ignoreAndBlock: null,
};
if (message.type === 'NewFriendRequestEvent') {
methods.rejectAndBlock = (msg) => {
return self.handleNewFriendRequest(...args, 2, msg);
};
}
if (message.type === 'MemberJoinRequestEvent') {
methods.ignore = msg => self.handleMemberJoinRequest(...args, 2, msg);
methods.rejectAndBlock = msg => self.handleMemberJoinRequest(...args, 3, msg);
methods.ignoreAndBlock = msg => self.handleMemberJoinRequest(...args, 4, msg);
}
Object.assign(message, methods);
}
for (let listener of this.eventListeners[events[message.type]]) {
Expand Down
32 changes: 26 additions & 6 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Permission, GroupPermissionInfo, GroupMember, MessageChain, MessageType, message } from "./typedef"
import { Permission, GroupPermissionInfo, GroupMember, MessageChain, MessageType, message, httpApiResponse } from "./typedef"

export enum events {
online = "online",
Expand Down Expand Up @@ -227,15 +227,15 @@ interface newFriendRequest {
/**
* 接受好友申请
*/
accept: (msg?: string) => void,
accept: (msg?: string) => Promise<httpApiResponse>,
/**
* 拒绝好友申请
*/
reject: (msg?: string) => void,
reject: (msg?: string) => Promise<httpApiResponse>,
/**
* 拒绝并拉黑, 不再接收该用户的好友申请
*/
rejectAndBlock: (msg?: string) => void,
rejectAndBlock: (msg?: string) => Promise<httpApiResponse>,
}
interface memberJoinRequest {
type: 'MemberJoinRequestEvent',
Expand All @@ -245,6 +245,26 @@ interface memberJoinRequest {
groupName: string,
nick: string,
message: string,
/**
* 接受加群申请
*/
accept: (msg?: string) => Promise<httpApiResponse>,
/**
* 拒绝加群申请
*/
reject: (msg?: string) => Promise<httpApiResponse>,
/**
* 忽略加群申请
*/
ignore: (msg?: string) => Promise<httpApiResponse>,
/**
* 拒绝并拉黑
*/
rejectAndBlock: (msg?: string) => Promise<httpApiResponse>,
/**
* 忽略并拉黑
*/
ignoreAndBlock: (msg?: string) => Promise<httpApiResponse>,
}
interface invitedJoinGroupRequest {
type: 'BotInvitedJoinGroupRequestEvent',
Expand All @@ -257,11 +277,11 @@ interface invitedJoinGroupRequest {
/**
* 接受邀请
*/
accept: (msg?: string) => void,
accept: (msg?: string) => Promise<httpApiResponse>,
/**
* 拒绝邀请
*/
reject: (msg?: string) => void,
reject: (msg?: string) => Promise<httpApiResponse>,
}
interface otherClientOnline {
type: 'OtherClientOnlineEvent',
Expand Down
10 changes: 9 additions & 1 deletion src/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,16 @@ const handleMemberJoinRequest = async({ //获取入群申请
fromId,
groupId,
operate,
message
message,
wsOnly,
}) => {
if (wsOnly) return ws.resp_memberJoinRequestEvent({
eventId,
fromId,
groupId,
operate,
message,
});
const { data } = await axios.post(`${host}/resp/memberJoinRequestEvent`, {
sessionKey,
eventId,
Expand Down

0 comments on commit 5da7a1f

Please sign in to comment.