Rustendo/src/commands/stop.rs

64 lines
2.5 KiB
Rust

use chrono::Local;
use serenity::all::{CommandInteraction, Context};
use serenity::builder::{CreateCommand, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter};
use crate::util::user_util;
pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
let username = command.user.name.as_str();
let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S");
let guild_id = match &command.guild_id {
Some(guild_id) => guild_id,
None => {
return CreateEmbed::new()
.author(CreateEmbedAuthor::new("Rustendo"))
.title("GuildId not found")
.description("Could not find guild id.")
.footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username)));
}
};
if !user_util::is_self_connected_to_vc(&ctx, guild_id) {
// Bot is not connectd to vc; no need to dc
return CreateEmbed::new()
.author(CreateEmbedAuthor::new("Rustendo"))
.title("Bot is not connected")
.description("And therefore I cannot stop playing.")
.footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username)));
}
let manager = songbird::get(&ctx)
.await
.expect("Cannot get Songbird")
.clone();
let has_handler = manager.get(guild_id.clone()).is_some();
if has_handler {
if let Err(e) = manager.remove(guild_id.clone()).await {
return CreateEmbed::new()
.author(CreateEmbedAuthor::new("Rustendo"))
.title("There was an error")
.description(format!("Failed: {:?}", e))
.footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username)));
}
return CreateEmbed::new()
.author(CreateEmbedAuthor::new("Rustendo"))
.title("I stopped and left\nJust like your girlfriend.")
.footer(CreateEmbedFooter::new(format!(">{} | {}", current_time, username)))
}
CreateEmbed::new()
.author(CreateEmbedAuthor::new("Rustendo"))
.title("Bot is not connected")
.description("And therefore I cannot stop playing.\nSomething happend, which shouldn't have.")
.footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username)))
}
pub fn register() -> CreateCommand {
CreateCommand::new("stop").description("Stop playing and start leavin'")
}
// >18/02/2024 @ 19:01:59 - bartlo
// >2024-02-19 17:58:39 | moonleay