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

Method getRandomPhotoSet

cosplay/cosplay.ts:165–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163 }
164
165 private async getRandomPhotoSet(): Promise<PhotoSet> {
166 return withRetry(async () => {
167 const randomPage = Math.floor(Math.random() * CONFIG.MAX_PAGES) + 1;
168 const pageUrl =
169 randomPage === 1 ? CONFIG.BASE_URL : `${CONFIG.BASE_URL}page/${randomPage}/`;
170
171 const html = await this.client.get(pageUrl).then((r) => r.data);
172 const links = this.extractLinks(html);
173
174 if (!links.length) {
175 throw new Error(`第${randomPage}页没有找到套图链接`);
176 }
177
178 const randomLink = links[Math.floor(Math.random() * links.length)];
179 const title = randomLink.split("/").filter(Boolean).pop() || "未知套图";
180
181 return { url: randomLink, title: title.replace(/-/g, " ") };
182 });
183 }
184
185 private extractLinks(html: string): string[] {
186 const $ = cheerio.load(html);

Callers 1

fetchImageUrlsMethod · 0.95

Calls 3

extractLinksMethod · 0.95
withRetryFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected