MCPcopy Index your code
hub / github.com/TeleBoxOrg/TeleBox_Plugins / speedtest

Function speedtest

speedtest/speedtest.ts:1055–1511  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

1053}
1054
1055const speedtest = async (msg: Api.Message) => {
1056 const rawArgs = msg.message.slice(1).split(" ").slice(1);
1057 // 支持位置参数和旗标(如 --system 或 -s)
1058 const flags = rawArgs.filter(a => a.startsWith('--') || a.startsWith('-'));
1059 const args = rawArgs.filter(a => !a.startsWith('--') && !a.startsWith('-'));
1060 const command = args[0] || "";
1061 const useSystem = flags.includes('--system') || flags.includes('-s');
1062
1063 try {
1064 if (command === "list") {
1065 await msg.edit({ text: "🔍 正在获取服务器列表...", parseMode: "html" });
1066
1067 const servers = await getAllServers();
1068 if (servers.length === 0) {
1069 await msg.edit({
1070 text: "❌ <b>错误</b>\n\n无可用服务器",
1071 parseMode: "html",
1072 });
1073 return;
1074 }
1075
1076 const serverList = servers
1077 .slice(0, 20)
1078 .map(
1079 (server) =>
1080 `<code>${server.id}</code> - <code>${htmlEscape(
1081 server.name
1082 )}</code> - <code>${htmlEscape(server.location)}</code>`
1083 )
1084 .join("\n");
1085
1086 await msg.edit({
1087 text: `<blockquote><b>⚡️SPEEDTEST by OOKLA</b></blockquote>\n${serverList}`,
1088 parseMode: "html",
1089 });
1090 } else if (command === "set") {
1091 const serverId = parseInt(args[1]);
1092 if (!serverId || isNaN(serverId)) {
1093 await msg.edit({
1094 text: "❌ <b>参数错误</b>\n\n请指定有效的服务器ID\n例: <code>s set 12345</code>",
1095 parseMode: "html",
1096 });
1097 return;
1098 }
1099
1100 saveDefaultServer(serverId);
1101 await msg.edit({
1102 text: `<blockquote><b>⚡️SPEEDTEST by OOKLA</b></blockquote>\n<code>默认服务器已设置为 ${serverId}</code>`,
1103 parseMode: "html",
1104 });
1105 } else if (command === "clear") {
1106 removeDefaultServer();
1107 await msg.edit({
1108 text: "<blockquote><b>⚡️SPEEDTEST by OOKLA</b></blockquote>\n<code>默认服务器已清除</code>",
1109 parseMode: "html",
1110 });
1111 } else if (command === "config") {
1112 const defaultServer = getDefaultServer() || "Auto";

Callers

nothing calls this directly

Calls 15

getAllServersFunction · 0.85
saveDefaultServerFunction · 0.85
removeDefaultServerFunction · 0.85
getDefaultServerFunction · 0.85
getPreferredTypeFunction · 0.85
savePreferredTypeFunction · 0.85
getMessageOrderFunction · 0.85
checkNetworkConnectivityFunction · 0.85
testServerAvailabilityFunction · 0.85
autoFixSpeedtestFunction · 0.85
runSpeedtestFunction · 0.85

Tested by

no test coverage detected