我也不知道这次提交是做什么的

This commit is contained in:
2026-07-22 02:18:01 +08:00
parent 2753fbba13
commit c8e5efe395
10 changed files with 2592 additions and 2580 deletions

View File

@@ -1,62 +1,62 @@
// 一些杂七杂八的小东西可以放在这
use std::sync::Arc;
use rand::distributions::Alphanumeric;
use rand::Rng;
use crate::configuration::Configuration;
// 处理json组件(有些TextComponent里面一堆extra看的我头皮发麻,所以整个这个)
pub fn parse_json_component(json: &str) -> String {
let data: serde_json::Value = serde_json::from_str(json).unwrap();
let mut res: String = String::new();
let text = data.get("text");
match text {
Some(t) => {
if t.is_string(){
res += t.as_str().unwrap();
}
}
None => {
let translate = data.get("translate");
match translate {
Some(t) => {
if t.is_string(){
res += t.as_str().unwrap();
}
}
None => {}
}
}
}
let extra = data.get("extra");
match extra {
Some(t) =>{
for i in t.as_array().unwrap(){
if !i.is_object(){
continue;
}
res += parse_json_component(i.to_string().as_str()).as_str();
}
}
None => {}
}
return res;
}
// 生成一个随机的用户名
// author: 通义
pub fn generate_string(len_min: i64, len_max: i64) -> String {
let mut rng = rand::thread_rng();
let len = rng.gen_range(len_min..=len_max);
rng.sample_iter(&Alphanumeric)
.take(len as usize)
.map(char::from)
.collect()
}
pub fn generate_username(config: &Arc<Configuration>) -> String {
config.username_prefix().to_string() + generate_string(
config.name_len_limit[0], config.name_len_limit[1]
).to_string().as_str()
// 一些杂七杂八的小东西可以放在这
use std::sync::Arc;
use rand::distributions::Alphanumeric;
use rand::Rng;
use crate::configuration::Configuration;
// 处理json组件(有些TextComponent里面一堆extra看的我头皮发麻,所以整个这个)
pub fn parse_json_component(json: &str) -> String {
let data: serde_json::Value = serde_json::from_str(json).unwrap();
let mut res: String = String::new();
let text = data.get("text");
match text {
Some(t) => {
if t.is_string(){
res += t.as_str().unwrap();
}
}
None => {
let translate = data.get("translate");
match translate {
Some(t) => {
if t.is_string(){
res += t.as_str().unwrap();
}
}
None => {}
}
}
}
let extra = data.get("extra");
match extra {
Some(t) =>{
for i in t.as_array().unwrap(){
if !i.is_object(){
continue;
}
res += parse_json_component(i.to_string().as_str()).as_str();
}
}
None => {}
}
return res;
}
// 生成一个随机的用户名
// author: 通义
pub fn generate_string(len_min: i64, len_max: i64) -> String {
let mut rng = rand::thread_rng();
let len = rng.gen_range(len_min..=len_max);
rng.sample_iter(&Alphanumeric)
.take(len as usize)
.map(char::from)
.collect()
}
pub fn generate_username(config: &Arc<Configuration>) -> String {
config.username_prefix().to_string() + generate_string(
config.name_len_limit[0], config.name_len_limit[1]
).to_string().as_str()
}