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

Method handleSet

music/music.ts:1943–2080  ·  view source on GitHub ↗
(msg: Api.Message, args: string[])

Source from the content-addressed store, hash-verified

1941 model: CONFIG.KEYS.MODEL,
1942 quality: CONFIG.KEYS.AUDIO_QUALITY,
1943 };
1944 const normalized = keyMap[rawKey.toLowerCase()] || rawKey;
1945
1946 // 针对音质做输入规范化与校验
1947 let finalValue = value;
1948 if (normalized === CONFIG.KEYS.AUDIO_QUALITY) {
1949 const v = value.trim().toLowerCase();
1950 // 接受 0..10 或 Xk / Xkbps / Xkb
1951 const vbrMatch = /^(?:[0-9]|10)$/.test(v);
1952 const kbpsMatch = /^(\d{2,3})\s*(k|kb|kbps)?$/.exec(v);
1953 if (vbrMatch) {
1954 finalValue = v; // VBR 等级
1955 } else if (kbpsMatch) {
1956 // 规范化为 128k 格式
1957 const kb = parseInt(kbpsMatch[1], 10);
1958 if ([64, 96, 128, 160, 192, 256, 320].includes(kb)) {
1959 finalValue = `${kb}k`;
1960 } else {
1961 await msg.edit({
1962 text: `❌ <b>音质无效</b>\n\n支持 <code>0..10</code> 或 <code>128k/192k/256k/320k</code>`,
1963 parseMode: "html",
1964 });
1965 return;
1966 }
1967 } else if (v === "" || v === "auto" || v === "best") {
1968 // 清空 = 自动(最佳可用)
1969 finalValue = "";
1970 } else {
1971 await msg.edit({
1972 text: `❌ <b>音质无效</b>\n\n支持 <code>0..10</code> 或 <code>128k/192k/256k/320k</code>`,
1973 parseMode: "html",
1974 });
1975 return;
1976 }
1977 }
1978
1979 const success = await ConfigManager.set(normalized, finalValue);
1980
1981 if (success) {
1982 // 根据不同的配置项给出友好提示
1983 let successMsg = `✅ <b>配置已更新</b>\n\n`;
1984
1985 switch (rawKey.toLowerCase()) {
1986 case "cookie":
1987 successMsg += `🍪 YouTube Cookie 已设置\n现在可以绕过地区限制了`;
1988 break;
1989 case "proxy":
1990 if (finalValue) {
1991 successMsg += `🌐 代理服务器已配置\n地址: <code>${Utils.escape(
1992 finalValue
1993 )}</code>`;
1994 } else {
1995 successMsg += `🌐 代理已清空\n现在将直连下载`;
1996 }
1997 break;
1998 case "api_key":
1999 successMsg += `🤖 AI 搜索功能已启用\n可以更智能地搜索音乐了`;
2000 break;

Callers 1

executeMethod · 0.95

Calls 4

execMethod · 0.80
editMethod · 0.45
setMethod · 0.45
escapeMethod · 0.45

Tested by

no test coverage detected