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

Function ttsSet

t/t.ts:310–382  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

308 attributes: [new (Api as any).DocumentAttributeAudio({ duration: 0, voice: true })],
309 });
310 try { await fs.unlink(r.oggFile); await fs.unlink(r.mp3File); } catch {}
311 await deleteCommandMessage(msg); // 发送后删命令
312 } else {
313 await msg.edit({ text: "❌ 生成失败" });
314 }
315}
316
317// 角色/Key 设置
318async function ttsSet(msg: Api.Message) {
319 const userId = msg.senderId?.toString();
320 if (!userId) return;
321
322 const args = msg.text?.trim().split(/\s+/).slice(1) || []; // 去掉命令名后的参数
323 const userData = await loadUserData();
324
325 // 分页参数识别:.ts 或 .ts <页码> ——
326 const PAGE_SIZE = 20;
327 const maybePage = args.length === 1 && /^\d+$/.test(args[0]) ? parseInt(args[0], 10) : null;
328
329 //或者只有页码:分页展示角色列表
330 if (args.length === 0 || (maybePage !== null && args.length === 1)) {
331 const names = Object.keys(userData.roles);
332 const total = names.length;
333 const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
334 const page = Math.min(Math.max(maybePage ?? 1, 1), totalPages);
335
336 const start = (page - 1) * PAGE_SIZE;
337 const slice = names.slice(start, start + PAGE_SIZE);
338 const list = slice.map((n, i) => `${start + i + 1}. ${n}`).join("\n");
339
340 const text =
341 `🎭 可用角色(${total}) | 第 ${page}/${totalPages} 页\n` +
342 `当前:${userData.users[userId]?.defaultRole || "未设置"}\n\n` +
343 list +
344 `\n\n用法:\n` +
345 `• .ts 角色名 (切换)\n` +
346 `• .ts 角色名 角色ID (新增/更新并切换)\n` +
347 `• .ts 2 (查看第 2 页)`;
348
349 await msg.edit({ text });
350 return;
351 }
352
353 // 新增/更新角色并切换为默认
354 if (args.length >= 2) {
355 const roleName = args[0];
356 const roleId = args[1];
357
358 if (!roleName || !roleId) {
359 await msg.edit({ text: "❌ 参数不完整。用法:.ts 角色名 角色ID" });
360 return;
361 }
362
363 userData.roles[roleName] = roleId; // 新增或更新
364
365 if (!userData.users[userId]) {
366 userData.users[userId] = { apiKey: "", defaultRole: roleName, defaultRoleId: roleId };
367 } else {

Callers

nothing calls this directly

Calls 3

loadUserDataFunction · 0.85
saveUserDataFunction · 0.85
editMethod · 0.45

Tested by

no test coverage detected