type MessageType = "comment" | "gift" | "follow" | "joinclub" | "like" | "guard" | "superchat" | "enter" | "share" | undefined; /** * 多平台直播消息解析器。 * * 将各平台(B站/OpenBLive/抖音/快手/AcFun/CHZZK)的原始消息 * 统一解析为便于使用的属性访问接口,内置属性值缓存机制。 * * @example * ```ts * const parser = new Parser({ type: 'DANMU_MSG', content: '...' }) * console.log(parser.platform, parser.userName, parser.comment) * ``` * * @see {@link https://dimsum.chat/zh/api/parser.html} */ declare class Parser { /** * Douyin emoji mappings. Accessible directly without going through CommentBuilder. * * @example * Parser.DouyinEmots.forEach(([emot, url]) => console.log(emot, url)); */ static readonly DouyinEmots: readonly [string, string][]; /** * Bilibili emoji mappings (also used by OpenBLive). * * @example * Parser.BilibiliEmots.forEach(([emot, url]) => console.log(emot, url)); */ static readonly BilibiliEmots: readonly [string, string][]; /** * Kuaishou emoji mappings. * * @example * Parser.KuaishouEmots.forEach(([emot, url]) => console.log(emot, url)); */ static readonly KuaishouEmots: readonly [string, string][]; private static douyinGiftGroup; private static kuaishouGiftGroup; /** 原始消息类型。 */ readonly rawType: string; /** 原始消息内容(字符串已自动反序列化为对象)。 */ readonly rawContent: any; /** SEND_GIFT_V2 的 protobuf 解码结果(仅该类型时有效)。 */ private _pbData?; private _cachedValues; constructor(rawMsg: { type: string; content: any; }); private getCachedValue; /** * The live platform to which the message belongs. * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-platform} */ get platform(): "acfun" | "openblive" | "bilibili" | "douyin" | "kuaishou" | "chzzk" | undefined; /** * Message Type. * * @type see {@link MessageType} * @see {@link https://dimsum.chat/zh/api/parser.html#parser-type} */ get type(): MessageType; /** * User Name. * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-username} */ get userName(): string | undefined; /** * User ID. * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-uid} */ get uid(): number | string | undefined; /** 粉丝团/守护团等级。 */ get clubLevel(): number | undefined; /** 粉丝团/守护团名称。 */ get clubName(): string | undefined; /** AcFun 守护团所属主播的用户 ID。 */ get acfunClubUid(): number | undefined; /** * User subscription status in the current Douyin live room. * * @type `0` for non-member, `1` for monthly member, `2` for annual member * @see {@link https://dimsum.chat/zh/api/parser.html#parser-douyinsubscribe} */ get douyinSubscribe(): 0 | 1 | 2 | undefined; /** * 用户头像 URL。 * * B 站头像存在跨域限制,建议配合 getBfaceURL() 使用。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-avatar} */ get avatar(): string | undefined; /** * 弹幕聊天内容。 * * 当 type 为 comment 或 superchat 时均有值。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-comment} */ get comment(): string | undefined; /** * Simple method to construct comments as HTML strings. Useful for rendering comment messages in general. * * @param options - {@link commentParseOptions} * @returns Rendered comment HTML. * @see {@link https://dimsum.chat/zh/api/parser.html#parser-getcommenthtml} */ getCommentHTML(options?: commentParseOptions): string | undefined; /** * Custom comment content builder. * * @param builder - builder function. * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-commentbuilder} */ CommentBuilder(builder: (comment: string, stickerUrl?: string, emots?: [string, string][]) => string): string | undefined; /** * 大航海等级。 * * 0=无,3=舰长,2=提督,1=总督。 * 当 type 为 guard 时,表示本次购买的大航海等级; * 其他消息类型中表示该用户当前的大航海等级。 * Chzzk 平台的 Subscription 事件也支持此属性。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardlevel} */ get guardLevel(): 0 | 3 | 2 | 1 | undefined; /** * 大航海购买数量。 * * B 站表示购买月数,Chzzk 表示订阅月数。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardnum} */ get guardNum(): number | undefined; /** * 大航海购买价格(CNY)。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardprice} */ get guardPrice(): number | undefined; /** Chzzk 订阅等级(1-3)。 */ get chzzkTier(): number | undefined; /** Chzzk 订阅月数。 */ get chzzkTierMonth(): number | undefined; /** 礼物名称。 */ get giftName(): string | undefined; /** * 礼物数量。 * * 抖音和快手已由 SDK 内部处理连击去重,每次返回增量值。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-giftnum} */ get giftNum(): number | undefined; /** * 单个礼物价格(CNY)。 * * 免费礼物(如 B 站银瓜子)返回 0。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-giftunitprice} */ get giftUnitPrice(): number | undefined; /** * 礼物总价值(CNY)。 * * 等价于 giftNum × giftUnitPrice。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-gifttotalprice} */ get giftTotalPrice(): number | undefined; /** 礼物图片 URL。 */ get giftImage(): string | undefined; /** 超级聊天评论内容。 */ get superChatComment(): string | undefined; /** * 超级聊天价格。 * * B 站与 OpenBLive 为人民币(元),Chzzk 为韩元(KRW)。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-superchatprice} */ get superChatPrice(): number | undefined; /** * 广义价格,根据消息类型自动选择对应价格属性: * * | 消息类型 | 对应属性 | * |-----------|-----------------| * | gift | giftTotalPrice | * | superchat | superChatPrice | * | guard | guardPrice | * | 其它 | undefined | * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-price} */ get price(): number | undefined; /** * 获取用户的抽象化分级,用于渲染用户等级标识。 * * 不同平台的映射规则见官网文档。 * * @param options - 各平台分段阈值配置,见 {@link abstractLevelOptions} * @returns 0-3 等级,undefined 表示不支持 * @see {@link https://dimsum.chat/zh/api/parser.html#parser-getabstractlevel} */ getAbstractLevel(options?: abstractLevelOptions): number | undefined; } /** * getCommentHTML 渲染选项。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-getcommenthtml} */ interface commentParseOptions { /** 贴纸表情的 CSS 样式。 */ stickerStyle?: string; /** 贴纸表情的 CSS 类名。 */ stickerClass?: string; /** 小表情的 CSS 样式。 */ emotStyle?: string; /** 小表情的 CSS 类名。 */ emotClass?: string; /** 自定义 AcFun 贴纸表情。仅 platform='acfun' 时生效。 */ acfunCustomStickers?: { keyWord: string; path: string; }[]; acfunCustomHtmlBuilder?: (stickerPath: string, content: string) => string; } /** * getAbstractLevel 配置选项。 * * 各平台的默认分段均为 [7, 11, 15],即 clubLevel ≤ 7 → 0, ≤ 11 → 1, ≤ 15 → 2, > 15 → 3。 * * @see {@link https://dimsum.chat/zh/api/parser.html#parser-getabstractlevel} */ interface abstractLevelOptions { /** 抖音 clubLevel 分段阈值,默认 [7, 11, 15]。 */ douyinSteps?: number[]; /** 快手 clubLevel 分段阈值,默认 [7, 11, 15]。 */ kuaishouSteps?: number[]; /** AcFun clubLevel 分段阈值,默认 [7, 11, 15]。 */ acfunSteps?: number[]; /** AcFun 目标主播 UID。设置后仅该主播的守护团成员返回 >0 的值。 */ acfunClubUid?: number; } export { Parser }; export type { commentParseOptions, abstractLevelOptions };