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

Class AtAllPlugin

atall/atall.ts:58–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 description = help_text;
57
58 cmdHandlers = {
59 atall: async (msg: Api.Message) => {
60 try {
61 const client = await getGlobalClient();
62 if (!client) {
63 await msg.edit({ text: "❌ 无法获取客户端", parseMode: "html" });
64 return;
65 }
66
67 // 获取当前聊天
68 const chat = await msg.getChat();
69 if (!chat || !("id" in chat)) {
70 await msg.edit({ text: "❌ 此命令只能在群组中使用", parseMode: "html" });
71 return;
72 }
73
74 const chatId = String(chat.id);
75
76 // 显示处理中
77 const processingMsg = (await msg.edit({
78 text: "🔄 正在获取群组成员列表...",
79 parseMode: "html"
80 })) ?? msg;
81
82 // 获取所有群组成员
83 const participants = await client.getParticipants(chatId, {});
84
85 if (!participants || participants.length === 0) {
86 await processingMsg.edit({
87 text: "❌ 无法获取群组成员或群组为空",
88 parseMode: "html"
89 });
90 return;
91 }
92
93 // 生成@列表
94 let mentionList: string[] = [];
95
96 for (const participant of participants) {
97 // 跳过机器人自身
98 if (participant.bot) continue;
99
100 // 尝试获取用户实体
101 let userEntity;
102 try {
103 userEntity = await client.getEntity(participant.id);
104 } catch {
105 continue; // 跳过无法获取实体的用户
106 }
107
108 if (userEntity && "username" in userEntity && userEntity.username) {
109 // 有用户名的情况 - 直接使用@username
110 mentionList.push(`@${userEntity.username}`);
111 } else {
112 // 无用户名,使用mention链接
113 let displayName = "";
114 if ("firstName" in participant && participant.firstName) {
115 displayName = participant.firstName;

Callers

nothing calls this directly

Calls 5

splitMessagesByMentionFunction · 0.85
errorMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected