0.5.0 embed, help, refractor

This commit is contained in:
2024-02-13 18:44:01 +01:00
parent d75c5bc9a2
commit 8fa86b0182
24 changed files with 341 additions and 94 deletions

View File

@@ -1,7 +1,17 @@
use crate::{Context, Error};
use crate::{commands::embeds::{error_embed, embed, fail}, Context, Error};
use poise::CreateReply;
#[poise::command(prefix_command, slash_command)]
pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
/// Mutes itself while in a voice channel; \
/// aliases: mute, unmute, shhh
#[poise::command(
prefix_command,
slash_command,
aliases("shhh", "unmute"),
category = "Music"
)]
pub async fn mute(
ctx: Context<'_>
) -> Result<(), Error> {
let guild_id = ctx.guild_id().unwrap();
let manager = songbird::get(&ctx.serenity_context())
@@ -11,9 +21,11 @@ pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
let handler_lock = match manager.get(guild_id) {
Some(handler) => handler,
None => {
ctx.say("Not in a voice channel").await?;
None => {
let msg = "I am not in a voice channel!";
ctx.send(
CreateReply::default().embed(error_embed(ctx, msg).await.unwrap())
).await?;
return Ok(());
}
};
@@ -21,17 +33,21 @@ pub async fn mute(ctx: Context<'_>) -> Result<(), Error> {
let mut handler = handler_lock.lock().await;
if handler.is_mute() {
if let Err(e) = handler.mute(false).await {
ctx.say(format!("failed: {:?}", e)).await?;
if let Err(err) = handler.mute(false).await {
fail(ctx, err.to_string()).await.unwrap();
}
ctx.say("Unmuted").await?;
ctx.send(
CreateReply::default().embed(embed(ctx, "Unmuted!", "", "").await.unwrap())
).await?;
} else {
if let Err(err) = handler.mute(true).await {
ctx.say(format!("Failed: {:?}", err)).await?;
fail(ctx, err.to_string()).await.unwrap();
}
ctx.say("Muted").await?;
ctx.send(
CreateReply::default().embed(embed(ctx, "Muted!", "", "").await.unwrap())
).await?;
}
Ok(())