uptime and fix
This commit is contained in:
parent
e6f60efbe7
commit
362dfeeb9d
|
@ -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::<crate::data::Uptime>()
|
||||
.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(),
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -18,3 +18,9 @@ pub(crate) struct BulletsContainer;
|
|||
impl TypeMapKey for BulletsContainer {
|
||||
type Value = HashMap<u64, (u8, u8)>;
|
||||
}
|
||||
|
||||
|
||||
pub(crate) struct Uptime;
|
||||
impl TypeMapKey for Uptime {
|
||||
type Value = std::time::Instant;
|
||||
}
|
|
@ -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<String> = 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::<VoiceManager>(std::sync::Arc::clone(&client.voice_manager.unwrap()));
|
||||
}*/
|
||||
data.insert::<Uptime>(now);
|
||||
|
||||
data.insert::<GuildOptionsKey>({
|
||||
let options = GuildOptions::load_from_dir("./data/guilds_options").unwrap_or_default();
|
||||
|
|
Loading…
Reference in New Issue