diff --git a/src/commands/general.rs b/src/commands/general.rs index c3cc6b5..c6a6933 100644 --- a/src/commands/general.rs +++ b/src/commands/general.rs @@ -22,7 +22,8 @@ use serenity::{ longcode, older, ping, - random_mute + random_mute, + uptime )] pub struct General; @@ -318,6 +319,40 @@ async fn random_mute(ctx: &Context, msg: &Message) -> CommandResult { Ok(()) } +#[command] +#[description("Get the uptime")] +async fn uptime(ctx: &Context, msg: &Message) -> CommandResult { + let now = std::time::Instant::now(); + let data = ctx.data.read().await; + let start = data + .get::() + .expect("Failed to get uptime"); + + let elapsed = now.duration_since(*start); + + let seconds = elapsed.as_secs(); + + let hours = seconds / (60 * 60); + let min = (seconds - (hours * 60 * 60)) / 60; + let seconds = seconds - (hours * 3600) - (min * 60); + + msg.channel_id.send_message(&ctx.http, |m| { + m.embed(|e| { + e.field( + "Uptime", + if hours > 0 { + format!("{}h {:02}min {:02}s", hours, min, seconds) + } else { + format!("{}min {:02}s", min, seconds) + }, + false, + ).colour((247, 76, 0)) + }) + }).await?; + + Ok(()) +} + // TODO JSON FILE enum Image { HackerMan(), diff --git a/src/commands/music/mod.rs b/src/commands/music/mod.rs index 4a053fd..6cba376 100644 --- a/src/commands/music/mod.rs +++ b/src/commands/music/mod.rs @@ -229,6 +229,7 @@ async fn leave(ctx: &Context, msg: &Message) -> CommandResult { #[command] #[description("Play a music (require an url)")] +#[aliases("p")] async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let guild_id = match ctx.cache.guild_channel(msg.channel_id).await { Some(channel) => channel.guild_id, @@ -283,6 +284,17 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { Ok(()) => { let source = if url.starts_with("http") { if url.contains("youtube.com") && url.contains("list=") { + msg.channel_id + .send_message(&ctx.http, |m| { + embed_response( + m, + "Error", + "This is disabled for the moment", + Some(&member), + ) + }) + .await?; + return Ok(()); msg.channel_id .send_message(&ctx.http, |m| { embed_response( diff --git a/src/commands/music/utils.rs b/src/commands/music/utils.rs index 7eb9346..11db9fc 100644 --- a/src/commands/music/utils.rs +++ b/src/commands/music/utils.rs @@ -40,7 +40,7 @@ pub(crate) fn embed_song<'a, 'b>( let hours = seconds / (60 * 60); let min = (seconds - (hours * 60 * 60)) / 60; - let seconds = seconds - (min * 60); + let seconds = seconds - (hours * 3600) - (min * 60); e.field( "Duration", diff --git a/src/data/mod.rs b/src/data/mod.rs index 94f83f6..32ab9eb 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -18,3 +18,9 @@ pub(crate) struct BulletsContainer; impl TypeMapKey for BulletsContainer { type Value = HashMap; } + + +pub(crate) struct Uptime; +impl TypeMapKey for Uptime { + type Value = std::time::Instant; +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d0f7ef6..6c7e1d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use crate::{ admin::ADMIN_GROUP, general::GENERAL_GROUP, owner::OWNER_GROUP, roulette::ROULETTE_GROUP, settings::SETTINGS_GROUP, }, - data::{BulletsContainer, GuildOptions, GuildOptionsKey, ShardManagerContainer}, + data::{BulletsContainer, GuildOptions, GuildOptionsKey, ShardManagerContainer, Uptime}, }; use async_trait::async_trait; use commands::interaction; @@ -27,6 +27,7 @@ use std::{ path::Path, sync::Arc, time::Duration, + time::Instant }; use tokio::{fs::File, io::AsyncWriteExt}; @@ -52,6 +53,8 @@ pub(crate) static mut INVITE_URL: Option = None; // TODO CLAP FOR CLI #[tokio::main] async fn main() -> IoResult<()> { + let now = Instant::now(); + log4rs::init_file("log4rs.yaml", Default::default()).unwrap(); let conf: config::Conf = toml::from_str(&fs::read_to_string("Conf.toml")?)?; debug!("conf : {:?}", conf); @@ -154,6 +157,7 @@ async fn main() -> IoResult<()> { { data.insert::(std::sync::Arc::clone(&client.voice_manager.unwrap())); }*/ + data.insert::(now); data.insert::({ let options = GuildOptions::load_from_dir("./data/guilds_options").unwrap_or_default();