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

Class CosplayPlugin

cosplay/cosplay.ts:400–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398}
399
400class CosplayPlugin extends Plugin {
401 private scraper: CosplayScraper | null = null;
402 private initPromise: Promise<void>;
403
404 constructor() {
405 super();
406 this.initPromise = this.initialize();
407 }
408
409 private async initialize(): Promise<void> {
410 await loadDependencies();
411 this.scraper = new CosplayScraper();
412 }
413
414 description: string = (() => {
415 const prefixes = getPrefixes();
416 const mainPrefix = prefixes[0];
417 return `从 cosplaytele.com 随机获取cosplay图片\n\n• ${mainPrefix}cos [数量] - 从随机套图中获取指定数量的cosplay图片 (默认1张,最大10张)\n• ${mainPrefix}cosplay [数量] - 同cos命令\n\n✨ 智能随机: 每次随机选择套图,确保多张图片来自同一套图,只获取高质量的gallery图片\n🔗 套图链接: 发送图片时自动包含原套图链接,方便查看完整套图`;
418 })();
419
420 cmdHandlers: Record<string, (msg: Api.Message) => Promise<void>> = {
421 cos: async (msg: Api.Message) => {
422 await this.initPromise;
423 if (!this.scraper) {
424 await msg.edit({ text: "❌ 插件初始化失败" });
425 return;
426 }
427
428 const count = parseImageCount(msg.text);
429 const client: any = msg.client;
430 let tempFiles: string[] = [];
431
432 try {
433 await msg.edit({ text: `正在从随机套图中获取 ${count} 张图片...` });
434
435 const result = await this.scraper.fetchImageUrls(count);
436
437 await msg.edit({
438 text: `从套图"${result.photoSet.title}"中找到 ${result.imageUrls.length} 张图片,正在下载...`,
439 });
440
441 tempFiles = await this.scraper.downloadImages(result.imageUrls);
442
443 await msg.edit({ text: `下载完成,正在发送...` });
444
445 await sendImages(client, msg.chatId, tempFiles, result.photoSet.url);
446
447 await msg.delete();
448 } catch (err: any) {
449 console.error("cosplay插件错误:", err);
450 await msg.edit({
451 text: `❌ 出错: ${err?.message || "未知错误"}`,
452 });
453 } finally {
454 if (tempFiles.length) {
455 await cleanup(tempFiles);
456 }
457 }

Callers

nothing calls this directly

Calls 8

parseImageCountFunction · 0.85
sendImagesFunction · 0.85
fetchImageUrlsMethod · 0.80
downloadImagesMethod · 0.80
errorMethod · 0.80
cleanupFunction · 0.70
editMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected