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

Function collectMessages

quote/quote.ts:1263–1294  ·  view source on GitHub ↗
(msg: Api.Message, args: QuoteArgs)

Source from the content-addressed store, hash-verified

1261function isGifBuffer(buffer: Buffer | undefined): boolean {
1262 return !!buffer && buffer.length >= 6 && (buffer.subarray(0, 6).toString("ascii") === "GIF87a" || buffer.subarray(0, 6).toString("ascii") === "GIF89a");
1263}
1264
1265function isAnimatedRasterBuffer(buffer: Buffer | undefined): boolean {
1266 return isWebmBuffer(buffer) || isGifBuffer(buffer);
1267}
1268
1269function bufferKind(buffer: Buffer | undefined): string {
1270 if (!buffer) return "none";
1271 if (isGifBuffer(buffer)) return "gif";
1272 if (isWebmBuffer(buffer)) return "webm";
1273 if (buffer.length >= 8 && buffer.subarray(1, 4).toString("ascii") === "PNG") return "png";
1274 if (buffer[0] === 0xff && buffer[1] === 0xd8) return "jpg";
1275 if (buffer[0] === 0x1f && buffer[1] === 0x8b) return "gzip/tgs";
1276 return `other:${buffer.subarray(0, 8).toString("hex")}`;
1277}
1278
1279async function probeWebmAlpha(buffer: Buffer): Promise<string> {
1280 const tmpBase = path.join(os.tmpdir(), `telebox_quote_alpha_${Date.now()}_${Math.random().toString(16).slice(2)}`);
1281 const input = `${tmpBase}.webm`;
1282 try {
1283 fs.writeFileSync(input, buffer);
1284 const out = await execFileCaptureAsync("ffprobe", [
1285 "-v", "error",
1286 "-select_streams", "v:0",
1287 "-show_entries", "stream=pix_fmt,width,height,duration:stream_tags=alpha_mode:format=duration",
1288 "-of", "default=noprint_wrappers=1",
1289 input,
1290 ], 10000);
1291 return out.trim().replace(/\s+/g, " ") || "empty-ffprobe";
1292 } catch (err: any) {
1293 return `probe-failed:${err?.message || err}`;
1294 } finally {
1295 try { if (fs.existsSync(input)) fs.unlinkSync(input); } catch (err) {
1296 console.debug("[quote] waitForStableFile loop error:", err?.message || err);
1297 }

Callers 1

handleQuoteMethod · 0.70

Calls 2

withTimeoutFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected