Skip to content

Commit

Permalink
Kook 你就那么喜欢改你那b结构?
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdg6 committed May 19, 2024
1 parent 84dbc17 commit 6db6253
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/core/src/event-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const logger = createLogger('Kook-Events');
export function internalWebhook(ctx: Context, bot, data) {
// 大多数情况下都为信息
const session: Session<any> = {
userId: data.author_id === '1' ? data.extra.body.user_id : data.author_id,
userId: data.author_id === '1' ? data?.extra?.body?.user_id : data?.author_id,
channelId: undefined,
guildId: undefined,
selfId: bot?.userME?.id,
Expand All @@ -17,15 +17,15 @@ export function internalWebhook(ctx: Context, bot, data) {

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

processEvent(ctx, session, 'message', bot);
if (data.channel_type === 'GROUP') {
processEvent(ctx, session, 'message-created', bot);
}
if (data.channel_type === 'PERSON') {
session.guildId = data.target_id;
session.guildId = data?.target_id;
processEvent(ctx, session, 'private-message-created', bot);
}
return;
Expand All @@ -35,8 +35,8 @@ export function internalWebhook(ctx: Context, bot, data) {
}

function handleSpecialTypes(data, session, ctx, bot) {
session.guildId = data.extra.body?.guild_id || data.target_id;
session.channelId = data.extra.body?.channel_id || data.target_id;
session.guildId = data?.extra?.body?.guild_id || data?.target_id;
session.channelId = data?.extra?.body?.channel_id || data?.target_id;

switch (data.extra.type) {
case 'message_btn_click':
Expand All @@ -53,7 +53,12 @@ function handleSpecialTypes(data, session, ctx, bot) {
processEvent(ctx, session, 'button-click', bot);
break;
default:
processEvent(ctx, session, eventMap[data.extra.type] || 'webhook', bot);
processEvent(
ctx,
session,
eventMap[data?.extra?.type] || data?.extra?.type || 'webhook',
bot,
);
}
}

Expand Down

0 comments on commit 6db6253

Please sign in to comment.