| 86 | > = { |
| 87 | dbdj: async (msg: Api.Message, trigger?: Api.Message) => { |
| 88 | const startAt = Date.now(); |
| 89 | const replyAndDeleteMsg = async (message: string) => { |
| 90 | const replyTarget = trigger || msg; |
| 91 | await replyTarget.reply({ |
| 92 | message, |
| 93 | parseMode: "html", |
| 94 | linkPreview: false, |
| 95 | }); |
| 96 | try { |
| 97 | await msg.delete(); |
| 98 | } catch {} |
| 99 | }; |
| 100 | |
| 101 | try { |
| 102 | const parts = msg.message.trim().split(/\s+/); |
| 103 | // 期望格式: .dbdj 消息数 人数 文案... |
| 104 | const countStr = parts[1]; |
| 105 | const pickStr = parts[2]; |
| 106 | const note = parts.slice(3).join(" "); |
| 107 | |
| 108 | const scanCount = toInt(countStr); |
| 109 | const pickCount = toInt(pickStr); |
| 110 | |
| 111 | if (!scanCount || !pickCount || scanCount <= 0 || pickCount <= 0) { |
| 112 | await replyAndDeleteMsg( |
| 113 | `用法: <code>${mainPrefix}dbdj 消息数 人数 文案</code>\n例如: <code>${mainPrefix}dbdj 50 2 恭喜发财</code>`, |
| 114 | ); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | await msg.edit({ |
| 119 | text: `点兵点将...`, |
| 120 | parseMode: "html", |
| 121 | }); |
| 122 | |
| 123 | const client = msg.client!; |
| 124 | const offsetId = (msg.id || 1) - 1; // 从命令消息之前开始 |
| 125 | const messages = await safeGetMessages(client, msg.peerId, { |
| 126 | offsetId, |
| 127 | limit: scanCount, |
| 128 | }); |
| 129 | |
| 130 | // 收集有效用户: 仅统计来自用户的消息, 排除自身(out)、无 fromId 的消息 |
| 131 | const uniqueUserIds: number[] = []; |
| 132 | const seen = new Set<number>(); |
| 133 | const filtered = new Set<number>(); |
| 134 | |
| 135 | for (const m of messages) { |
| 136 | // 跳过自己发送的消息 |
| 137 | // if ((m as any).out) continue; |
| 138 | const from = (m as any).fromId as any; |
| 139 | const uid = from?.userId ? Number(from.userId) : undefined; |
| 140 | if (!uid || !Number.isFinite(uid)) continue; |
| 141 | |
| 142 | if (!seen.has(uid) && !filtered.has(uid)) { |
| 143 | const entity = (await formatEntity(uid))?.entity; |
| 144 | |
| 145 | if ( |
nothing calls this directly
no test coverage detected