diff --git a/adapters/satori/src/bot.ts b/adapters/satori/src/bot.ts index 9f3e4518..cf201cea 100644 --- a/adapters/satori/src/bot.ts +++ b/adapters/satori/src/bot.ts @@ -1,4 +1,4 @@ -import { Bot, Context, h, Quester, Session, snakeCase, Universal } from '@satorijs/satori' +import { Bot, Context, h, Quester, snakeCase, Universal } from '@satorijs/satori' export function transformKey(source: any, callback: (key: string) => string) { if (!source || typeof source !== 'object') return source @@ -38,12 +38,14 @@ for (const [key, method] of Object.entries(Universal.Methods)) { const payload = {} for (const [index, field] of method.fields.entries()) { if (method.name === 'createMessage' && field.name === 'content') { - const session: Session = args[3]?.session ?? this.session({ + const session = this.session({ type: 'send', channel: { id: args[0], type: 0 }, + ...args[3]?.session?.event, }) - const elements = await session.transform(h.normalize(args[index])) - payload[field.name] = elements.join('') + session.elements = await session.transform(h.normalize(args[index])) + if (await session.app.serial(session, 'before-send', session, args[3] ?? {})) return + payload[field.name] = session.elements.join('') } else { payload[field.name] = transformKey(args[index], snakeCase) } diff --git a/adapters/satori/src/ws.ts b/adapters/satori/src/ws.ts index b5a2d075..d9013e91 100644 --- a/adapters/satori/src/ws.ts +++ b/adapters/satori/src/ws.ts @@ -119,6 +119,10 @@ export class SatoriAdapter extends Adapter.WsClient session.setInternal(parsed.body._type, parsed.body._data) } bot.dispatch(session) + // temporary solution for `send` event + if (type === 'message-created' && session.userId === selfId) { + session.app.emit(session, 'send', session) + } } })