Improve clean-up system

This commit is contained in:
ErrorNoInternet 2023-01-18 15:22:20 +08:00
parent b8b077a813
commit 448bd443a6
Signed by untrusted user who does not match committer: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 13 additions and 3 deletions

View File

@ -260,7 +260,7 @@ pub async fn process_command(
let mut player_timestamps = state.player_timestamps.lock().unwrap().to_owned(); let mut player_timestamps = state.player_timestamps.lock().unwrap().to_owned();
let mut players = Vec::new(); let mut players = Vec::new();
for player_time_data in sorted_player_time_data { for player_time_data in sorted_player_time_data {
for (player, original_player_time_data) in player_timestamps.clone().iter() { for (player, original_player_time_data) in player_timestamps.to_owned().iter() {
if player_time_data == original_player_time_data.to_owned() { if player_time_data == original_player_time_data.to_owned() {
players.push(player.to_owned()); players.push(player.to_owned());
player_timestamps.remove(player); player_timestamps.remove(player);

View File

@ -302,7 +302,7 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
} }
if alert_command.len() >= 1 { if alert_command.len() >= 1 {
log_message(Bot, &"Executing alert shell command...".to_string()); log_message(Bot, &"Executing alert shell command...".to_string());
let command_name = alert_command[0].clone(); let command_name = alert_command[0].to_owned();
alert_command.remove(0); alert_command.remove(0);
log_error( log_error(
std::process::Command::new(command_name) std::process::Command::new(command_name)
@ -321,7 +321,17 @@ async fn handle(mut client: Client, event: Event, mut state: State) -> anyhow::R
*state.cleanup_second_counter.lock().unwrap() = 0; *state.cleanup_second_counter.lock().unwrap() = 0;
log_message(Bot, &"Cleaning up mob locations...".to_string()); log_message(Bot, &"Cleaning up mob locations...".to_string());
*state.mob_locations.lock().unwrap() = HashMap::new(); let mut mob_locations = state.mob_locations.lock().unwrap().to_owned();
let current_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
for (mob, position_time_data) in mob_locations.to_owned() {
if current_time - position_time_data.time > 1200 {
mob_locations.remove(&mob);
}
}
*state.mob_locations.lock().unwrap() = mob_locations;
} }
} }
Event::Packet(packet) => match packet.as_ref() { Event::Packet(packet) => match packet.as_ref() {