Add command to manage playlists
Signed-off-by: trivernis <trivernis@protonmail.com>pull/2/head
parent
6d75b840b4
commit
0cb0a4c47b
@ -0,0 +1,2 @@
|
|||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
DROP TABLE guild_playlists;
|
@ -0,0 +1,7 @@
|
|||||||
|
-- Your SQL goes here
|
||||||
|
CREATE TABLE guild_playlists (
|
||||||
|
guild_id BIGINT NOT NULL,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
url VARCHAR(1024) NOT NULL,
|
||||||
|
PRIMARY KEY (guild_id, name)
|
||||||
|
)
|
@ -0,0 +1,27 @@
|
|||||||
|
use crate::utils::context_data::get_database_from_context;
|
||||||
|
use serenity::client::Context;
|
||||||
|
use serenity::framework::standard::macros::command;
|
||||||
|
use serenity::framework::standard::CommandResult;
|
||||||
|
use serenity::model::channel::Message;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[only_in(guilds)]
|
||||||
|
#[description("Displays a list of all saved playlists")]
|
||||||
|
#[usage("")]
|
||||||
|
async fn playlists(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
let guild = msg.guild(&ctx.cache).await.unwrap();
|
||||||
|
log::debug!("Displaying playlists for guild {}", guild.id);
|
||||||
|
let database = get_database_from_context(ctx).await;
|
||||||
|
|
||||||
|
let playlists = database.get_guild_playlists(guild.id.0)?;
|
||||||
|
msg.channel_id
|
||||||
|
.send_message(ctx, |m| {
|
||||||
|
m.embed(|e| {
|
||||||
|
e.title("Saved Playlists")
|
||||||
|
.fields(playlists.into_iter().map(|p| (p.name, p.url, true)))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
use crate::utils::context_data::get_database_from_context;
|
||||||
|
use serenity::client::Context;
|
||||||
|
use serenity::framework::standard::macros::command;
|
||||||
|
use serenity::framework::standard::{Args, CommandResult};
|
||||||
|
use serenity::model::channel::Message;
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
#[only_in(guilds)]
|
||||||
|
#[description("Adds a playlist to the guilds saved playlists")]
|
||||||
|
#[usage("<name> <url/query>")]
|
||||||
|
#[example("anime https://www.youtube.com/playlist?list=PLqaM77H_o5hykROCe3uluvZEaPo6bZj-C")]
|
||||||
|
#[min_args(2)]
|
||||||
|
#[aliases("add-playlist", "save-playlist")]
|
||||||
|
#[allowed_roles("DJ")]
|
||||||
|
async fn save_playlist(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
|
let guild = msg.guild(&ctx.cache).await.unwrap();
|
||||||
|
let name: String = args.single().unwrap();
|
||||||
|
let url: &str = args.remains().unwrap();
|
||||||
|
log::debug!(
|
||||||
|
"Adding playlist '{}' with url '{}' to guild {}",
|
||||||
|
name,
|
||||||
|
url,
|
||||||
|
guild.id
|
||||||
|
);
|
||||||
|
let database = get_database_from_context(ctx).await;
|
||||||
|
|
||||||
|
database.add_guild_playlist(guild.id.0, &*name, url)?;
|
||||||
|
|
||||||
|
msg.channel_id
|
||||||
|
.say(ctx, format!("Playlist **{}** saved", name))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue