Skip to content

Commit 6db6253

Browse files
committed
Kook 你就那么喜欢改你那b结构?
1 parent 84dbc17 commit 6db6253

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/core/src/event-trigger.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const logger = createLogger('Kook-Events');
77
export function internalWebhook(ctx: Context, bot, data) {
88
// 大多数情况下都为信息
99
const session: Session<any> = {
10-
userId: data.author_id === '1' ? data.extra.body.user_id : data.author_id,
10+
userId: data.author_id === '1' ? data?.extra?.body?.user_id : data?.author_id,
1111
channelId: undefined,
1212
guildId: undefined,
1313
selfId: bot?.userME?.id,
@@ -17,15 +17,15 @@ export function internalWebhook(ctx: Context, bot, data) {
1717

1818
// 不是特定类型,当作普通信息
1919
if (data.type !== 255) {
20-
session.guildId = data.extra?.guild_id;
21-
session.channelId = data.target_id;
20+
session.guildId = data?.extra?.guild_id;
21+
session.channelId = data?.target_id;
2222

2323
processEvent(ctx, session, 'message', bot);
2424
if (data.channel_type === 'GROUP') {
2525
processEvent(ctx, session, 'message-created', bot);
2626
}
2727
if (data.channel_type === 'PERSON') {
28-
session.guildId = data.target_id;
28+
session.guildId = data?.target_id;
2929
processEvent(ctx, session, 'private-message-created', bot);
3030
}
3131
return;
@@ -35,8 +35,8 @@ export function internalWebhook(ctx: Context, bot, data) {
3535
}
3636

3737
function handleSpecialTypes(data, session, ctx, bot) {
38-
session.guildId = data.extra.body?.guild_id || data.target_id;
39-
session.channelId = data.extra.body?.channel_id || data.target_id;
38+
session.guildId = data?.extra?.body?.guild_id || data?.target_id;
39+
session.channelId = data?.extra?.body?.channel_id || data?.target_id;
4040

4141
switch (data.extra.type) {
4242
case 'message_btn_click':
@@ -53,7 +53,12 @@ function handleSpecialTypes(data, session, ctx, bot) {
5353
processEvent(ctx, session, 'button-click', bot);
5454
break;
5555
default:
56-
processEvent(ctx, session, eventMap[data.extra.type] || 'webhook', bot);
56+
processEvent(
57+
ctx,
58+
session,
59+
eventMap[data?.extra?.type] || data?.extra?.type || 'webhook',
60+
bot,
61+
);
5762
}
5863
}
5964

0 commit comments

Comments
 (0)