0.2.0 rust-namer
This commit is contained in:
parent
ba46f78ff8
commit
cc0420d8f4
1140
Cargo.lock
generated
1140
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
42
Cargo.toml
42
Cargo.toml
@ -1,29 +1,15 @@
|
|||||||
[package]
|
[workspace]
|
||||||
name = "tswn"
|
resolver = "2"
|
||||||
description = "tool shenjack work shop namerena"
|
members = [
|
||||||
version = "0.1.0"
|
"rust-namer",
|
||||||
edition = "2021"
|
"miner"
|
||||||
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# [miner.profile.release]
|
||||||
|
# opt-level = 3
|
||||||
[dependencies]
|
# codegen-units = 1
|
||||||
clap = { version = "4.5.1", features = ["derive"] }
|
# # panic = "abort"
|
||||||
base16384 = "0.1.0"
|
# debug = true
|
||||||
|
# strip = false
|
||||||
tracing = "0.1.40"
|
# lto = true
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["time"] }
|
# overflow-checks = false
|
||||||
chrono = "0.4.34"
|
|
||||||
colored = "2.1.0"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["simd"]
|
|
||||||
simd = []
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
opt-level = 3
|
|
||||||
codegen-units = 1
|
|
||||||
panic = "abort"
|
|
||||||
debug = true
|
|
||||||
strip = false
|
|
||||||
lto = true
|
|
||||||
overflow-checks = false
|
|
||||||
|
20
miner/Cargo.toml
Normal file
20
miner/Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "tswn"
|
||||||
|
description = "tool shenjack work shop namerena"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.5.1", features = ["derive"] }
|
||||||
|
base16384 = "0.1.0"
|
||||||
|
|
||||||
|
tracing = "0.1.40"
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["time"] }
|
||||||
|
chrono = "0.4.34"
|
||||||
|
colored = "2.1.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["simd"]
|
||||||
|
simd = []
|
@ -77,7 +77,6 @@ pub fn predict_13(name: &Namer) -> f64 {
|
|||||||
sum += target[i] * xuping13::MODULE[i];
|
sum += target[i] * xuping13::MODULE[i];
|
||||||
check[i] = target[i] * xuping13::MODULE[i];
|
check[i] = target[i] * xuping13::MODULE[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "simd"))]
|
#[cfg(not(feature = "simd"))]
|
||||||
#[cfg(feature = "simd")]
|
#[cfg(feature = "simd")]
|
@ -528,7 +528,7 @@ mod test {
|
|||||||
fn shadow_test() {
|
fn shadow_test() {
|
||||||
let name = Namer::new_unchecked("一一七啺埀㴁?shadow");
|
let name = Namer::new_unchecked("一一七啺埀㴁?shadow");
|
||||||
let prop_vec: Vec<u32> = vec![240, 89, 69, 82, 65, 75, 49, 49];
|
let prop_vec: Vec<u32> = vec![240, 89, 69, 82, 65, 75, 49, 49];
|
||||||
|
|
||||||
assert_eq!(name.name_prop.to_vec(), prop_vec);
|
assert_eq!(name.name_prop.to_vec(), prop_vec);
|
||||||
}
|
}
|
||||||
}
|
}
|
1457
rust-namer/Cargo.lock
generated
1457
rust-namer/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust-namer"
|
name = "rust-namer"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -10,3 +10,4 @@ serde_json = "1.0"
|
|||||||
tokio = { version = "1.36.0", features = ["full"] }
|
tokio = { version = "1.36.0", features = ["full"] }
|
||||||
|
|
||||||
thirtyfour = "0.31.0"
|
thirtyfour = "0.31.0"
|
||||||
|
clap = "4.5.4"
|
||||||
|
@ -1,14 +1,64 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
mod runner;
|
mod runner;
|
||||||
|
|
||||||
|
const ABOUT: &str = "名竞-CLI 版 by shenjack";
|
||||||
|
const LONG_ABOUT: &str = r#"名竞-CLI 版 by shenjack
|
||||||
|
基于 msedge webdriver"#;
|
||||||
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
#[derive(Parser, Debug, Clone)]
|
||||||
|
#[command(version = VERSION, about = ABOUT, long_about = LONG_ABOUT, name = "namerena-cli-webderiver")]
|
||||||
|
pub struct CliArg {
|
||||||
|
#[arg(
|
||||||
|
short,
|
||||||
|
long = "target-url",
|
||||||
|
default_value = "https://shenjack.top:82/md5",
|
||||||
|
help = "使用的名竞 URL",
|
||||||
|
long_help = "使用的名竞 URL, 可以用于指定到不同的名竞服务端点"
|
||||||
|
)]
|
||||||
|
pub target_url: String,
|
||||||
|
#[arg(
|
||||||
|
short,
|
||||||
|
long = "input",
|
||||||
|
default_value = "aaaaaaa\\nnnnnn",
|
||||||
|
help = "输入的队伍名, 以\\n分隔",
|
||||||
|
long_help = "输入要对战的队伍名称, 用 \\n 分割, 会自动替换为换行符\n请不要输入任何!test!相关的测号内容, 会导致报错"
|
||||||
|
)]
|
||||||
|
pub input: String,
|
||||||
|
#[arg(short = 'c',
|
||||||
|
long = "cli",
|
||||||
|
default_value = None,
|
||||||
|
help = "是否输出为 CLI 格式",
|
||||||
|
long_help = "是否将输出切换为 json 的 CLI 格式, 默认为 false\n切换后可用于cli调用"
|
||||||
|
)]
|
||||||
|
pub is_cli: bool,
|
||||||
|
#[arg(
|
||||||
|
short = 'd',
|
||||||
|
long = "driver",
|
||||||
|
default_value = "http://localhost:9515",
|
||||||
|
help = "webdriver 的地址",
|
||||||
|
long_help = "使用的 msedge webdriver 地址"
|
||||||
|
)]
|
||||||
|
pub driver_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let web_runner = runner::WebDriverRunner::init("https://shenjack.top:82/md5").await?;
|
let args = CliArg::parse();
|
||||||
|
|
||||||
let result = web_runner.raw_flight("aaaaaaa\nnnnnn".to_string()).await?;
|
let replaced_input = args.input.replace("\\n", "\n");
|
||||||
|
|
||||||
println!("{}", result.str_without_pic());
|
let web_runner = runner::WebDriverRunner::init(&args).await?;
|
||||||
|
|
||||||
|
let result = web_runner.raw_flight(replaced_input).await?;
|
||||||
|
|
||||||
|
if args.is_cli {
|
||||||
|
println!("{}", result.cli_str());
|
||||||
|
} else {
|
||||||
|
println!("{}", result.str_without_pic());
|
||||||
|
}
|
||||||
|
|
||||||
web_runner.quit().await?;
|
web_runner.quit().await?;
|
||||||
|
|
||||||
|
@ -2,8 +2,11 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::json;
|
||||||
use thirtyfour::prelude::*;
|
use thirtyfour::prelude::*;
|
||||||
|
|
||||||
|
use crate::CliArg;
|
||||||
|
|
||||||
const INSERT_JS: &str = include_str!("../insert.js");
|
const INSERT_JS: &str = include_str!("../insert.js");
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -22,6 +25,17 @@ impl WinData {
|
|||||||
self.winners, self.first_kill, self.all
|
self.winners, self.first_kill, self.all
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cli_str(&self) -> String {
|
||||||
|
let json_string = json!(
|
||||||
|
{
|
||||||
|
"winners": self.winners,
|
||||||
|
"first_kill": self.first_kill,
|
||||||
|
"all": self.all
|
||||||
|
}
|
||||||
|
);
|
||||||
|
json_string.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -40,16 +54,14 @@ pub struct WebDriverRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for WebDriverRunner {
|
impl std::fmt::Display for WebDriverRunner {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Runner") }
|
||||||
write!(f, "Runner")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebDriverRunner {
|
impl WebDriverRunner {
|
||||||
pub async fn init(target_url: impl AsRef<str>) -> Result<Self> {
|
pub async fn init(config: &CliArg) -> Result<Self> {
|
||||||
let caps = DesiredCapabilities::edge();
|
let caps = DesiredCapabilities::edge();
|
||||||
let driver = WebDriver::new("http://localhost:9515", caps).await?;
|
let driver = WebDriver::new(&config.driver_url, caps).await?;
|
||||||
driver.goto(target_url.as_ref()).await?;
|
driver.goto(&config.target_url).await?;
|
||||||
driver.execute(INSERT_JS, vec![]).await?;
|
driver.execute(INSERT_JS, vec![]).await?;
|
||||||
// insert.js
|
// insert.js
|
||||||
// 预备环境
|
// 预备环境
|
||||||
@ -67,12 +79,9 @@ impl WebDriverRunner {
|
|||||||
|
|
||||||
go_btn.click().await?;
|
go_btn.click().await?;
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await; // 等一会
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await; // 等一会
|
||||||
fast_forward_btn.click().await?;
|
fast_forward_btn.click().await.ok();
|
||||||
|
|
||||||
done_target
|
done_target.wait_until().has_attribute("done", "true").await?;
|
||||||
.wait_until()
|
|
||||||
.has_attribute("done", "true")
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let win_data = self
|
let win_data = self
|
||||||
.driver
|
.driver
|
||||||
|
Loading…
Reference in New Issue
Block a user