packageDocumentation import { Mirai } from "./mirai" ; import type { EventType , MessageType } from "." ; import { getPlain } from "./utils/internal" ; import { isAt , isChatMessage } from "./utils/check" ; import { BotInvitedJoinGroupRequestOperationType , MemberJoinRequestOperationType , NewFriendRequestOperationType , } from "./mirai-api-http/resp" ; import { SingleMessage } from "./types/message-type" ; param msg export function createHelperForMsg ( mirai , msg ) { mirai . curMsg = msg ; if ( isChatMessage ( msg ) ) { msg . plain = getPlain ( msg . messageChain ) ; if ( msg . type === "GroupMessage" ) { msg . isAt = ( qq ? ) => { return isAt ( msg , qq ? qq : mirai . qq ) as boolean ; } ; } msg . group = ( ... groupIds ) => { return groupIds . includes ( ( msg as MessageType . GroupMessage ) . sender . group . id ) ; } ; msg . friend = ( ... qqs ) => { return qqs . includes ( msg . sender . id ) ; } ; msg . get = ( type ) => { let curSingleMessage = null ; msg . messageChain . some ( ( singleMessage ) => { if ( singleMessage . type === type ) { curSingleMessage = singleMessage ; return true ; } } ) ; return curSingleMessage ; } ; } ( msg as any ) . reply = async ( msgChain , quote = false ) => { return mirai . reply ( msgChain , msg , quote ) ; } ; if ( msg . type === "NewFriendRequestEvent" ) { msg . respond = async ( operate , message ? ) => { return mirai . api . resp . newFriendRequest ( msg , operate , message ) ; } ; } else if ( msg . type === "MemberJoinRequestEvent" ) { msg . respond = async ( operate , message ? ) => { return mirai . api . resp . memberJoinRequest ( msg , operate , message ) ; } ; } else if ( msg . type === "BotInvitedJoinGroupRequestEvent" ) { msg . respond = async ( operate , message ? ) => { return mirai . api . resp . botInvitedJoinGroupRequest ( msg , operate , message ) ; } ; } }