packageDocumentation import * as MessageType from "../types/message-type" ; import * as EventType from "../types/event-type" ; packageDocumentation /**
 * 正则表达式
 */ export interface Re { pattern : string ; flags ? : string ; } /**
 * 匹配配置
 */ export interface Match { re ? : Re | string ; is ? : string | string [ ] ; includes ? : string | string [ ] ; } param str param keywords export function is ( str , keywords ) { if ( Array . isArray ( keywords ) ) { return keywords . some ( ( keyword ) => { return str === keyword ; } ) ; } else { return str === keywords ; } } param str param keywords export function includes ( str , keywords ) { if ( Array . isArray ( keywords ) ) { return keywords . every ( ( keyword ) => { /**
             * 有 false 时跳出循环
             */ return str . includes ( keyword ) ; } ) ; } else { return str . includes ( keywords ) ; } } param str param config export function re ( str , config ) { let regExp = null ; if ( typeof config === "string" ) { regExp = new RegExp ( config ) ; } else { regExp = new RegExp ( config . pattern , config . flags || "i" ) ; } const result = regExp . exec ( str ) ; if ( result && result [ 0 ] ) { return result ; } else { return false ; } } param str param ans export function match ( str , ans ) { if ( ans . re ) return re ( str , ans . re ) ; if ( ans . is ) return is ( str , ans . is ) ; if ( ans . includes ) return includes ( str , ans . includes ) ; return false ; } param msg export function isChatMessage ( msg ) { const msgType = [ "FriendMessage" , "GroupMessage" , "TempMessage" ] ; return msgType . includes ( msg . type ) ; } param msg export function isAt ( msg , qq ? ) { if ( qq ) { return msg . messageChain . some ( ( singleMessage ) => { return singleMessage . type === "At" && singleMessage . target === qq ; } ) ; } else { let atMsg = undefined ; msg . messageChain . some ( ( singleMessage ) => { if ( singleMessage . type === "At" ) { atMsg = singleMessage ; return true ; } } ) ; return atMsg ? atMsg : false ; } }