Skip to content

Commit

Permalink
feat: napcat 戳一戳优化
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Dec 11, 2024
1 parent 76a67d8 commit 035ee56
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"elysia": "^1.1.26",
"esbuild": "^0.24.0",
"eviltransform": "^0.2.2",
"file-type": "19.6.0",
"file-type": "19.3.0",
"fluent-ffmpeg": "^2.1.3",
"image-size": "^1.1.1",
"lodash": "^4.17.21",
Expand Down
3 changes: 2 additions & 1 deletion main/src/client/NapCatClient/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export class NapCatClient extends QQClient {
private async handlePoke(data: WSReceiveHandler['notice.notify.poke.group'] | WSReceiveHandler['notice.notify.poke.friend']) {
const chat = 'group_id' in data ? await this.pickGroup(data.group_id) : await this.pickFriend(data.user_id);
const operator = 'sender_id' in data ? data.sender_id as number : data.user_id;
const event = new PokeEvent(chat, operator, data.target_id, '戳了戳', undefined);
const nors: any[] = data.raw_info?.filter(it => (it.type as any) === 'nor') || [];
const event = new PokeEvent(chat, operator, data.target_id, nors[0]?.txt, nors[1]?.txt);
await this.callHandlers(this.onPokeHandlers, event);
}

Expand Down
30 changes: 30 additions & 0 deletions main/src/client/NapCatClient/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ abstract class NapCatUser extends NapCatEntity implements QQUser {
rand: 0,
};
}

async poke(self?: boolean): Promise<boolean> {
if (self) {
throw new Error('NapCat 不支持自己戳自己');
}
try {
await this.client.callApi('friend_poke', { user_id: this.uid });
return true;
}
catch (e) {
this.logger.error('戳一戳失败', e);
posthog.capture('NapCat 戳一戳失败', { error: e });
return false;
}
}
}

export class NapCatFriend extends NapCatUser implements Friend {
Expand Down Expand Up @@ -235,6 +250,21 @@ export class NapCatGroup extends NapCatEntity implements Group {
content,
});
}

async pokeMember(uid: number): Promise<boolean> {
try {
await this.client.callApi('group_poke', {
group_id: this.gid,
user_id: uid,
});
return true;
}
catch (e) {
this.logger.error('戳一戳失败', e);
posthog.capture('NapCat 戳一戳失败', { error: e });
return false;
}
}
}

export class NapCatGroupMember extends NapCatUser implements GroupMember {
Expand Down
4 changes: 2 additions & 2 deletions main/src/services/InChatCommandsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export default class InChatCommandsService {
target = Number(dbEntry.qqSenderId);
}
}
if (qq instanceof OicqGroup && !target) {
if ('pokeMember' in qq && !target) {
await message.reply({
message: '<i>请回复一条消息</i>',
});
}
else if (qq instanceof OicqGroup) {
else if ('pokeMember' in qq) {
await qq.pokeMember(target);
}
else {
Expand Down
39 changes: 9 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 035ee56

Please sign in to comment.