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

Function formatEntity

tmp_admin/tmp_admin.ts:309–348  ·  view source on GitHub ↗
(target: any, mention?: boolean, throwErrorIfFailed?: boolean)

Source from the content-addressed store, hash-verified

307 let id: any;
308 let entity: any;
309 try {
310 entity = target?.className ? target : await client.getEntity(target);
311 if (!entity) throw new Error("无法获取 entity");
312 id = entity.id;
313 if (!id) throw new Error("无法获取 entity id");
314 } catch (e: any) {
315 if (throwErrorIfFailed) {
316 throw new Error(`无法获取 ${target} 的 entity: ${e?.message || "未知错误"}`);
317 }
318 }
319
320 const displayParts: string[] = [];
321 if (entity?.title) displayParts.push(htmlEscape(entity.title));
322 if (entity?.firstName) displayParts.push(htmlEscape(entity.firstName));
323 if (entity?.lastName) displayParts.push(htmlEscape(entity.lastName));
324 if (entity?.username) {
325 displayParts.push(
326 mention ? `@${htmlEscape(entity.username)}` : codeTag(`@${entity.username}`)
327 );
328 }
329
330 if (id) {
331 displayParts.push(`<a href="tg://user?id=${id}">${id}</a>`);
332 } else if (!target?.className) {
333 displayParts.push(codeTag(target));
334 }
335
336 return {
337 id,
338 entity,
339 display: displayParts.join(" ").trim(),
340 };
341}
342
343class TmpAdminPlugin extends Plugin {
344 private jobs = new Map<string, TempAdminJob>();
345 private dbPromise?: Promise<Low<TmpAdminDB>>;
346 private dbQueue: Promise<void> = Promise.resolve();
347 private restorePromise: Promise<void>;
348
349 constructor() {
350 super();
351 this.restorePromise = this.restoreJobs().catch((error) => {

Callers 2

addTemporaryAdminMethod · 0.70
removeTemporaryAdminMethod · 0.70

Calls 2

htmlEscapeFunction · 0.70
codeTagFunction · 0.70

Tested by

no test coverage detected