mirror of
https://github.com/plexusorg/IBConverter.git
synced 2024-12-22 09:37:37 +00:00
Fix issues with null checking for IPs (??) and also add support for reasons
This commit is contained in:
parent
00f4310344
commit
c74625957e
89
Cargo.lock
generated
89
Cargo.lock
generated
@ -7,38 +7,63 @@ name = "IBConverter"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "equivalent"
|
||||||
version = "1.1.0"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.11.2"
|
version = "0.14.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.8.1"
|
version = "2.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
|
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"equivalent",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
version = "0.5.4"
|
version = "0.5.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.66"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
@ -47,22 +72,60 @@ checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.137"
|
version = "1.0.186"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
|
checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.186"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_yaml"
|
name = "serde_yaml"
|
||||||
version = "0.8.24"
|
version = "0.9.25"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc"
|
checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
"yaml-rust",
|
"unsafe-libyaml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unsafe-libyaml"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yaml-rust"
|
name = "yaml-rust"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
@ -6,4 +6,5 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
yaml-rust = "0.4"
|
yaml-rust = "0.4"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.9.22"
|
||||||
|
serde_derive = "1.0.166"
|
28
src/main.rs
28
src/main.rs
@ -3,9 +3,17 @@ use std::{env, fs, io};
|
|||||||
use std::collections::{BTreeMap};
|
use std::collections::{BTreeMap};
|
||||||
use std::io::{Read};
|
use std::io::{Read};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use yaml_rust::{Yaml, YamlLoader};
|
use yaml_rust::{Yaml, YamlLoader};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum Value {
|
||||||
|
SingleString(String),
|
||||||
|
StringVec(Vec<String>),
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env::set_var("RUST_BACKTRACE", "full");
|
env::set_var("RUST_BACKTRACE", "full");
|
||||||
println!("Welcome to IBConverter. This program converts TotalFreedomMod indefinite bans to Plex's format.");
|
println!("Welcome to IBConverter. This program converts TotalFreedomMod indefinite bans to Plex's format.");
|
||||||
@ -26,36 +34,42 @@ fn main() {
|
|||||||
let file_data = fs::read_to_string(&path).expect("Unable to read this file! Perhaps it's corrupt or the file was not found.");
|
let file_data = fs::read_to_string(&path).expect("Unable to read this file! Perhaps it's corrupt or the file was not found.");
|
||||||
let yaml = &YamlLoader::load_from_str(&file_data).expect("This file couldn't be loaded as a YAML")[0];
|
let yaml = &YamlLoader::load_from_str(&file_data).expect("This file couldn't be loaded as a YAML")[0];
|
||||||
let parent_hash = yaml.as_hash().expect("Unable to load everything into a hash");
|
let parent_hash = yaml.as_hash().expect("Unable to load everything into a hash");
|
||||||
let mut map: BTreeMap<usize, BTreeMap<String, Vec<String>>> = BTreeMap::new();
|
let mut map: BTreeMap<usize, BTreeMap<String, Value>> = BTreeMap::new();
|
||||||
for i in 0..parent_hash.keys().len()
|
for i in 0..parent_hash.keys().len()
|
||||||
{
|
{
|
||||||
let k = parent_hash.iter().skip(i).next().unwrap().0;
|
let k = parent_hash.iter().skip(i).next().unwrap().0;
|
||||||
println!("Key: {:?}", k);
|
println!("Key: {:?}", k);
|
||||||
let mut data: BTreeMap<String, Vec<String>> = BTreeMap::new();
|
let mut data: BTreeMap<String, Value> = BTreeMap::new();
|
||||||
let mut names: Vec<String> = Vec::new();
|
let mut names: Vec<String> = Vec::new();
|
||||||
if k.as_str().is_some() {
|
if k.as_str().is_some() {
|
||||||
names.push(k.as_str().unwrap().to_string());
|
names.push(k.as_str().unwrap().to_string());
|
||||||
data.insert("users".to_string(), names);
|
data.insert("users".to_string(), Value::StringVec(names));
|
||||||
} else {
|
} else {
|
||||||
let str = String::from(k.to_owned().as_i64().clone().unwrap().to_string());
|
let str = String::from(k.to_owned().as_i64().clone().unwrap().to_string());
|
||||||
names.push(str);
|
names.push(str);
|
||||||
data.insert("users".to_string(), names);
|
data.insert("users".to_string(), Value::StringVec(names));
|
||||||
}
|
}
|
||||||
let hash = parent_hash[k].as_hash().expect("Couldn't load key as hash");
|
let hash = parent_hash[k].as_hash().expect("Couldn't load key as hash");
|
||||||
if hash.contains_key(&Yaml::String("uuid".to_string())) {
|
if hash.contains_key(&Yaml::String("uuid".to_string())) {
|
||||||
let mut uuids: Vec<String> = Vec::new();
|
let mut uuids: Vec<String> = Vec::new();
|
||||||
uuids.push(hash.get(&Yaml::String("uuid".to_string())).unwrap().to_owned().into_string().unwrap());
|
uuids.push(hash.get(&Yaml::String("uuid".to_string())).unwrap().to_owned().into_string().unwrap());
|
||||||
data.insert("uuids".to_string(), uuids);
|
data.insert("uuids".to_string(), Value::StringVec(uuids));
|
||||||
}
|
}
|
||||||
if hash.contains_key(&Yaml::String("ips".to_string())) {
|
if hash.contains_key(&Yaml::String("ips".to_string())) {
|
||||||
if hash.get(&Yaml::String("ips".to_string())).unwrap().is_array() {
|
if hash.get(&Yaml::String("ips".to_string())).unwrap().is_array() {
|
||||||
let mut ips: Vec<String> = Vec::new();
|
let mut ips: Vec<String> = Vec::new();
|
||||||
for x in hash.get(&Yaml::String("ips".to_string())).unwrap().as_vec().unwrap() {
|
for x in hash.get(&Yaml::String("ips".to_string())).unwrap().as_vec().unwrap() {
|
||||||
ips.push(x.to_owned().into_string().unwrap());
|
let ip = x.to_owned().into_string();
|
||||||
|
if ip.is_some() {
|
||||||
|
ips.push(ip.unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data.insert("ips".to_string(), ips);
|
data.insert("ips".to_string(), Value::StringVec(ips));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if hash.contains_key(&Yaml::String("reason".to_string())) {
|
||||||
|
data.insert("reason".to_string(), Value::SingleString(hash.get(&Yaml::String("reason".to_string())).unwrap().as_str().unwrap().to_string()));
|
||||||
|
}
|
||||||
map.insert(i, data);
|
map.insert(i, data);
|
||||||
println!("Inserted {}", i);
|
println!("Inserted {}", i);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user