Add invite and kick functions
This commit is contained in:
parent
5b91d77684
commit
bc286562e1
86
src/main.rs
86
src/main.rs
@ -53,56 +53,28 @@ fn main() {
|
|||||||
|
|
||||||
for event in events {
|
for event in events {
|
||||||
match event {
|
match event {
|
||||||
Event::Chat(message) => {
|
Event::Chat(message) => match message.chat_type {
|
||||||
if let ChatType::Tell(from, _) = message.chat_type {
|
ChatType::Tell(from, _) | ChatType::Group(from, _) => {
|
||||||
if let Some(content) = message.content().as_plain() {
|
if let Some(content) = message.content().as_plain() {
|
||||||
println!("{from}: {content}");
|
let mut words = content.split_whitespace();
|
||||||
|
|
||||||
if content == "inv" {
|
if let Some(command) = words.next() {
|
||||||
client.send_invite(from, InviteKind::Group);
|
match command {
|
||||||
} else if content.starts_with("inv") {
|
"inv" => invite_players(&mut client, words),
|
||||||
let player_names =
|
"kick" => {
|
||||||
content.trim_start_matches("inv").split_whitespace();
|
let sender_info = client.player_list().get(&from).unwrap();
|
||||||
|
|
||||||
for name in player_names {
|
if sender_info.uuid.to_string() == CRABO_UUID {
|
||||||
if let Some(player_id) =
|
kick_players(&mut client, words)
|
||||||
client.player_list().iter().find_map(|(id, info)| {
|
|
||||||
if info.player_alias == name {
|
|
||||||
Some(id)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
{
|
|
||||||
client.send_invite(player_id.clone(), InviteKind::Group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if content.starts_with("kick") {
|
|
||||||
let player_names =
|
|
||||||
content.trim_start_matches("kick").split_whitespace();
|
|
||||||
let sender_info = client.player_list().get(&from).unwrap();
|
|
||||||
|
|
||||||
if sender_info.uuid.to_string() == CRABO_UUID {
|
|
||||||
for name in player_names {
|
|
||||||
if let Some(player_id) =
|
|
||||||
client.player_list().iter().find_map(|(id, info)| {
|
|
||||||
if info.player_alias == name {
|
|
||||||
Some(id)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
{
|
|
||||||
client.kick_from_group(player_id.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
_ => {}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,3 +106,35 @@ fn connect_to_veloren(password: String) -> Client {
|
|||||||
))
|
))
|
||||||
.expect("Failed to create client instance.")
|
.expect("Failed to create client instance.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn invite_players<'a, T: Iterator<Item = &'a str>>(client: &mut Client, names: T) {
|
||||||
|
for name in names {
|
||||||
|
let find_id = client.player_list().iter().find_map(|(id, info)| {
|
||||||
|
if info.player_alias == name {
|
||||||
|
Some(id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(player_id) = find_id {
|
||||||
|
client.send_invite(player_id.clone(), InviteKind::Group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn kick_players<'a, T: Iterator<Item = &'a str>>(client: &mut Client, names: T) {
|
||||||
|
for name in names {
|
||||||
|
let find_id = client.player_list().iter().find_map(|(id, info)| {
|
||||||
|
if info.player_alias == name {
|
||||||
|
Some(id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(player_id) = find_id {
|
||||||
|
client.kick_from_group(player_id.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user