feat(commands/utils): adding the anyhow result return
This commit is contained in:
parent
e0711a2a13
commit
37eac33485
1 changed files with 7 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::HashMap, sync::atomic::AtomicU64, time::Duration};
|
use std::{collections::HashMap, time::Duration};
|
||||||
use serenity::{
|
use serenity::{
|
||||||
all::{
|
all::{
|
||||||
ButtonStyle, Command, CommandInteraction, ComponentInteractionCollector, Context, CreateActionRow, CreateButton, CreateCommand, CreateEmbed, CreateEmbedFooter, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse, GuildId, InteractionContext, Message, MessageId, ReactionType, UserId
|
ButtonStyle, Command, CommandInteraction, ComponentInteractionCollector, Context, CreateActionRow, CreateButton, CreateCommand, CreateEmbed, CreateEmbedFooter, CreateInteractionResponse, CreateInteractionResponseMessage, EditInteractionResponse, GuildId, InteractionContext, Message, MessageId, ReactionType, UserId
|
||||||
|
|
@ -6,7 +6,8 @@ use serenity::{
|
||||||
futures::StreamExt,
|
futures::StreamExt,
|
||||||
};
|
};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use tracing::info;
|
use tracing::{debug, info};
|
||||||
|
use anyhow::Result;
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::{
|
commands::{
|
||||||
CommandCategory,
|
CommandCategory,
|
||||||
|
|
@ -18,17 +19,7 @@ use crate::{
|
||||||
models::DbGuild,
|
models::DbGuild,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Help {
|
pub struct Help;
|
||||||
pub command_id: AtomicU64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Help {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
command_id: AtomicU64::new(0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_category_buttons(categories: &HashMap<CommandCategory, Vec<String>>, disabled: bool) -> Vec<CreateActionRow> {
|
fn create_category_buttons(categories: &HashMap<CommandCategory, Vec<String>>, disabled: bool) -> Vec<CreateActionRow> {
|
||||||
let buttons: Vec<CreateButton> = categories
|
let buttons: Vec<CreateButton> = categories
|
||||||
|
|
@ -87,10 +78,6 @@ impl SlashCommand for Help {
|
||||||
&CommandCategory::Utils
|
&CommandCategory::Utils
|
||||||
}
|
}
|
||||||
|
|
||||||
fn command_id_ref(&self) -> &AtomicU64 {
|
|
||||||
&self.command_id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register(&self) -> CreateCommand {
|
fn register(&self) -> CreateCommand {
|
||||||
info!("\t✅ | {}", self.name());
|
info!("\t✅ | {}", self.name());
|
||||||
CreateCommand::new(self.name())
|
CreateCommand::new(self.name())
|
||||||
|
|
@ -106,7 +93,8 @@ impl SlashCommand for Help {
|
||||||
command: &CommandInteraction,
|
command: &CommandInteraction,
|
||||||
_database: &PgPool,
|
_database: &PgPool,
|
||||||
_emoji: &EmojiConfig,
|
_emoji: &EmojiConfig,
|
||||||
) -> Result<(), serenity::Error> {
|
) -> Result<()> {
|
||||||
|
debug!("Help command called");
|
||||||
let guild: GuildId = command.guild_id.ok_or(serenity::Error::Other("Commande non disponible en DM"))?;
|
let guild: GuildId = command.guild_id.ok_or(serenity::Error::Other("Commande non disponible en DM"))?;
|
||||||
let guild_id: String = guild.to_string();
|
let guild_id: String = guild.to_string();
|
||||||
let guild_db: Option<DbGuild> = guild::get(_database, &guild_id).await.map_err(|_e| serenity::Error::Other("Database error guild on help command"))?;
|
let guild_db: Option<DbGuild> = guild::get(_database, &guild_id).await.map_err(|_e| serenity::Error::Other("Database error guild on help command"))?;
|
||||||
|
|
@ -198,5 +186,5 @@ impl SlashCommand for Help {
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory::submit! {
|
inventory::submit! {
|
||||||
CommandEntry { create: || Box::new(Help::new()) }
|
CommandEntry { create: || Box::new(Help) }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue