@napuketto/adapter 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{buddy-req-BvAxJo6d.mjs → buddy-req-CN7gzJpq.mjs} +51 -14
- package/dist/buddy-req-CN7gzJpq.mjs.map +1 -0
- package/dist/core/index.mjs +1 -1
- package/dist/{core-D8sq68iP.mjs → core-C7Nnl45P.mjs} +3 -3
- package/dist/core-C7Nnl45P.mjs.map +1 -0
- package/dist/index-B-HpCes-.d.mts.map +1 -1
- package/dist/{index-DBD-IZKn.d.mts → index-B2Hf9yzT.d.mts} +18 -6
- package/dist/{index-DBD-IZKn.d.mts.map → index-B2Hf9yzT.d.mts.map} +1 -1
- package/dist/index-DBjlR2dn.d.mts.map +1 -1
- package/dist/{index-CepyMhuM.d.mts → index-d_RSpWyb.d.mts} +17 -6
- package/dist/index-d_RSpWyb.d.mts.map +1 -0
- package/dist/index-dsurF2t_.d.mts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +5 -5
- package/dist/kurobot/index.mjs +1 -1
- package/dist/{kurobot-cMBAVX3L.mjs → kurobot-B3por6f4.mjs} +19 -19
- package/dist/kurobot-B3por6f4.mjs.map +1 -0
- package/dist/milky/index.d.mts +1 -1
- package/dist/milky/index.mjs +1 -1
- package/dist/{milky-CYAOJLv_.mjs → milky-Dpk2r5RV.mjs} +261 -145
- package/dist/milky-Dpk2r5RV.mjs.map +1 -0
- package/dist/onebot11/index.d.mts +1 -1
- package/dist/onebot11/index.mjs +1 -1
- package/dist/{onebot11-BikYDo3k.mjs → onebot11-D_JlAsjy.mjs} +254 -150
- package/dist/onebot11-D_JlAsjy.mjs.map +1 -0
- package/dist/{raw-message-D5nMIebz.mjs → raw-message-Cs4vDKUU.mjs} +11 -3
- package/dist/raw-message-Cs4vDKUU.mjs.map +1 -0
- package/dist/satori/index.mjs +1 -1
- package/dist/{satori-Cb2uM3PY.mjs → satori-Deamai7y.mjs} +47 -22
- package/dist/satori-Deamai7y.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/buddy-req-BvAxJo6d.mjs.map +0 -1
- package/dist/core-D8sq68iP.mjs.map +0 -1
- package/dist/index-CepyMhuM.d.mts.map +0 -1
- package/dist/kurobot-cMBAVX3L.mjs.map +0 -1
- package/dist/milky-CYAOJLv_.mjs.map +0 -1
- package/dist/onebot11-BikYDo3k.mjs.map +0 -1
- package/dist/raw-message-D5nMIebz.mjs.map +0 -1
- package/dist/satori-Cb2uM3PY.mjs.map +0 -1
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* OneBot 11 协议适配器(当前主战场)
|
|
3
3
|
* 公共面:类型 + 动作注册表 + 配置 schema + 翻译层(adapter.ts 于 打通 kernel 事件后接入)。
|
|
4
4
|
*/
|
|
5
|
-
import { $ as OB11Return, A as Ob11ActionDeps, B as cqMessageToCanonical, C as CqCode, D as parseCqMessage, E as escapeCqText, F as OneBotApiOptions, G as GroupHonorInfo, H as segmentsToCanonical, I as OneBotSystemOptions, J as HonorMember, K as GroupInfo, L as MessageUnique, M as AtAllRemainInfo, N as ob11ErrorCodeMap, O as serializeCqParts, P as OneBotApi, Q as OB11MessageSegment, R as canonicalToCqMessage, S as segmentsToCqMessage, T as escapeCqParam, U as CurrentTalkative, V as cqMessageToSegments, W as FriendInfo, X as OB11Message, Y as LoginInfo, Z as OB11MessageInfo, _ as OB11PrivateMessageEvent, a as OneBot11AdapterOptions, b as OB11Config, c as OB11GroupRequestEvent, d as OB11HeartbeatMetaEvent, et as Sender, f as OB11LifecycleMetaEvent, g as OB11MessageEvent, h as OB11GroupMessageEvent, i as NapukettoOneBot11Adapter, j as createOb11ActionRegistry, k as unescapeCqText, l as OB11RequestEvent, m as OB11Status, n as Ob11TransportSet, nt as StrangerInfo, o as OB11Event, p as OB11MetaEvent, q as GroupMemberInfo, r as assembleOb11Transports, rt as VersionInfo, s as OB11FriendRequestEvent, t as AssembleOb11TransportsOptions, tt as Sex, u as OB11NoticeEvent, v as OB11BaseEvent, w as encodeCqCode, x as ob11ConfigSchema, y as OB11PostType, z as canonicalToSegments } from "../index-
|
|
5
|
+
import { $ as OB11Return, A as Ob11ActionDeps, B as cqMessageToCanonical, C as CqCode, D as parseCqMessage, E as escapeCqText, F as OneBotApiOptions, G as GroupHonorInfo, H as segmentsToCanonical, I as OneBotSystemOptions, J as HonorMember, K as GroupInfo, L as MessageUnique, M as AtAllRemainInfo, N as ob11ErrorCodeMap, O as serializeCqParts, P as OneBotApi, Q as OB11MessageSegment, R as canonicalToCqMessage, S as segmentsToCqMessage, T as escapeCqParam, U as CurrentTalkative, V as cqMessageToSegments, W as FriendInfo, X as OB11Message, Y as LoginInfo, Z as OB11MessageInfo, _ as OB11PrivateMessageEvent, a as OneBot11AdapterOptions, b as OB11Config, c as OB11GroupRequestEvent, d as OB11HeartbeatMetaEvent, et as Sender, f as OB11LifecycleMetaEvent, g as OB11MessageEvent, h as OB11GroupMessageEvent, i as NapukettoOneBot11Adapter, j as createOb11ActionRegistry, k as unescapeCqText, l as OB11RequestEvent, m as OB11Status, n as Ob11TransportSet, nt as StrangerInfo, o as OB11Event, p as OB11MetaEvent, q as GroupMemberInfo, r as assembleOb11Transports, rt as VersionInfo, s as OB11FriendRequestEvent, t as AssembleOb11TransportsOptions, tt as Sex, u as OB11NoticeEvent, v as OB11BaseEvent, w as encodeCqCode, x as ob11ConfigSchema, y as OB11PostType, z as canonicalToSegments } from "../index-B2Hf9yzT.mjs";
|
|
6
6
|
export { type AssembleOb11TransportsOptions, type AtAllRemainInfo, type CqCode, type CurrentTalkative, type FriendInfo, type GroupHonorInfo, type GroupInfo, type GroupMemberInfo, type HonorMember, type LoginInfo, MessageUnique, NapukettoOneBot11Adapter, type OB11BaseEvent, type OB11Config, type OB11Event, type OB11FriendRequestEvent, type OB11GroupMessageEvent, type OB11GroupRequestEvent, type OB11HeartbeatMetaEvent, type OB11LifecycleMetaEvent, type OB11Message, type OB11MessageEvent, type OB11MessageInfo, type OB11MessageSegment, type OB11MetaEvent, type OB11NoticeEvent, type OB11PostType, type OB11PrivateMessageEvent, type OB11RequestEvent, type OB11Return, type OB11Status, type Ob11ActionDeps, type Ob11TransportSet, type OneBot11AdapterOptions, OneBotApi, type OneBotApiOptions, type OneBotSystemOptions, type Sender, type Sex, type StrangerInfo, type VersionInfo, assembleOb11Transports, canonicalToCqMessage, canonicalToSegments, cqMessageToCanonical, cqMessageToSegments, createOb11ActionRegistry, encodeCqCode, escapeCqParam, escapeCqText, ob11ConfigSchema, ob11ErrorCodeMap, parseCqMessage, segmentsToCanonical, segmentsToCqMessage, serializeCqParts, unescapeCqText };
|
package/dist/onebot11/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-
|
|
1
|
+
export { y as MessageUnique, t as NapukettoOneBot11Adapter, r as OneBotApi, n as assembleOb11Transports, a as canonicalToCqMessage, o as canonicalToSegments, s as cqMessageToCanonical, c as cqMessageToSegments, i as createOb11ActionRegistry, f as encodeCqCode, p as escapeCqParam, m as escapeCqText, u as ob11ConfigSchema, v as ob11ErrorCodeMap, h as parseCqMessage, l as segmentsToCanonical, d as segmentsToCqMessage, g as serializeCqParts, _ as unescapeCqText } from "../onebot11-D_JlAsjy.mjs";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as resolveProtocolConfig, i as BaseProtocolAdapter, o as ActionRegistry, r as createServerSchema, s as runAction } from "./core-
|
|
2
|
-
import { a as firstNonEmptyString, c as MS_TO_SEC, f as toUin, i as toUnixSeconds, l as NUMERIC_RE, n as senderNickname, o as stringOrUndefined, r as subscribeRawMessages, s as startupBaselineSec, u as numericUin } from "./raw-message-
|
|
1
|
+
import { a as resolveProtocolConfig, i as BaseProtocolAdapter, o as ActionRegistry, r as createServerSchema, s as runAction } from "./core-C7Nnl45P.mjs";
|
|
2
|
+
import { a as firstNonEmptyString, c as MS_TO_SEC, f as toUin, i as toUnixSeconds, l as NUMERIC_RE, n as senderNickname, o as stringOrUndefined, r as subscribeRawMessages, s as startupBaselineSec, u as numericUin } from "./raw-message-Cs4vDKUU.mjs";
|
|
3
3
|
import { a as logEventFailure, c as downloadBufferToFile, d as prepareVideoElements, i as hasGrayTip, l as ensureSilk, o as sliceRaw, r as firstUntranslatedGrayTip, s as truncRaw, t as collectGrayTipUids, u as fileUriToPath } from "./gray-tip-DmZmdtjP.mjs";
|
|
4
|
-
import { a as EssenceListSync, c as OBSERVED_UNNAMED_SYSMSG_KEYS, d as processSysMsgBlob, f as recognizeSysMsg, i as narrowBuddyReqs, l as narrowSysMsgBlobs, n as batchUnreadNums, o as extractEssenceSetSysMsg, r as filterBuddyReqs, s as narrowEssenceGroupArg, t as BuddyReqDedup } from "./buddy-req-
|
|
5
|
-
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
4
|
+
import { a as EssenceListSync, c as OBSERVED_UNNAMED_SYSMSG_KEYS, d as processSysMsgBlob, f as recognizeSysMsg, i as narrowBuddyReqs, l as narrowSysMsgBlobs, n as batchUnreadNums, o as extractEssenceSetSysMsg, r as filterBuddyReqs, s as narrowEssenceGroupArg, t as BuddyReqDedup } from "./buddy-req-CN7gzJpq.mjs";
|
|
5
|
+
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupMemberRole, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, WebHonorType, errorMessage, hasStringProp, isRecord, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
6
6
|
import { HttpClient, HttpServer, WsClient, WsServer } from "@napuketto/network";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
@@ -374,13 +374,13 @@ function createGroupEssenceActions(api) {
|
|
|
374
374
|
if (seg !== null) content.push(seg);
|
|
375
375
|
}
|
|
376
376
|
out.push({
|
|
377
|
-
msg_seq: item.msg_seq,
|
|
378
|
-
msg_random: item.msg_random,
|
|
377
|
+
msg_seq: item.msg_seq ?? 0,
|
|
378
|
+
msg_random: item.msg_random ?? 0,
|
|
379
379
|
sender_id: Number(item.sender_uin),
|
|
380
|
-
sender_nick: item.sender_nick,
|
|
380
|
+
sender_nick: item.sender_nick ?? "",
|
|
381
381
|
operator_id: Number(item.add_digest_uin),
|
|
382
|
-
operator_nick: item.add_digest_nick,
|
|
383
|
-
operator_time: item.add_digest_time,
|
|
382
|
+
operator_nick: item.add_digest_nick ?? "",
|
|
383
|
+
operator_time: item.add_digest_time ?? 0,
|
|
384
384
|
message_id: 0,
|
|
385
385
|
content
|
|
386
386
|
});
|
|
@@ -775,8 +775,8 @@ function createGroupNotifyActions(api) {
|
|
|
775
775
|
const out = [];
|
|
776
776
|
for (const member of members) out.push({
|
|
777
777
|
user_id: Number(uinMap.get(member.uid) ?? member.uin ?? member.uid),
|
|
778
|
-
nickname: member.nick,
|
|
779
|
-
shut_up_time: member.shutUpTime
|
|
778
|
+
nickname: member.nick ?? "",
|
|
779
|
+
shut_up_time: member.shutUpTime ?? 0
|
|
780
780
|
});
|
|
781
781
|
return out;
|
|
782
782
|
}
|
|
@@ -812,6 +812,22 @@ function toOb11GroupInfoDetail(detail) {
|
|
|
812
812
|
}
|
|
813
813
|
/** 禁言秒 → 毫秒(shut_up_timestamp 单位)。 */
|
|
814
814
|
const SEC_TO_MS = 1e3;
|
|
815
|
+
/** 可选成员字段补全(缺省 / 空值不写入,保持 OB11 事件精简)。 */
|
|
816
|
+
function applyMemberOptionalFields(info, member) {
|
|
817
|
+
const cardName = member.cardName ?? "";
|
|
818
|
+
if (cardName !== "") info.card = cardName;
|
|
819
|
+
if (member.memberSpecialTitle !== void 0 && member.memberSpecialTitle !== "") {
|
|
820
|
+
info.title = member.memberSpecialTitle;
|
|
821
|
+
info.special_title = member.memberSpecialTitle;
|
|
822
|
+
}
|
|
823
|
+
const shutUpTime = member.shutUpTime ?? 0;
|
|
824
|
+
if (shutUpTime > 0) info.shut_up_timestamp = shutUpTime * SEC_TO_MS;
|
|
825
|
+
const joinTime = member.joinTime ?? "";
|
|
826
|
+
if (joinTime !== "" && joinTime !== "0") info.join_time = Number(joinTime);
|
|
827
|
+
const lastSpeakTime = member.lastSpeakTime ?? "";
|
|
828
|
+
if (lastSpeakTime !== "" && lastSpeakTime !== "0") info.last_sent_time = Number(lastSpeakTime);
|
|
829
|
+
if (typeof member.age === "number") info.age = member.age;
|
|
830
|
+
}
|
|
815
831
|
/** NT GroupMember → OB11 GroupMemberInfo(uin 由 uidToUin 映射补全)。 */
|
|
816
832
|
function toOb11GroupMemberInfo(groupCode, member, uidToUin) {
|
|
817
833
|
let uinStr = member.uin;
|
|
@@ -819,18 +835,10 @@ function toOb11GroupMemberInfo(groupCode, member, uidToUin) {
|
|
|
819
835
|
const info = {
|
|
820
836
|
group_id: Number(groupCode),
|
|
821
837
|
user_id: Number(uinStr),
|
|
822
|
-
nickname: member.nick,
|
|
823
|
-
role: GroupApi.roleToString(member.role)
|
|
838
|
+
nickname: member.nick ?? "",
|
|
839
|
+
role: GroupApi.roleToString(member.role ?? NTGroupMemberRole.UNSPECIFIED)
|
|
824
840
|
};
|
|
825
|
-
|
|
826
|
-
if (member.memberSpecialTitle !== void 0 && member.memberSpecialTitle !== "") {
|
|
827
|
-
info.title = member.memberSpecialTitle;
|
|
828
|
-
info.special_title = member.memberSpecialTitle;
|
|
829
|
-
}
|
|
830
|
-
if (member.shutUpTime > 0) info.shut_up_timestamp = member.shutUpTime * SEC_TO_MS;
|
|
831
|
-
if (member.joinTime !== "" && member.joinTime !== "0") info.join_time = Number(member.joinTime);
|
|
832
|
-
if (member.lastSpeakTime !== "" && member.lastSpeakTime !== "0") info.last_sent_time = Number(member.lastSpeakTime);
|
|
833
|
-
if (typeof member.age === "number") info.age = member.age;
|
|
841
|
+
applyMemberOptionalFields(info, member);
|
|
834
842
|
return info;
|
|
835
843
|
}
|
|
836
844
|
// src/onebot11/action/group/query.ts
|
|
@@ -922,6 +930,8 @@ no_cache: z.boolean().optional() }),
|
|
|
922
930
|
// src/onebot11/action/group/system-msg.ts
|
|
923
931
|
/** 默认获取数量。 */
|
|
924
932
|
const DEFAULT_COUNT = 50;
|
|
933
|
+
/** OB11 兼容别名键(常量是为了规避 objectLiteralMember 命名规则)。 */
|
|
934
|
+
const INVITED_REQUEST_ALIAS = "InvitedRequest";
|
|
925
935
|
/** 收集全部涉及的 uid 批量转 uin(循环外一次请求)。 */
|
|
926
936
|
async function collectUinMap(api, notifies) {
|
|
927
937
|
const uids = [];
|
|
@@ -998,12 +1008,11 @@ function createGroupSystemMsgActions(api) {
|
|
|
998
1008
|
if (notify.type === GroupNotifyMsgType.INVITED_BY_MEMBER) invited.push(info);
|
|
999
1009
|
else if (notify.type === GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS) joined.push(info);
|
|
1000
1010
|
}
|
|
1001
|
-
|
|
1011
|
+
return {
|
|
1002
1012
|
invited_requests: invited,
|
|
1003
|
-
join_requests: joined
|
|
1013
|
+
join_requests: joined,
|
|
1014
|
+
[INVITED_REQUEST_ALIAS]: invited
|
|
1004
1015
|
};
|
|
1005
|
-
result["InvitedRequest"] = invited;
|
|
1006
|
-
return result;
|
|
1007
1016
|
}
|
|
1008
1017
|
})];
|
|
1009
1018
|
}
|
|
@@ -1083,6 +1092,8 @@ function serializeCqParts(parts) {
|
|
|
1083
1092
|
return out;
|
|
1084
1093
|
}
|
|
1085
1094
|
// src/onebot11/helper/codec/segment.ts
|
|
1095
|
+
/** 校验失败统一文案(协议入站边界,ADR-009)。 */
|
|
1096
|
+
const INVALID_SEGMENT_MESSAGE = "OneBot11 消息段格式不合法";
|
|
1086
1097
|
/** OB11 媒体段 data(image/record/video 共用,url 可选)。 */
|
|
1087
1098
|
function mediaData(file, url) {
|
|
1088
1099
|
const data = { file };
|
|
@@ -1104,113 +1115,199 @@ function canonicalAt(target, display) {
|
|
|
1104
1115
|
if (display !== void 0) el.display = display;
|
|
1105
1116
|
return el;
|
|
1106
1117
|
}
|
|
1107
|
-
/** canonical 媒体元素(image/voice/video,url
|
|
1118
|
+
/** canonical 媒体元素(image/voice/video,url 可选;分支内收窄,无需断言)。 */
|
|
1108
1119
|
function canonicalMedia(type, path, url) {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1120
|
+
switch (type) {
|
|
1121
|
+
case "image": return url === void 0 ? {
|
|
1122
|
+
type: "image",
|
|
1123
|
+
path
|
|
1124
|
+
} : {
|
|
1125
|
+
type: "image",
|
|
1126
|
+
path,
|
|
1127
|
+
url
|
|
1128
|
+
};
|
|
1129
|
+
case "voice": return url === void 0 ? {
|
|
1130
|
+
type: "voice",
|
|
1131
|
+
path
|
|
1132
|
+
} : {
|
|
1133
|
+
type: "voice",
|
|
1134
|
+
path,
|
|
1135
|
+
url
|
|
1136
|
+
};
|
|
1137
|
+
case "video": return url === void 0 ? {
|
|
1138
|
+
type: "video",
|
|
1139
|
+
path
|
|
1140
|
+
} : {
|
|
1141
|
+
type: "video",
|
|
1142
|
+
path,
|
|
1143
|
+
url
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1115
1146
|
}
|
|
1116
1147
|
/** canonical json/xml 的 raw → OB11 data 字符串(字符串原样,对象序列化)。 */
|
|
1117
1148
|
function rawToString(raw) {
|
|
1118
1149
|
if (typeof raw === "string") return raw;
|
|
1119
1150
|
return JSON.stringify(raw);
|
|
1120
1151
|
}
|
|
1121
|
-
/**
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1152
|
+
/** 字段是否为 string | number(OB11 数值型 id 的容忍形态)。 */
|
|
1153
|
+
function isStringOrNumber(val) {
|
|
1154
|
+
return typeof val === "string" || typeof val === "number";
|
|
1155
|
+
}
|
|
1156
|
+
/** 可选字符串字段(缺省合法,出现时必须是 string)。 */
|
|
1157
|
+
function isOptionalString(data, key) {
|
|
1158
|
+
return data[key] === void 0 || typeof data[key] === "string";
|
|
1159
|
+
}
|
|
1160
|
+
/** 文本 / at / face 类型的 data 校验。 */
|
|
1161
|
+
function isTextLikeSegmentData(type, data) {
|
|
1162
|
+
switch (type) {
|
|
1163
|
+
case "text":
|
|
1164
|
+
case "string": return hasStringProp(data, "text");
|
|
1165
|
+
case "at": return isStringOrNumber(data["qq"]) && isOptionalString(data, "name");
|
|
1166
|
+
case "face": return isStringOrNumber(data["id"]);
|
|
1167
|
+
default: return false;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
/** image / record / video / file 类型的 data 校验。 */
|
|
1171
|
+
function isMediaSegmentData(type, data) {
|
|
1172
|
+
switch (type) {
|
|
1173
|
+
case "image":
|
|
1174
|
+
case "record":
|
|
1175
|
+
case "video": return hasStringProp(data, "file") && isOptionalString(data, "url");
|
|
1176
|
+
case "file": return hasStringProp(data, "file");
|
|
1177
|
+
default: return false;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
/** reply / forward / json / xml 类型的 data 校验。 */
|
|
1181
|
+
function isPayloadSegmentData(type, data) {
|
|
1182
|
+
switch (type) {
|
|
1183
|
+
case "reply":
|
|
1184
|
+
case "forward": return isStringOrNumber(data["id"]);
|
|
1185
|
+
case "json":
|
|
1186
|
+
case "xml": return typeof data["data"] === "string" || isRecord(data["data"]);
|
|
1187
|
+
default: return false;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* OB11 消息段形状守卫:`type` 为 string,`data` 为对象,且**已知类型的必填字段**
|
|
1192
|
+
* 类型正确。未知 `type` 一律判非法(发送入口显式拒绝,不静默丢段)。
|
|
1193
|
+
*
|
|
1194
|
+
* 按 data 校验形态拆成三组小函数(文本类 / 媒体类 / 载荷类),主函数只做短路组合。
|
|
1195
|
+
*/
|
|
1196
|
+
function isOB11MessageSegment(val) {
|
|
1197
|
+
if (!isRecord(val) || !hasStringProp(val, "type")) return false;
|
|
1198
|
+
const data = val["data"];
|
|
1199
|
+
if (!isRecord(data)) return false;
|
|
1200
|
+
const type = val["type"];
|
|
1201
|
+
return isTextLikeSegmentData(type, data) || isMediaSegmentData(type, data) || isPayloadSegmentData(type, data);
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* 校验并收窄入站 segment 数组(HTTP 动作载荷 → OB11MessageSegment[])。
|
|
1205
|
+
* 任一项不合法即抛 INVALID_PARAM(ADR-009 外部边界统一错误语义)。
|
|
1206
|
+
*/
|
|
1207
|
+
function parseOB11MessageSegments(raw) {
|
|
1208
|
+
const out = [];
|
|
1209
|
+
for (const item of raw) {
|
|
1210
|
+
if (!isOB11MessageSegment(item)) throw kernelError(INVALID_SEGMENT_MESSAGE, "INVALID_PARAM");
|
|
1211
|
+
out.push(item);
|
|
1212
|
+
}
|
|
1213
|
+
return out;
|
|
1214
|
+
}
|
|
1168
1215
|
/** canonical 元素 → OB11 segment(null = OB11 无法表达,跳过)。 */
|
|
1169
1216
|
function canonicalToSegment(el) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1217
|
+
switch (el.type) {
|
|
1218
|
+
case "text": return {
|
|
1219
|
+
type: "text",
|
|
1220
|
+
data: { text: el.text }
|
|
1221
|
+
};
|
|
1222
|
+
case "at": return {
|
|
1223
|
+
type: "at",
|
|
1224
|
+
data: atData(el.target, el.display)
|
|
1225
|
+
};
|
|
1226
|
+
case "image": return {
|
|
1227
|
+
type: "image",
|
|
1228
|
+
data: mediaData(el.path, el.url)
|
|
1229
|
+
};
|
|
1230
|
+
case "face": return {
|
|
1231
|
+
type: "face",
|
|
1232
|
+
data: { id: el.id }
|
|
1233
|
+
};
|
|
1234
|
+
case "voice": return {
|
|
1235
|
+
type: "record",
|
|
1236
|
+
data: mediaData(el.path, el.url)
|
|
1237
|
+
};
|
|
1238
|
+
case "video": return {
|
|
1239
|
+
type: "video",
|
|
1240
|
+
data: mediaData(el.path, el.url)
|
|
1241
|
+
};
|
|
1242
|
+
case "file": return {
|
|
1243
|
+
type: "file",
|
|
1244
|
+
data: { file: el.name ?? el.path }
|
|
1245
|
+
};
|
|
1246
|
+
case "reply": return {
|
|
1247
|
+
type: "reply",
|
|
1248
|
+
data: { id: el.messageId }
|
|
1249
|
+
};
|
|
1250
|
+
case "forward": return {
|
|
1251
|
+
type: "forward",
|
|
1252
|
+
data: { id: el.messageIds[0] ?? "" }
|
|
1253
|
+
};
|
|
1254
|
+
case "json": return {
|
|
1255
|
+
type: "json",
|
|
1256
|
+
data: { data: rawToString(el.raw) }
|
|
1257
|
+
};
|
|
1258
|
+
case "xml": return {
|
|
1259
|
+
type: "xml",
|
|
1260
|
+
data: { data: rawToString(el.raw) }
|
|
1261
|
+
};
|
|
1262
|
+
case "unknown": return null;
|
|
1263
|
+
default: return null;
|
|
1264
|
+
}
|
|
1172
1265
|
}
|
|
1173
|
-
/**
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
}),
|
|
1179
|
-
string: (seg) => ({
|
|
1180
|
-
type: "text",
|
|
1181
|
-
text: seg.data.text
|
|
1182
|
-
}),
|
|
1183
|
-
at: (seg) => canonicalAt(seg.data.qq, seg.data.name),
|
|
1184
|
-
face: (seg) => ({
|
|
1185
|
-
type: "face",
|
|
1186
|
-
id: seg.data.id
|
|
1187
|
-
}),
|
|
1188
|
-
image: (seg) => canonicalMedia("image", seg.data.file, seg.data.url),
|
|
1189
|
-
record: (seg) => canonicalMedia("voice", seg.data.file, seg.data.url),
|
|
1190
|
-
video: (seg) => canonicalMedia("video", seg.data.file, seg.data.url),
|
|
1191
|
-
reply: (seg) => ({
|
|
1192
|
-
type: "reply",
|
|
1193
|
-
messageId: seg.data.id
|
|
1194
|
-
}),
|
|
1195
|
-
forward: (seg) => ({
|
|
1196
|
-
type: "forward",
|
|
1197
|
-
messageIds: [seg.data.id]
|
|
1198
|
-
}),
|
|
1199
|
-
json: (seg) => ({
|
|
1200
|
-
type: "json",
|
|
1201
|
-
raw: seg.data.data
|
|
1202
|
-
}),
|
|
1203
|
-
xml: (seg) => ({
|
|
1204
|
-
type: "xml",
|
|
1205
|
-
raw: seg.data.data
|
|
1206
|
-
})
|
|
1207
|
-
};
|
|
1208
|
-
/** OB11 segment → canonical 元素(未知 type 兜底按 xml 处理,保持既有行为)。 */
|
|
1266
|
+
/**
|
|
1267
|
+
* OB11 segment → canonical 元素(未知 type 兜底按 xml 处理,保持既有行为)。
|
|
1268
|
+
* 入参已由 isOB11MessageSegment 收窄;类型侧调用(内部 CQ 码生成 / 接收方向翻译)
|
|
1269
|
+
* 直接传 OB11MessageSegment,default 分支仅在运行时出现意外 type 时命中。
|
|
1270
|
+
*/
|
|
1209
1271
|
function segmentToCanonical(seg) {
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1272
|
+
const rawSegment = seg;
|
|
1273
|
+
switch (seg.type) {
|
|
1274
|
+
case "text":
|
|
1275
|
+
case "string": return {
|
|
1276
|
+
type: "text",
|
|
1277
|
+
text: seg.data.text
|
|
1278
|
+
};
|
|
1279
|
+
case "at": return canonicalAt(String(seg.data.qq), seg.data.name);
|
|
1280
|
+
case "face": return {
|
|
1281
|
+
type: "face",
|
|
1282
|
+
id: String(seg.data.id)
|
|
1283
|
+
};
|
|
1284
|
+
case "image": return canonicalMedia("image", seg.data.file, seg.data.url);
|
|
1285
|
+
case "record": return canonicalMedia("voice", seg.data.file, seg.data.url);
|
|
1286
|
+
case "video": return canonicalMedia("video", seg.data.file, seg.data.url);
|
|
1287
|
+
case "reply": return {
|
|
1288
|
+
type: "reply",
|
|
1289
|
+
messageId: String(seg.data.id)
|
|
1290
|
+
};
|
|
1291
|
+
case "forward": return {
|
|
1292
|
+
type: "forward",
|
|
1293
|
+
messageIds: [String(seg.data.id)]
|
|
1294
|
+
};
|
|
1295
|
+
case "json": return {
|
|
1296
|
+
type: "json",
|
|
1297
|
+
raw: seg.data.data
|
|
1298
|
+
};
|
|
1299
|
+
case "xml": return {
|
|
1300
|
+
type: "xml",
|
|
1301
|
+
raw: seg.data.data
|
|
1302
|
+
};
|
|
1303
|
+
default: {
|
|
1304
|
+
const data = isRecord(rawSegment) ? rawSegment["data"] : void 0;
|
|
1305
|
+
return {
|
|
1306
|
+
type: "xml",
|
|
1307
|
+
raw: isRecord(data) ? data["data"] : void 0
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1214
1311
|
}
|
|
1215
1312
|
/** 已知 CQ 类型 → segment 构造器。 */
|
|
1216
1313
|
const CQ_SEGMENT_BUILDERS = {
|
|
@@ -1513,7 +1610,7 @@ const GROUP_FILE_BUS_ID = 102;
|
|
|
1513
1610
|
* 会把每条普通消息都判成「含该元素」——OB11 入站消息因此全部被误路由到
|
|
1514
1611
|
* grayTip notice 分支并静默丢弃(真机复现)。
|
|
1515
1612
|
*/
|
|
1516
|
-
function hasFileElement(msg) {
|
|
1613
|
+
function hasFileElement$1(msg) {
|
|
1517
1614
|
return msg.elements.some((el) => el.fileElement != null);
|
|
1518
1615
|
}
|
|
1519
1616
|
/** 基础字段(time/self_id/post_type)。 */
|
|
@@ -2325,7 +2422,7 @@ const sendGroupMsgSchema = z.object({
|
|
|
2325
2422
|
async function sendOb11Message(payload, deps) {
|
|
2326
2423
|
const peer = await resolveTargetPeer(payload, deps, "send_msg 需要 group_id 或 user_id");
|
|
2327
2424
|
let canonical;
|
|
2328
|
-
if (Array.isArray(payload.message)) canonical = segmentsToCanonical(payload.message);
|
|
2425
|
+
if (Array.isArray(payload.message)) canonical = segmentsToCanonical(parseOB11MessageSegments(payload.message));
|
|
2329
2426
|
else canonical = cqMessageToCanonical(payload.message);
|
|
2330
2427
|
const atUins = [];
|
|
2331
2428
|
for (const el of canonical) if (el.type === "at" && el.target !== "all") atUins.push(el.target);
|
|
@@ -2913,7 +3010,7 @@ var OneBotApi = class {
|
|
|
2913
3010
|
if (this.groupCache === void 0) return;
|
|
2914
3011
|
try {
|
|
2915
3012
|
const member = await this.groupCache.getMember(groupCode, uid);
|
|
2916
|
-
return member === void 0 ? void 0 : GroupApi.roleToString(member.role);
|
|
3013
|
+
return member === void 0 ? void 0 : GroupApi.roleToString(member.role ?? NTGroupMemberRole.UNSPECIFIED);
|
|
2917
3014
|
} catch (err) {
|
|
2918
3015
|
this.logger?.warn({
|
|
2919
3016
|
group: groupCode,
|
|
@@ -2931,7 +3028,7 @@ var OneBotApi = class {
|
|
|
2931
3028
|
if (this.groupCache === void 0) return;
|
|
2932
3029
|
try {
|
|
2933
3030
|
const out = /* @__PURE__ */ new Map();
|
|
2934
|
-
for (const member of await this.groupCache.getMembers(groupCode)) out.set(member.uid, GroupApi.roleToString(member.role));
|
|
3031
|
+
for (const member of await this.groupCache.getMembers(groupCode)) out.set(member.uid, GroupApi.roleToString(member.role ?? NTGroupMemberRole.UNSPECIFIED));
|
|
2935
3032
|
return out;
|
|
2936
3033
|
} catch (err) {
|
|
2937
3034
|
this.logger?.warn({
|
|
@@ -3170,28 +3267,35 @@ function pickUrl(item) {
|
|
|
3170
3267
|
}
|
|
3171
3268
|
return "";
|
|
3172
3269
|
}
|
|
3270
|
+
/** 元素项是否携带 fileElement 记录。 */
|
|
3271
|
+
function hasFileElement(el) {
|
|
3272
|
+
return isRecord(el) && isRecord(el["fileElement"]);
|
|
3273
|
+
}
|
|
3173
3274
|
/** 单个候选对象 → 归一化项(不可识别返回 null)。接受两类形状:
|
|
3174
3275
|
* ① RawMessage 型(elements[].fileElement——离线文件以消息推送到达的假设,
|
|
3175
3276
|
* 与 onRecvOfflineFileMsg 挂在 MsgService、UpdateC2CFileMsg 字符串一致)
|
|
3176
3277
|
* ② 专用实体型(顶层 fileName 或 fileInfo.fileName——getNewOfflineFileList 族) */
|
|
3177
3278
|
function narrowItem(item) {
|
|
3178
|
-
if (
|
|
3179
|
-
const
|
|
3180
|
-
if (Array.isArray(
|
|
3181
|
-
const
|
|
3182
|
-
if (
|
|
3279
|
+
if (!isRecord(item)) return null;
|
|
3280
|
+
const elements = item["elements"];
|
|
3281
|
+
if (Array.isArray(elements)) {
|
|
3282
|
+
const el = elements.find(hasFileElement);
|
|
3283
|
+
if (el === void 0) return null;
|
|
3284
|
+
const file = el.fileElement;
|
|
3183
3285
|
return {
|
|
3184
|
-
senderUin: pickUin(
|
|
3286
|
+
senderUin: pickUin(item),
|
|
3185
3287
|
name: typeof file["fileName"] === "string" ? file["fileName"] : "",
|
|
3186
3288
|
size: Number(file["fileSize"] ?? 0),
|
|
3187
3289
|
url: pickUrl(file)
|
|
3188
3290
|
};
|
|
3189
3291
|
}
|
|
3190
|
-
const
|
|
3191
|
-
|
|
3292
|
+
const fileInfo = item["fileInfo"];
|
|
3293
|
+
const file = isRecord(fileInfo) ? fileInfo : item;
|
|
3294
|
+
const fileName = file["fileName"];
|
|
3295
|
+
if (typeof fileName !== "string") return null;
|
|
3192
3296
|
return {
|
|
3193
|
-
senderUin: pickUin(
|
|
3194
|
-
name:
|
|
3297
|
+
senderUin: pickUin(item),
|
|
3298
|
+
name: fileName,
|
|
3195
3299
|
size: Number(file["fileSize"] ?? 0),
|
|
3196
3300
|
url: pickUrl(file)
|
|
3197
3301
|
};
|
|
@@ -3330,7 +3434,7 @@ var Ob11InboundMessage = class {
|
|
|
3330
3434
|
return;
|
|
3331
3435
|
}
|
|
3332
3436
|
if (!this.reportSelfMessage && String(msg.senderUin) === this.deps.selfUin) return;
|
|
3333
|
-
if (this.groupUploadAsNotice && msg.chatType === ChatType.GROUP && hasFileElement(msg)) {
|
|
3437
|
+
if (this.groupUploadAsNotice && msg.chatType === ChatType.GROUP && hasFileElement$1(msg)) {
|
|
3334
3438
|
const notice = toGroupUpload(msg, this.deps.selfUin);
|
|
3335
3439
|
if (notice !== null) {
|
|
3336
3440
|
this.deps.broadcast(notice);
|
|
@@ -3855,12 +3959,13 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
3855
3959
|
}
|
|
3856
3960
|
/** 请求分发(挂到 transport 的 onRequest):{ action, params, echo } → 注册表分发。 */
|
|
3857
3961
|
async handleRequest(req, respond) {
|
|
3858
|
-
const parsed = req
|
|
3859
|
-
const
|
|
3860
|
-
const
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
if (action === "")
|
|
3962
|
+
const parsed = isRecord(req) ? req : {};
|
|
3963
|
+
const action = parsed["action"];
|
|
3964
|
+
const echo = parsed["echo"];
|
|
3965
|
+
const params = parsed["params"] ?? {};
|
|
3966
|
+
let actionName = "";
|
|
3967
|
+
if (typeof action === "string") actionName = action;
|
|
3968
|
+
if (actionName === "") {
|
|
3864
3969
|
respond({
|
|
3865
3970
|
status: "failed",
|
|
3866
3971
|
retcode: 404,
|
|
@@ -3870,13 +3975,13 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
3870
3975
|
});
|
|
3871
3976
|
return;
|
|
3872
3977
|
}
|
|
3873
|
-
const act = this.registry.get(
|
|
3978
|
+
const act = this.registry.get(actionName);
|
|
3874
3979
|
if (act === void 0) {
|
|
3875
3980
|
respond({
|
|
3876
3981
|
status: "failed",
|
|
3877
3982
|
retcode: 404,
|
|
3878
3983
|
data: null,
|
|
3879
|
-
message: `未知动作: ${
|
|
3984
|
+
message: `未知动作: ${actionName}`,
|
|
3880
3985
|
...echo !== void 0 ? { echo } : {}
|
|
3881
3986
|
});
|
|
3882
3987
|
return;
|
|
@@ -3889,12 +3994,11 @@ var NapukettoOneBot11Adapter = class extends BaseProtocolAdapter {
|
|
|
3889
3994
|
};
|
|
3890
3995
|
/** 请求体 echo 字段提取(透传用;非对象 / 缺省 / undefined 返回空对象)。 */
|
|
3891
3996
|
function echoFieldOf(req) {
|
|
3892
|
-
if (req
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
}
|
|
3997
|
+
if (!isRecord(req)) return {};
|
|
3998
|
+
const echo = req["echo"];
|
|
3999
|
+
if (echo !== void 0) return { echo };
|
|
3896
4000
|
return {};
|
|
3897
4001
|
}
|
|
3898
4002
|
export { unescapeCqText as _, canonicalToCqMessage as a, cqMessageToSegments as c, segmentsToCqMessage as d, encodeCqCode as f, serializeCqParts as g, parseCqMessage as h, createOb11ActionRegistry as i, segmentsToCanonical as l, escapeCqText as m, assembleOb11Transports as n, canonicalToSegments as o, escapeCqParam as p, OneBotApi as r, cqMessageToCanonical as s, NapukettoOneBot11Adapter as t, ob11ConfigSchema as u, ob11ErrorCodeMap as v, MessageUnique as y };
|
|
3899
4003
|
|
|
3900
|
-
//# sourceMappingURL=onebot11-
|
|
4004
|
+
//# sourceMappingURL=onebot11-D_JlAsjy.mjs.map
|