mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-20 11:59:53 +08:00
Compare commits
No commits in common. "4dfb17533d7068f377fefe68696b063a9a4098db" and "a99467dfbf7b8d6aca4367b595e7c4448fe25404" have entirely different histories.
4dfb17533d
...
a99467dfbf
|
@ -62,7 +62,7 @@ function fight(names) {
|
|||
* @returns
|
||||
*/
|
||||
function test_check(names) {
|
||||
var have_test = names.trim().startsWith("!test!");
|
||||
var have_test = names.startsWith("!test!");
|
||||
return have_test;
|
||||
}
|
||||
/**
|
||||
|
@ -141,87 +141,34 @@ function score_callback(names, callback) {
|
|||
});
|
||||
});
|
||||
}
|
||||
function run_any(names, round) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, md5_module.run_any(names, round)];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
var out_limit = 1000;
|
||||
function wrap_any(names, round) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var result, win_rate_1, win_rate_str, output_str_1, output_datas_1, win_rate_2, output_str_2, output_datas_2;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, run_any(names, round)];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
if ('message' in result) {
|
||||
// 对战结果
|
||||
return [2 /*return*/, "\u8D62\u5BB6:|".concat(result.source_plr, "|")];
|
||||
}
|
||||
else if ('win_count' in result) {
|
||||
win_rate_1 = result.win_count * 100 / round;
|
||||
win_rate_str = win_rate_1.toFixed(4);
|
||||
output_str_1 = "\u6700\u7EC8\u80DC\u7387:|".concat(win_rate_str, "%|(").concat(round, "\u8F6E)");
|
||||
// 每 500 轮, 输出一次
|
||||
if (round > out_limit) {
|
||||
output_datas_1 = [];
|
||||
result.raw_data.forEach(function (data, index) {
|
||||
if (data.round % out_limit === 0) {
|
||||
output_datas_1.push(data);
|
||||
}
|
||||
});
|
||||
output_datas_1.forEach(function (data, index) {
|
||||
var win_rate = data.win_count * 100 / data.round;
|
||||
output_str_1 += "\n".concat(win_rate.toFixed(2), "%(").concat(data.round, ")");
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, output_str_1];
|
||||
// } else if ('score' in result) {
|
||||
}
|
||||
else {
|
||||
win_rate_2 = (result.score * 10000 / round).toFixed(2);
|
||||
output_str_2 = "\u5206\u6570:|".concat(win_rate_2, "|(").concat(round, "\u8F6E)");
|
||||
if (round > out_limit) {
|
||||
output_datas_2 = [];
|
||||
result.raw_data.forEach(function (data, index) {
|
||||
if (data.round % out_limit === 0) {
|
||||
output_datas_2.push(data);
|
||||
}
|
||||
});
|
||||
output_datas_2.forEach(function (data, index) {
|
||||
var win_rate = (data.score / data.round * 10000).toFixed(2);
|
||||
output_str_2 += "\n".concat(win_rate, "(").concat(data.round, ")");
|
||||
});
|
||||
}
|
||||
return [2 /*return*/, output_str_2];
|
||||
}
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// export {
|
||||
// type FightResult,
|
||||
// type WinRate,
|
||||
// type WinRateResult,
|
||||
// type WinRateCallback,
|
||||
// type Score,
|
||||
// type ScoreResult,
|
||||
// type ScoreCallback,
|
||||
// fight,
|
||||
// win_rate,
|
||||
// win_rate_callback,
|
||||
// score,
|
||||
// score_callback,
|
||||
// };
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var fs, path, names, start_time, result, end_time;
|
||||
var fs, path, names, result;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
fs = require("fs");
|
||||
path = require("path");
|
||||
names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8");
|
||||
start_time = Date.now();
|
||||
return [4 /*yield*/, wrap_any(names, 10000)];
|
||||
return [4 /*yield*/, md5_module.run_any(names, 50000)];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
end_time = Date.now();
|
||||
// console.log(`赢家:|${result.source_plr}|`);
|
||||
console.log(result);
|
||||
console.log("Node.js \u8017\u65F6: ".concat(end_time - start_time, " ms"));
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ type WinRate = {
|
|||
* 胜率的数据结构
|
||||
*/
|
||||
type WinRateResult = {
|
||||
win_count: number;
|
||||
souce: number;
|
||||
raw_data: WinRate[];
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,7 @@ type Score = {
|
|||
* 分数的数据结构
|
||||
*/
|
||||
type ScoreResult = {
|
||||
score: number;
|
||||
source: number;
|
||||
raw_data: Score[];
|
||||
};
|
||||
|
||||
|
@ -76,7 +76,7 @@ async function fight(names: string): Promise<FightResult> {
|
|||
* @returns
|
||||
*/
|
||||
function test_check(names: string): boolean {
|
||||
const have_test = names.trim().startsWith("!test!");
|
||||
const have_test = names.startsWith("!test!");
|
||||
|
||||
return have_test;
|
||||
}
|
||||
|
@ -135,58 +135,20 @@ async function score_callback(
|
|||
return await md5_module.score_callback(names, callback);
|
||||
}
|
||||
|
||||
async function run_any(names: string, round: number): Promise<FightResult | WinRateResult | ScoreResult> {
|
||||
return await md5_module.run_any(names, round);
|
||||
}
|
||||
|
||||
const out_limit: number = 1000;
|
||||
|
||||
async function wrap_any(names: string, round: number): Promise<string> {
|
||||
const result = await run_any(names, round);
|
||||
if ('message' in result) {
|
||||
// 对战结果
|
||||
return `赢家:|${result.source_plr}|`;
|
||||
} else if ('win_count' in result) {
|
||||
// 胜率结果
|
||||
const win_rate = result.win_count * 100 / round;
|
||||
let win_rate_str = win_rate.toFixed(4);
|
||||
let output_str = `最终胜率:|${win_rate_str}%|(${round}轮)`;
|
||||
// 每 500 轮, 输出一次
|
||||
if (round > out_limit) {
|
||||
// 把所有要找的数据拿出来
|
||||
let output_datas: WinRate[] = [];
|
||||
result.raw_data.forEach((data, index) => {
|
||||
if (data.round % out_limit === 0) {
|
||||
output_datas.push(data);
|
||||
}
|
||||
});
|
||||
output_datas.forEach((data, index) => {
|
||||
const win_rate = data.win_count * 100 / data.round;
|
||||
output_str += `\n${win_rate.toFixed(2)}%(${data.round})`;
|
||||
});
|
||||
}
|
||||
return output_str;
|
||||
// } else if ('score' in result) {
|
||||
} else {
|
||||
// 分数结果其实还是个胜率, 不过需要 * 100
|
||||
const win_rate = (result.score * 10000 / round).toFixed(2);
|
||||
let output_str = `分数:|${win_rate}|(${round}轮)`;
|
||||
if (round > out_limit) {
|
||||
// 把所有要找的数据拿出来
|
||||
let output_datas: Score[] = [];
|
||||
result.raw_data.forEach((data, index) => {
|
||||
if (data.round % out_limit === 0) {
|
||||
output_datas.push(data);
|
||||
}
|
||||
});
|
||||
output_datas.forEach((data, index) => {
|
||||
const win_rate = (data.score / data.round * 10000).toFixed(2);
|
||||
output_str += `\n${win_rate}(${data.round})`;
|
||||
});
|
||||
}
|
||||
return output_str;
|
||||
}
|
||||
}
|
||||
// export {
|
||||
// type FightResult,
|
||||
// type WinRate,
|
||||
// type WinRateResult,
|
||||
// type WinRateCallback,
|
||||
// type Score,
|
||||
// type ScoreResult,
|
||||
// type ScoreCallback,
|
||||
// fight,
|
||||
// win_rate,
|
||||
// win_rate_callback,
|
||||
// score,
|
||||
// score_callback,
|
||||
// };
|
||||
|
||||
async function main() {
|
||||
// 从相对位置导入内容
|
||||
|
@ -195,13 +157,9 @@ async function main() {
|
|||
|
||||
const names = fs.readFileSync(path.resolve(__dirname, "input.txt"), "utf-8");
|
||||
// const result = await fight(names);
|
||||
// const result = await md5_module.run_any(names, 50000);
|
||||
const result = await md5_module.run_any(names, 50000);
|
||||
// console.log(`赢家:|${result.source_plr}|`);
|
||||
const start_time = Date.now();
|
||||
const result = await wrap_any(names, 10000);
|
||||
const end_time = Date.now();
|
||||
console.log(result);
|
||||
console.log(`Node.js 耗时: ${end_time - start_time} ms`);
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const _version_ = "0.3.0";
|
||||
const _version_ = "0.2.0";
|
||||
|
||||
// let name_input = "!test!\n\natest\n\ntest2";
|
||||
// let name_input = "!test!\n\nthis_is_a";
|
||||
|
@ -26,9 +26,9 @@ let assets_data = {
|
|||
};
|
||||
|
||||
let run_env = {
|
||||
from_code: (typeof window === "undefined"),
|
||||
is_node: (typeof Bun === "undefined"),
|
||||
is_bun: (typeof Bun !== "undefined"),
|
||||
from_code: (typeof window == "undefined"),
|
||||
is_node: (typeof Bun == "undefined"),
|
||||
is_bun: (typeof Bun != "undefined"),
|
||||
version: _version_,
|
||||
};
|
||||
|
||||
|
@ -196,16 +196,16 @@ if (run_env.from_code) {
|
|||
}
|
||||
|
||||
global.document = {
|
||||
createElement: (tag) => {
|
||||
createElement: function (tag) {
|
||||
// return fake_element.fake_init(tag);
|
||||
return new fake_element(tag);
|
||||
},
|
||||
createTextNode: (data) => {
|
||||
createTextNode: function (data) {
|
||||
let node = new fake_element("text");
|
||||
node.innerHTML = data;
|
||||
return node;
|
||||
},
|
||||
querySelector: (tag) => {
|
||||
querySelector: function (tag) {
|
||||
// 搜索一下有没有这个元素
|
||||
logger.debug("querySelector", tag);
|
||||
for (let i = 0; i < stored_elements.length; i++) {
|
||||
|
@ -21795,7 +21795,7 @@ const runner = {
|
|||
// 如果数据长度等于 round,说明数据已经全部返回
|
||||
if (run_round >= target_round) {
|
||||
stop_bomb = true;
|
||||
resolve({ win_count: win_count, raw_data: win_datas });
|
||||
resolve({ score: win_count, raw_data: win_datas });
|
||||
}
|
||||
});
|
||||
main(names);
|
||||
|
@ -21811,7 +21811,7 @@ const runner = {
|
|||
let result = callback(run_round, win_count);
|
||||
if (!result) {
|
||||
stop_bomb = true;
|
||||
resolve({ win_count: win_count, raw_data: win_datas });
|
||||
resolve({ score: win_count, raw_data: win_datas });
|
||||
}
|
||||
});
|
||||
main(names);
|
||||
|
@ -21856,7 +21856,7 @@ const runner = {
|
|||
data.push({ round: run_round, win_count: win_count });
|
||||
if (run_round >= round) {
|
||||
stop_bomb = true;
|
||||
resolve({ win_count: win_count, raw_data: data });
|
||||
resolve({ score: win_count, raw_data: data });
|
||||
}
|
||||
});
|
||||
finish_trigger.on("score_report", (run_round, score) => {
|
||||
|
@ -21868,7 +21868,7 @@ const runner = {
|
|||
});
|
||||
main(names);
|
||||
})
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
if (run_env.from_code) {
|
||||
|
|
|
@ -15,7 +15,7 @@ else:
|
|||
IcaNewMessage = TypeVar("NewMessage")
|
||||
IcaClient = TypeVar("IcaClient")
|
||||
|
||||
_version_ = "0.4.1"
|
||||
_version_ = "0.4.0"
|
||||
|
||||
COMMAND = "/namerena"
|
||||
|
||||
|
@ -56,7 +56,7 @@ def on_ica_message(msg: IcaNewMessage, client: IcaClient) -> None:
|
|||
# 发送结果
|
||||
end_time = time.time()
|
||||
reply = msg.reply_with(
|
||||
f"{out_result}{err_result}外部耗时:{end_time - start_time:.2f}s\n版本:{_version_}"
|
||||
f"{out_result}{err_result}\n耗时:{end_time - start_time:.2f}s\n版本:{_version_}"
|
||||
)
|
||||
client.send_message(reply)
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue
Block a user