让代码变得好看,允许玩家自定生成的用户名长度(随机字母部分)
This commit is contained in:
@@ -20,31 +20,11 @@ pub struct BotMessage {
|
||||
pub last_keepalive_sec: u64,
|
||||
}
|
||||
|
||||
// impl Clone for BotVariable {
|
||||
// fn clone(&self) -> Self {
|
||||
// Self { spam_file: self.spam_file.clone() }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 定义一个StreamType的特性,要求实现Read和Write,且含有connect函数
|
||||
pub trait StreamType: Read + Write {
|
||||
fn connect(server_addr: &str,proxy_addr: &str) -> Result<Self, Error> where Self: Sized;
|
||||
}
|
||||
|
||||
// *由于下面的Stream已经实现过connect了,所以这里没必要重复一遍
|
||||
// // 然后让Socks5Stream实现StreamType
|
||||
// impl StreamType for Socks5Stream{
|
||||
// fn connect(server_addr: &str,proxy_addr: &str) -> Result<Self, Error> where Self: Sized {
|
||||
// return Socks5Stream::connect(proxy_addr, server_addr);
|
||||
// }
|
||||
// }
|
||||
// // 再让TcpStream实现StreamType
|
||||
// impl StreamType for TcpStream {
|
||||
// fn connect(server_addr: &str,_: &str) -> Result<Self, Error> where Self: Sized {
|
||||
// return TcpStream::connect(server_addr);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Bot泛型版
|
||||
pub struct Bot<T: StreamType> {
|
||||
pub username: String,
|
||||
@@ -307,7 +287,7 @@ impl<T: StreamType> Bot<T> {
|
||||
&& !login_command_flag { // 登录3s后且未执行过登录命令
|
||||
let commands = self.config.login_commands().clone();
|
||||
for i in commands{
|
||||
self.send_command(i.to_string()).await.unwrap();
|
||||
self.send_command(i.to_string()).await.unwrap_or(());
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
info!("[{}/WORKER] Login commands executed!",self.username);
|
||||
|
||||
Reference in New Issue
Block a user