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

Function compositeWithEntryConfig

eat/eat.ts:229–357  ·  view source on GitHub ↗
(parmas: {
  entry: EntryConfig;
  msg: Api.Message;
  isEat2: boolean;
  trigger?: Api.Message;
})

Source from the content-addressed store, hash-verified

227}
228
229async function compositeWithEntryConfig(parmas: {
230 entry: EntryConfig;
231 msg: Api.Message;
232 isEat2: boolean;
233 trigger?: Api.Message;
234}): Promise<void> {
235 const { entry, msg, isEat2, trigger } = parmas;
236
237 const youAvatarBuffer = await downloadAvatar(msg, isEat2);
238 if (!youAvatarBuffer) return;
239
240 if (entry.stamp) {
241 const stampCfg = entry.stamp || {};
242 const size = stampCfg.size ?? 512;
243 const scale = stampCfg.scale ?? 0.9;
244 const rotate = stampCfg.rotate ?? -12;
245 const opacity = stampCfg.opacity ?? 0.6;
246
247 const stampBuf = await getAssetBuffer(entry.url);
248
249 const base = await sharp(youAvatarBuffer)
250 .resize(size, size, { fit: "cover" })
251 .png()
252 .toBuffer();
253
254 const stampRotated = await sharp(stampBuf)
255 .resize({ width: Math.round(size * scale) })
256 .rotate(rotate, { background: { r: 0, g: 0, b: 0, alpha: 0 } })
257 .ensureAlpha()
258 .linear([1, 1, 1, opacity], [0, 0, 0, 0])
259 .png()
260 .toBuffer();
261
262 const stampFinal = await sharp(stampRotated)
263 .resize({ width: size, height: size, fit: "inside" })
264 .png()
265 .toBuffer();
266
267 const outBuffer = await sharp(base)
268 .composite([{ input: stampFinal, gravity: "center" }])
269 .webp({ lossless: true })
270 .toBuffer();
271
272 const file = new CustomFile("output.webp", outBuffer.length, "", outBuffer);
273 const { width = size, height = size } = await sharp(outBuffer).metadata();
274
275 const stickerAttr = new Api.DocumentAttributeSticker({
276 alt: entry.name,
277 stickerset: new Api.InputStickerSetEmpty(),
278 });
279
280 const imageSizeAttr = new Api.DocumentAttributeImageSize({
281 w: width,
282 h: height,
283 });
284
285 const filenameAttr = new Api.DocumentAttributeFilename({
286 fileName: "output.webp",

Callers 1

sendStickerFunction · 0.85

Calls 4

downloadAvatarFunction · 0.85
getAssetBufferFunction · 0.85
iconMaskedForFunction · 0.85
editMethod · 0.45

Tested by

no test coverage detected