feat: added skip command, reworked embed messages
fix: fixed issue with queue not working properly
This commit is contained in:
parent
1dcd0ab66b
commit
ba0f1fb959
10 changed files with 159 additions and 114 deletions
|
@ -6,9 +6,6 @@ use std::error::Error;
|
|||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
pub discord_token: String,
|
||||
pub lavalink_address: String,
|
||||
pub lavalink_password: String,
|
||||
pub user_id: u64,
|
||||
}
|
||||
|
||||
const CONFIG_FILE: &str = "./data/config.json";
|
||||
|
@ -26,9 +23,6 @@ pub fn load() -> Result<Config, Box<dyn Error>> {
|
|||
fn create_empty() -> fs::File {
|
||||
let example_config = Config {
|
||||
discord_token: "paste_your_token".to_string(),
|
||||
lavalink_address: "paste_your_lavalink_address".to_string(),
|
||||
lavalink_password: "paste_your_lavalink_password".to_string(),
|
||||
user_id: 1,
|
||||
};
|
||||
|
||||
let mut config_file = fs::File::create(CONFIG_FILE).unwrap();
|
||||
|
|
|
@ -1,29 +1,56 @@
|
|||
use std::fmt::Display;
|
||||
use std::time::Duration;
|
||||
|
||||
use chrono::Local;
|
||||
use serenity::all::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter};
|
||||
use serenity::all::{Color, CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter};
|
||||
use songbird::input::{Compose, YoutubeDl};
|
||||
|
||||
pub struct Embed;
|
||||
|
||||
impl Embed {
|
||||
pub fn create<
|
||||
S: Into<String> + Display,
|
||||
T: Into<String> + Display,
|
||||
U: Into<String> + Display,
|
||||
>(
|
||||
username: S,
|
||||
title: T,
|
||||
message: U,
|
||||
) -> CreateEmbed {
|
||||
pub fn create_success_response(username: &str, title: &str, desc: &str) -> CreateEmbed {
|
||||
let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S");
|
||||
|
||||
CreateEmbed::new()
|
||||
.author(CreateEmbedAuthor::new(username.to_string()))
|
||||
.title(title)
|
||||
.description(message)
|
||||
.footer(CreateEmbedFooter::new(format!(
|
||||
"> {} - {}",
|
||||
current_time, username
|
||||
)))
|
||||
.title(title)
|
||||
.description(desc)
|
||||
.color(Color::from_rgb(224, 49, 26))
|
||||
.footer(CreateEmbedFooter::new(format!("> {} - {}", current_time, username)))
|
||||
}
|
||||
|
||||
pub fn create_error_respose(username: &str, error_title: &str, error_desc: &str) -> CreateEmbed {
|
||||
let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S");
|
||||
|
||||
CreateEmbed::new()
|
||||
.author(CreateEmbedAuthor::new("Oops, something went wrong."))
|
||||
.title(error_title)
|
||||
.description(error_desc)
|
||||
.color(Color::from_rgb(224, 49, 26))
|
||||
.footer(CreateEmbedFooter::new(format!("> {} - {}", current_time, username)))
|
||||
}
|
||||
|
||||
pub async fn create_yt_playing(mut src: YoutubeDl, username: &str, show_as_author: &str) -> CreateEmbed {
|
||||
let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S");
|
||||
|
||||
// Get metadata
|
||||
let metadata = src.aux_metadata().await.expect("Cannot get metadata");
|
||||
let title = metadata.title.unwrap_or("Unknown title".to_string());
|
||||
let artist = metadata.artist.unwrap_or("Unknown artist".to_string());
|
||||
let duration = metadata.duration.unwrap_or(Duration::from_millis(0));
|
||||
let thumbnail = metadata
|
||||
.thumbnail
|
||||
.unwrap_or("https://http.cat/images/403.jpg".to_string());
|
||||
let link = metadata
|
||||
.source_url
|
||||
.unwrap_or("https://piped.moonleay.net/403".to_string());
|
||||
|
||||
CreateEmbed::new()
|
||||
.author(CreateEmbedAuthor::new(show_as_author))
|
||||
.title(title)
|
||||
.url(link)
|
||||
.thumbnail(thumbnail)
|
||||
.field("Artist", artist, true)
|
||||
.field("Duration", format!("{}min {}sec", duration.as_secs() / 58, duration.as_secs() % 59), true)
|
||||
.color(Color::from_rgb(81, 224, 26))
|
||||
.footer(CreateEmbedFooter::new(format!("> {} - {}",current_time, username)))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue