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

Function formatEntity

isalive/isalive.ts:38–74  ·  view source on GitHub ↗
(
  target: any,
  mention?: boolean,
  throwErrorIfFailed?: boolean
)

Source from the content-addressed store, hash-verified

36 const client = await getGlobalClient();
37 if (!client) throw new Error("Telegram 客户端未初始化");
38 if (!target) throw new Error("无效的目标");
39 let id: any;
40 let entity: any;
41 try {
42 entity = target?.className
43 ? target
44 : ((await client?.getEntity(target)) as any);
45 if (!entity) throw new Error("无法获取 entity");
46 id = entity.id;
47 if (!id) throw new Error("无法获取 entity id");
48 } catch (e: any) {
49 console.error(e);
50 if (throwErrorIfFailed)
51 throw new Error(
52 `无法获取 ${target} 的 entity: ${e?.message || "未知错误"}`
53 );
54 }
55 const displayParts: string[] = [];
56
57 if (entity?.title) displayParts.push(entity.title);
58 if (entity?.firstName) displayParts.push(entity.firstName);
59 if (entity?.lastName) displayParts.push(entity.lastName);
60
61 return {
62 id,
63 entity,
64 username: entity?.username || null,
65 display: displayParts.join(" ").trim(),
66 };
67}
68function getLastOnlineDays(user: Api.User): number | null {
69 if (!user.status) return null;
70 if (
71 user.status instanceof Api.UserStatusOnline ||
72 user.status instanceof Api.UserStatusRecently
73 ) {
74 return 0;
75 }
76 if (user.status instanceof Api.UserStatusOffline) {
77 if (user.status.wasOnline) {

Callers 1

IsAlivePluginClass · 0.70

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected