refactor(event): use platform in ctx

This commit is contained in:
Il Harper 2024-03-05 21:20:08 +08:00
parent dd93e1f125
commit 07f282420d
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
4 changed files with 5 additions and 9 deletions

View File

@ -1 +0,0 @@
export const PLATFORM = 'chronocat'

View File

@ -1 +0,0 @@
export const PLATFORM = 'chronocat'

View File

@ -7,7 +7,6 @@ import type {
SatoriDispatchMessage,
} from '@chronocat/shell'
import type { O } from 'ts-toolbelt'
import { PLATFORM } from './consts'
import { buildParser } from './parser'
export class MessageCreatedDispatchMessage implements SatoriDispatchMessage {
@ -48,7 +47,7 @@ export class FriendRequestDispatchMessage implements SatoriDispatchMessage {
type = 'satori' as const
toSatori = async (
_ctx: ChronocatContext,
ctx: ChronocatContext,
_config: O.Intersect<
ChronocatLogCurrentConfig,
ChronocatSatoriEventsConfig
@ -58,7 +57,7 @@ export class FriendRequestDispatchMessage implements SatoriDispatchMessage {
id: undefined as unknown as number,
type: 'friend-request',
platform: PLATFORM,
platform: ctx.chronocat.platform,
self_id: undefined as unknown as string,
timestamp: Number(this.buddyReq.reqTime) * 1000,
}

View File

@ -12,7 +12,6 @@ import type {
import h from '@satorijs/element'
import { Buffer } from 'node:buffer'
import type { O } from 'ts-toolbelt'
import { PLATFORM } from '../consts'
import { parseMsgTypes } from './msgt'
export const buildParser =
@ -480,7 +479,7 @@ async function parseElements(
switch (m.faceElement!.faceType) {
case FaceType.PCPoke: {
elements.push(
h(`${PLATFORM}:pcpoke`, {
h(`${ctx.chronocat.platform}:pcpoke`, {
id: m.faceElement!.pokeType,
}),
)
@ -490,10 +489,10 @@ async function parseElements(
case FaceType.Normal:
case FaceType.Super: {
elements.push(
h(`${PLATFORM}:face`, {
h(`${ctx.chronocat.platform}:face`, {
id: m.faceElement!.faceIndex,
name: `[${(await ctx.chronocat.api['chronocat.internal.qface.get'](`${m.faceElement!.faceIndex}`))!.QDes.slice(1)}]`,
platform: PLATFORM,
platform: ctx.chronocat.platform,
'unsafe-super': m.faceElement!.faceType === FaceType.Super,
'unsafe-result-id': m.faceElement!.resultId,
'unsafe-chain-count': m.faceElement!.chainCount,