generated from Oliver/discord-bot-template
add deserializing
This commit is contained in:
parent
9492f378d3
commit
8e53f2a234
@ -7,12 +7,14 @@ use serde::Serialize;
|
||||
use tokio::time::Instant;
|
||||
use tracing::{debug, error, info, trace};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Channel {
|
||||
this: GuildChannel,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
#[serde(default)]
|
||||
children: Vec<Channel>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
#[serde(default)]
|
||||
messages: Vec<Message>,
|
||||
}
|
||||
|
||||
@ -27,12 +29,16 @@ impl Channel {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Server {
|
||||
#[serde(default)]
|
||||
name: String,
|
||||
channels: Vec<Channel>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
#[serde(default)]
|
||||
orphanage: Vec<GuildChannel>,
|
||||
#[serde(skip_serializing)]
|
||||
#[serde(default)]
|
||||
needs_clean: bool,
|
||||
}
|
||||
|
||||
@ -258,6 +264,13 @@ pub async fn scrape_all(ctx: Context<'_>, pretty_print: bool) -> Result<(), Erro
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn from_json() {
|
||||
let data = fs::read_to_string("server.json").unwrap();
|
||||
let server: Server = serde_json::from_str(&data).unwrap();
|
||||
|
||||
black_box(server);
|
||||
}
|
||||
|
||||
/// Get server's topology (and runs clean)
|
||||
async fn index(map: HashMap<ChannelId, GuildChannel>) -> Server {
|
||||
let mut server = Server::new();
|
||||
|
Loading…
Reference in New Issue
Block a user