Sync and rustify
This commit is contained in:
parent
3f16bfd086
commit
2ff05b1a19
@ -15,7 +15,6 @@ pub async fn data(
|
|||||||
|
|
||||||
// Send a GET request to the provided URL
|
// Send a GET request to the provided URL
|
||||||
let response = get(&url).await?.json::<HashMap<String, Value>>().await?;
|
let response = get(&url).await?.json::<HashMap<String, Value>>().await?;
|
||||||
// println!("{:?}", response);
|
|
||||||
|
|
||||||
// Extract the required values from the parsed JSON
|
// Extract the required values from the parsed JSON
|
||||||
let server = &response["server"];
|
let server = &response["server"];
|
||||||
@ -28,28 +27,25 @@ pub async fn data(
|
|||||||
let slot_cap = slots["capacity"].as_i64().unwrap();
|
let slot_cap = slots["capacity"].as_i64().unwrap();
|
||||||
let slot_cur = slots["used"].as_i64().unwrap();
|
let slot_cur = slots["used"].as_i64().unwrap();
|
||||||
|
|
||||||
ctx.send(|m| {
|
ctx.send(|m| m.embed(|e| e.color(crate::COLOR)
|
||||||
m.embed(|e| {
|
.author(|a|
|
||||||
e.color(crate::COLOR)
|
a.name(format!("{}/{}", slot_cur, slot_cap))
|
||||||
.author(|a|
|
)
|
||||||
a.name(format!("{}/{}", slot_cur, slot_cap))
|
.title(name)
|
||||||
)
|
.description("*Nobody is playing*")
|
||||||
.title(name)
|
.fields(vec![
|
||||||
.description("*Nobody is playing*")
|
("Map", map, true),
|
||||||
.fields(vec![
|
("Version", ver, true),
|
||||||
("Map", map, true),
|
("Time", "xx:xx", true),
|
||||||
("Version", ver, true),
|
("Slot usage", "xx/xx", true),
|
||||||
("Time", "xx:xx", true),
|
("Autosave", "xx", true),
|
||||||
("Slot usage", "xx/xx", true),
|
("Timescale", "0x", true)
|
||||||
("Autosave", "xx", true),
|
])
|
||||||
("Timescale", "0x", true)
|
.footer(|f|
|
||||||
])
|
f.text("Last updated")
|
||||||
.footer(|f|
|
)
|
||||||
f.text("Last updated")
|
.timestamp(poise::serenity_prelude::Timestamp::now())
|
||||||
)
|
)).await?;
|
||||||
.timestamp(poise::serenity_prelude::Timestamp::now())
|
|
||||||
})
|
|
||||||
}).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,6 @@ use crate::Error;
|
|||||||
/// Check if the bot is alive
|
/// Check if the bot is alive
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command)]
|
||||||
pub async fn ping(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
pub async fn ping(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
|
||||||
ctx.reply(format!("Powong! `{:?}`ms", ctx.ping().await.as_millis())).await?;
|
ctx.reply(format!("Powong! `{:?}`", ctx.ping().await)).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
27
src/main.rs
27
src/main.rs
@ -13,15 +13,13 @@ async fn on_ready(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
println!("Connected to API as {}", ready.user.name);
|
println!("Connected to API as {}", ready.user.name);
|
||||||
|
|
||||||
serenity::ChannelId(865673694184996888).send_message(&ctx.http, |m| {
|
serenity::ChannelId(865673694184996888).send_message(&ctx.http, |m| m.embed(|e|
|
||||||
m.embed(|e|
|
e.color(COLOR)
|
||||||
e.color(COLOR)
|
.thumbnail(ready.user.avatar_url().unwrap_or_default())
|
||||||
.thumbnail(ready.user.avatar_url().unwrap_or_default())
|
.author(|a|
|
||||||
.author(|a|
|
a.name(format!("{} is ready!", ready.user.name))
|
||||||
a.name(format!("{} is ready!", ready.user.name))
|
)
|
||||||
)
|
)).await?;
|
||||||
)
|
|
||||||
}).await?;
|
|
||||||
|
|
||||||
let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
|
let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
|
||||||
|
|
||||||
@ -58,10 +56,15 @@ async fn main() {
|
|||||||
commands::data::data()
|
commands::data::data()
|
||||||
],
|
],
|
||||||
pre_command: |ctx| Box::pin(async move {
|
pre_command: |ctx| Box::pin(async move {
|
||||||
println!("{} ran /{}", ctx.author().name, ctx.command().name)
|
let get_guild_name = match ctx.guild() {
|
||||||
}),
|
Some(guild) => guild.name.clone(),
|
||||||
|
None => String::from("DM")
|
||||||
|
};
|
||||||
|
println!("[{}] {} ran /{}", get_guild_name, ctx.author().name, ctx.command().qualified_name)
|
||||||
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}).setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework)))
|
})
|
||||||
|
.setup(|ctx, ready, framework| Box::pin(on_ready(ctx, ready, framework)))
|
||||||
.build().await.expect("Error while building the client");
|
.build().await.expect("Error while building the client");
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Err(why) = client.start().await {
|
||||||
|
Loading…
Reference in New Issue
Block a user