Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ytb join

Join and monitor a livestream chat (check YouTube for available commands)

Warning

This is actively work in progress

Usage

/ytb join id=...
/ytb leave (the opposite)


ArgumentDescriptionExemple
idID of currently active livestreamC4qJeIjNd2U

Source code

#[poise::command(
    slash_command,
    rename = "ytb",
    subcommands("post", "join", "leave"),
    subcommand_required
)]
pub async fn cmd(_: Context<'_>) -> Result<(), Error> {
    Ok(())
}

#[derive(poise::ChoiceParameter)]
pub enum Kind {
    Video,
    Stream,
}
#[poise::command(slash_command)]
pub async fn join(
    ctx: Context<'_>,
    #[description = "Youtube livestream URL"] livestream_id: String,
) -> Result<(), Error> {
    {
        let mut joined_livechat = ctx.data().joined_livechat.lock().unwrap();
        let task_tx = ctx.data().task_tx.lock().unwrap();

        let hndl = task::spawn(chat_monitor(livestream_id.clone(), task_tx.clone()));

        if joined_livechat.is_some() {
            joined_livechat.as_ref().unwrap().abort();
        }

        *joined_livechat = Some(hndl);
    }

    ctx.say(format!(
        "✔ Joined https://youtube.com/watch?v={} livestream",
        livestream_id.clone()
    ))
    .await?;

    Ok(())
}
#[poise::command(slash_command)]
pub async fn leave(ctx: Context<'_>) -> Result<(), Error> {
    {
        let mut joined_livechat = ctx.data().joined_livechat.lock().unwrap();

        if joined_livechat.is_some() {
            joined_livechat.as_ref().unwrap().abort();
            *joined_livechat = None;
        }
    }

    ctx.say("✔ Left current livestream").await?;

    Ok(())
}