Use weekly tags for veloren deps; Add kick_all

This commit is contained in:
Jeff 2024-06-16 08:09:59 -04:00
parent 7eefb6ef8e
commit 49e6f8a68b
4 changed files with 61 additions and 31 deletions

22
Cargo.lock generated
View File

@ -2543,7 +2543,7 @@ dependencies = [
[[package]]
name = "veloren-client"
version = "0.16.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"authc",
"byteorder",
@ -2569,7 +2569,7 @@ dependencies = [
[[package]]
name = "veloren-common"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"approx",
"bitflags 2.5.0",
@ -2609,7 +2609,7 @@ dependencies = [
[[package]]
name = "veloren-common-assets"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"assets_manager",
"dot_vox",
@ -2624,7 +2624,7 @@ dependencies = [
[[package]]
name = "veloren-common-base"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"directories-next",
"tracing",
@ -2633,7 +2633,7 @@ dependencies = [
[[package]]
name = "veloren-common-ecs"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"specs",
"tracing",
@ -2643,7 +2643,7 @@ dependencies = [
[[package]]
name = "veloren-common-i18n"
version = "0.1.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"hashbrown 0.13.2",
"rand",
@ -2653,7 +2653,7 @@ dependencies = [
[[package]]
name = "veloren-common-net"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"bincode",
"flate2",
@ -2671,7 +2671,7 @@ dependencies = [
[[package]]
name = "veloren-common-state"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"async-trait",
"bytes",
@ -2693,7 +2693,7 @@ dependencies = [
[[package]]
name = "veloren-common-systems"
version = "0.10.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"itertools",
"ordered-float",
@ -2711,7 +2711,7 @@ dependencies = [
[[package]]
name = "veloren-network"
version = "0.3.0"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"async-channel",
"async-trait",
@ -2736,7 +2736,7 @@ dependencies = [
[[package]]
name = "veloren-network-protocol"
version = "0.6.1"
source = "git+https://gitlab.com/veloren/veloren?branch=master#c205a1fae21ae92a85695b10428e06eade31fc32"
source = "git+https://gitlab.com/veloren/veloren?tag=weekly#5c0299ef8223927796e6f6d3062a1a144803a3cf"
dependencies = [
"async-trait",
"bitflags 2.5.0",

View File

@ -5,9 +5,9 @@ edition = "2021"
[dependencies]
tokio = "1.38.0"
veloren-common = { git = "https://gitlab.com/veloren/veloren", branch = "master", features = ["no-assets"] }
veloren-client = { git = "https://gitlab.com/veloren/veloren", branch = "master" }
veloren-common-net = { git = "https://gitlab.com/veloren/veloren", branch = "master" }
veloren-common = { git = "https://gitlab.com/veloren/veloren", features = ["no-assets"], tag = "weekly" }
veloren-client = { git = "https://gitlab.com/veloren/veloren", tag = "weekly" }
veloren-common-net = { git = "https://gitlab.com/veloren/veloren", tag = "weekly" }
toml = "0.8.14"
serde = { version = "1.0.203", features = ["derive"] }
env_logger = "0.11.3"

View File

@ -31,7 +31,7 @@ impl Bot {
info!("Connecting to veloren");
let client = connect_to_veloren(username, password)?;
let clock = Clock::new(Duration::from_secs_f64(0.034));
let clock = Clock::new(Duration::from_secs_f64(1.0 / 60.0));
Ok(Bot {
client,
@ -101,6 +101,12 @@ impl Bot {
&sender_info,
)?;
}
ChatType::Offline(uid) => {
self.client.kick_from_group(uid);
}
ChatType::CommandError => {
eprintln!("Command Error!")
}
_ => {}
}
}
@ -109,6 +115,24 @@ impl Bot {
}
fn handle_message(&mut self, content: &str, sender: &PlayerInfo) -> Result<(), String> {
if content == "inv" {
info!("Inviting {}", sender.player_alias);
let uid = self.find_uid(&sender.player_alias)?;
self.client.send_invite(uid, InviteKind::Group);
}
if content == "kick_all" && self.admin_list.contains(&sender.uuid) {
info!("Kicking everyone");
let group_members = self.client.group_members().clone();
for (uid, _) in group_members {
self.client.kick_from_group(uid);
}
}
let mut words = content.split_whitespace();
let command = if let Some(command) = words.next() {
command
@ -120,6 +144,8 @@ impl Bot {
"admin" => {
if self.admin_list.contains(&sender.uuid) || self.admin_list.is_empty() {
for word in words {
info!("Adminifying {word}");
self.adminify_player(word)?;
}
}
@ -127,6 +153,8 @@ impl Bot {
"ban" => {
if self.admin_list.contains(&sender.uuid) {
for word in words {
info!("Banning {word}");
let uid = self.find_uid(word)?;
self.client.kick_from_group(uid);
@ -135,6 +163,8 @@ impl Bot {
}
}
"cheese" => {
info!("Saying 'I love cheese!' to {}", sender.player_alias);
let uid = self.find_uid(&sender.player_alias)?;
if self.client.group_members().contains_key(&uid) {
@ -144,22 +174,20 @@ impl Bot {
}
"inv" => {
if !self.ban_list.contains(&sender.uuid) {
if content == "inv" {
let uid = self.find_uid(&sender.player_alias)?;
for word in words {
info!("Inviting {word}");
let uid = self.find_uid(word)?;
self.client.send_invite(uid, InviteKind::Group);
} else {
for word in words {
let uid = self.find_uid(word)?;
self.client.send_invite(uid, InviteKind::Group);
}
}
}
}
"kick" => {
if self.admin_list.contains(&sender.uuid) {
for word in words {
info!("Kicking {word}");
let uid = self.find_uid(word)?;
self.client.kick_from_group(uid);
@ -169,6 +197,8 @@ impl Bot {
"unban" => {
if self.admin_list.contains(&sender.uuid) {
for word in words {
info!("Unbanning {word}");
self.unban_player(word)?;
}
}
@ -180,8 +210,6 @@ impl Bot {
}
fn adminify_player(&mut self, name: &str) -> Result<(), String> {
info!("Adminifying {name}");
let uuid = self.find_uuid(name)?;
if !self.admin_list.contains(&uuid) && !self.ban_list.contains(&uuid) {
@ -202,8 +230,6 @@ impl Bot {
}
fn ban_player(&mut self, name: &str) -> Result<(), String> {
info!("Banning {name}");
let uuid = self.find_uuid(name)?;
if !self.admin_list.contains(&uuid) && !self.ban_list.contains(&uuid) {
@ -224,8 +250,6 @@ impl Bot {
}
fn unban_player(&mut self, name: &str) -> Result<(), String> {
info!("Unbanning {name}");
let uuid = self.find_uuid(name)?;
if let Some(uuid) = self
@ -275,7 +299,7 @@ impl Bot {
None
}
})
.ok_or(format!("Failed to find uid for player {}", name))
.ok_or(format!("Failed to find uuid for player {}", name))
}
}

View File

@ -6,6 +6,7 @@ use std::{
};
use bot::Bot;
use log::{error, info};
use serde::{Deserialize, Serialize};
use veloren_common::uuid::Uuid;
@ -19,6 +20,8 @@ struct Config {
impl Config {
fn read() -> Result<Self, String> {
info!("Reading config");
let config_path = var("CONFIG_PATH").map_err(|error| error.to_string())?;
let config_file_content = read_to_string(config_path).map_err(|error| error.to_string())?;
@ -26,6 +29,8 @@ impl Config {
}
fn write(&self) -> Result<(), String> {
info!("Writing config");
let config_path = var("CONFIG_PATH").map_err(|error| error.to_string())?;
let config_string = toml::to_string(self).map_err(|error| error.to_string())?;
@ -47,7 +52,8 @@ fn main() {
bot.select_character().expect("Failed to select character");
#[allow(unused_must_use)]
loop {
bot.tick().expect("Failed to run bot")
bot.tick().inspect_err(|e| error!("{e}"));
}
}