Add unban command; Fix cheese command
This commit is contained in:
parent
5d73e0d5ce
commit
4428785640
65
src/bot.rs
65
src/bot.rs
@ -123,18 +123,22 @@ impl Bot {
|
|||||||
self.ban_players(names)?;
|
self.ban_players(names)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"cheese" => {
|
"cheese" => self
|
||||||
self.client.chat_mode = ChatMode::Group;
|
.client
|
||||||
self.client.send_chat("I love cheese!".to_string());
|
.send_command("group".to_string(), vec!["I love cheese!".to_string()]),
|
||||||
}
|
|
||||||
"inv" => {
|
"inv" => {
|
||||||
if !self.ban_list.contains(sender) {
|
if !self.ban_list.contains(sender) {
|
||||||
self.invite_players(names)
|
self.invite_players(names);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"kick" => {
|
"kick" => {
|
||||||
if self.admin_list.contains(sender) {
|
if self.admin_list.contains(sender) {
|
||||||
self.kick_players(names)
|
self.kick_players(names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"unban" => {
|
||||||
|
if self.admin_list.contains(sender) {
|
||||||
|
self.unban_players(names)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -149,9 +153,9 @@ impl Bot {
|
|||||||
names: T,
|
names: T,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
for name in names {
|
for name in names {
|
||||||
if let Some(player_id) = self.find_uuid(&name) {
|
if let Some(uuid) = self.find_uuid(&name) {
|
||||||
if !self.admin_list.contains(&player_id) {
|
if !self.admin_list.contains(&uuid) && !self.ban_list.contains(&uuid) {
|
||||||
self.admin_list.push(player_id);
|
self.admin_list.push(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,9 +175,9 @@ impl Bot {
|
|||||||
|
|
||||||
fn ban_players<'a, T: Iterator<Item = &'a str>>(&mut self, names: T) -> Result<(), String> {
|
fn ban_players<'a, T: Iterator<Item = &'a str>>(&mut self, names: T) -> Result<(), String> {
|
||||||
for name in names {
|
for name in names {
|
||||||
if let Some(player_id) = self.find_uuid(&name) {
|
if let Some(uuid) = self.find_uuid(&name) {
|
||||||
if !self.ban_list.contains(&player_id) {
|
if !self.admin_list.contains(&uuid) && !self.ban_list.contains(&uuid) {
|
||||||
self.ban_list.push(player_id);
|
self.ban_list.push(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,11 +206,44 @@ impl Bot {
|
|||||||
|
|
||||||
fn kick_players<'a, T: Iterator<Item = &'a str>>(&mut self, names: T) {
|
fn kick_players<'a, T: Iterator<Item = &'a str>>(&mut self, names: T) {
|
||||||
for name in names {
|
for name in names {
|
||||||
if let Some(player_id) = self.find_uid(&name) {
|
if let Some(uid) = self.find_uid(&name) {
|
||||||
self.client.kick_from_group(player_id.clone());
|
if let Some(uuid) = self.find_uuid(&name) {
|
||||||
|
if !self.admin_list.contains(&uuid) {
|
||||||
|
self.client.kick_from_group(uid.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unban_players<'a, T: Iterator<Item = &'a str>>(&mut self, names: T) -> Result<(), String> {
|
||||||
|
let uuids = names
|
||||||
|
.filter_map(|name| self.find_uuid(name))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
for uuid in uuids {
|
||||||
|
if let Some(index) = self
|
||||||
|
.ban_list
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find_map(|(index, banned)| if &uuid == banned { Some(index) } else { None })
|
||||||
|
{
|
||||||
|
self.ban_list.remove(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let old_config = Config::read()?;
|
||||||
|
let new_config = Config {
|
||||||
|
username: old_config.username,
|
||||||
|
password: old_config.password,
|
||||||
|
admin_list: old_config.admin_list,
|
||||||
|
ban_list: self.ban_list.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
new_config.write()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn find_uid<'a>(&'a self, name: &str) -> Option<&'a Uid> {
|
fn find_uid<'a>(&'a self, name: &str) -> Option<&'a Uid> {
|
||||||
self.client.player_list().iter().find_map(|(id, info)| {
|
self.client.player_list().iter().find_map(|(id, info)| {
|
||||||
|
Loading…
Reference in New Issue
Block a user