1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::checks::ENABLED_CHECK;
use anyhow::Context as _;
use serenity::{
    client::Context,
    framework::standard::{
        macros::command,
        CommandResult,
    },
    model::prelude::*,
};

#[command]
#[only_in(guilds)]
#[bucket("default")]
#[checks(Enabled)]
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
    let guild_id: GuildId = msg.guild(&ctx.cache).context("missing server data")?.id;

    let manager = songbird::get(ctx)
        .await
        .expect("missing songbird data")
        .clone();
    let has_handler = manager.get(guild_id).is_some();

    if has_handler {
        if let Err(e) = manager.remove(guild_id).await {
            msg.channel_id.say(&ctx.http, format!("{:?}", e)).await?;
        }

        msg.channel_id.say(&ctx.http, "Left voice channel").await?;
    } else {
        msg.reply(ctx, "Not in a voice channel").await?;
    }

    Ok(())
}