MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / getRandomVideo

Method getRandomVideo

kkp/kkp.ts:218–299  ·  view source on GitHub ↗
(msg: Api.Message, client: any)

Source from the content-addressed store, hash-verified

216 await new Promise((resolve) => setTimeout(resolve, 2000));
217 }
218
219 const replyPromise = this.waitForBotReply(client, botEntity, 20000);
220 await client.sendMessage(botEntity, { message: "随机色色" });
221 const videoMessage = await replyPromise;
222
223 if (videoMessage && this.isVideoMessage(videoMessage)) {
224 const mediaToSend = videoMessage.media;
225
226 if (mediaToSend) {
227 const plainTextCaption = this.extractPlainText(videoMessage);
228
229 await msg.edit({ text: "📥 正在转发视频...", parseMode: "html" });
230
231 let fileInput = mediaToSend;
232
233 // 1. 视频画面剧透:手动重构 InputMediaDocument
234 if (
235 mediaToSend instanceof Api.MessageMediaDocument &&
236 mediaToSend.document instanceof Api.Document
237 ) {
238 const doc = mediaToSend.document;
239 fileInput = new Api.InputMediaDocument({
240 id: new Api.InputDocument({
241 id: doc.id,
242 accessHash: doc.accessHash,
243 fileReference: doc.fileReference,
244 }),
245 spoiler: true, // 🚨 画面剧透的关键
246 });
247 }
248
249 // 2. 文字剧透:手动构造 Entity
250 const finalCaption = plainTextCaption;
251
252 // 创建一个覆盖整个文本长度的剧透实体
253 // 这是最底层的实现方式,无视 ParseMode
254 const spoilerEntities = [
255 new Api.MessageEntitySpoiler({
256 offset: 0,
257 length: finalCaption.length,
258 }),
259 ];
260
261 await client.sendFile(msg.peerId, {
262 file: fileInput,
263 caption: finalCaption, // 这里只传纯文本
264 formattingEntities: spoilerEntities, // ✨ 直接传入格式化实体,不走HTML解析
265 spoiler: true, // 视频画面剧透(冗余备份)
266 forceDocument: false,
267 // ⚠️ 注意:不要在这里加 parseMode: "html",否则可能会覆盖 formattingEntities
268 });
269
270 try {
271 await client.markAsRead(botEntity);
272 } catch {}
273 await msg.delete();
274 } else {
275 await msg.edit({ text: "❌ 无法提取视频文件", parseMode: "html" });

Callers 1

KkpPluginClass · 0.95

Calls 7

waitForBotReplyMethod · 0.95
isVideoMessageMethod · 0.95
extractPlainTextMethod · 0.95
errorMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected