(targetArg?: string, titleArg?: string)
| 248 | await resolveUserFromReplyOrArg(targetLike); |
| 249 | if (!userEntity) { |
| 250 | await msg.edit({ text: "请回复一条消息或提供 用户ID/用户名" }); |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | // Normalize title (support clear keywords) |
| 255 | const rawTitle = (title || "").trim(); |
| 256 | const titleIsProvided = title !== undefined; |
| 257 | const normalizedTitle = [""].includes(rawTitle.toLowerCase()) |
| 258 | ? "" |
| 259 | : rawTitle; |
| 260 | // Telegram 限制头衔最长 16 字符 |
| 261 | const limitedTitle = |
| 262 | normalizedTitle.length > 16 |
| 263 | ? normalizedTitle.slice(0, 16) |
| 264 | : normalizedTitle; |
| 265 | |
| 266 | // Per spec: 权限默认只有 ban。无论此前是否为管理员,均设置为仅 ban 权限。 |
| 267 | const participant = await getCurrentParticipant(userEntity); |
| 268 | // 不传头衔 = 清空 |
| 269 | let rankToUse = limitedTitle; // empty string clears |
| 270 | let adminRightsToUse: Api.ChatAdminRights = new Api.ChatAdminRights({ |
| 271 | banUsers: true, |
| 272 | }); |
| 273 | |
| 274 | try { |
| 275 | const client = await getGlobalClient(); |
| 276 | |
| 277 | const isChannelChat = chatEntity instanceof Api.Channel; |
| 278 | if (isChannelChat) { |
| 279 | await client?.invoke( |
| 280 | new Api.channels.EditAdmin({ |
| 281 | channel, |
| 282 | userId: userEntity, |
| 283 | adminRights: adminRightsToUse!, |
| 284 | rank: rankToUse, |
| 285 | }) |
| 286 | ); |
| 287 | // 等待服务器状态同步 |
| 288 | await sleep(1200); |
| 289 | } else { |
| 290 | // Basic group fallback: cannot set title/rights granularity |
| 291 | await client?.invoke( |
| 292 | new Api.messages.EditChatAdmin({ |
| 293 | chatId: (msg as any).chatId, |
| 294 | userId: userEntity, |
| 295 | isAdmin: true as any, |
| 296 | }) |
| 297 | ); |
| 298 | } |
| 299 | |
| 300 | // Verify rank actually updated |
| 301 | let appliedRank = rankToUse; |
| 302 | let selfIsCreator = false; |
| 303 | try { |
| 304 | selfIsCreator = await getSelfIsCreator(); |
| 305 | const refreshed = await getCurrentParticipant(userEntity); |
| 306 | if ( |
| 307 | refreshed instanceof Api.ChannelParticipantAdmin || |
nothing calls this directly
no test coverage detected