diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 6b37cb7..91cb0be 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,4 +1,5 @@
-use anyhow::Result;
+use std::sync::atomic::{AtomicU64, Ordering};
+
use serenity::all::{CommandInteraction, Context, CreateCommand};
use sqlx::PgPool;
@@ -10,7 +11,6 @@ include!("./mod_gen.rs");
pub enum CommandCategory {
Moderation,
Utils,
- Gestion,
}
impl CommandCategory {
@@ -18,7 +18,6 @@ impl CommandCategory {
match self {
Self::Utils => "🌐",
Self::Moderation => "🛡️",
- Self::Gestion => "👑",
}
}
@@ -26,7 +25,6 @@ impl CommandCategory {
match self {
Self::Utils => "Utils",
Self::Moderation => "Moderation",
- Self::Gestion => "Gestion",
}
}
}
@@ -36,6 +34,15 @@ pub trait SlashCommand: Send + Sync {
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn category(&self) -> &'static CommandCategory;
+ fn command_id_ref(&self) -> &AtomicU64;
+
+ fn get_id(&self) -> u64 {
+ self.command_id_ref().load(Ordering::Relaxed)
+ }
+
+ fn set_id(&self, id: u64) {
+ self.command_id_ref().store(id, Ordering::Relaxed);
+ }
fn register(&self) -> CreateCommand;
@@ -45,7 +52,7 @@ pub trait SlashCommand: Send + Sync {
command: &CommandInteraction,
database: &PgPool,
_emoji: &EmojiConfig,
- ) -> Result<()>;
+ ) -> Result<(), serenity::Error>;
}
pub struct CommandEntry {
diff --git a/src/commands/utils/ping.rs b/src/commands/utils/ping.rs
index 1c3cc86..1a5919e 100644
--- a/src/commands/utils/ping.rs
+++ b/src/commands/utils/ping.rs
@@ -1,4 +1,7 @@
use std::{
+ sync::atomic::{
+ AtomicU64,
+ },
time::Instant,
};
@@ -14,10 +17,19 @@ use serenity::all::{
CreateInteractionResponseMessage, EditInteractionResponse,
};
use sqlx::PgPool;
-use tracing::{debug, info};
-use anyhow::Result;
+use tracing::info;
-pub struct Ping;
+pub struct Ping {
+ pub command_id: AtomicU64,
+}
+
+impl Ping {
+ pub fn new() -> Self {
+ Self {
+ command_id: AtomicU64::new(0),
+ }
+ }
+}
#[serenity::async_trait]
impl SlashCommand for Ping {
@@ -33,6 +45,10 @@ impl SlashCommand for Ping {
&CommandCategory::Utils
}
+ fn command_id_ref(&self) -> &AtomicU64 {
+ &self.command_id
+ }
+
fn register(&self) -> CreateCommand {
info!("\t✅ | {}", self.name());
CreateCommand::new(self.name()).description(self.description())
@@ -44,8 +60,7 @@ impl SlashCommand for Ping {
command: &CommandInteraction,
_database: &PgPool,
_emoji: &EmojiConfig,
- ) -> Result<()> {
- debug!("Ping command called");
+ ) -> Result<(), serenity::Error> {
let message: CreateInteractionResponseMessage = CreateInteractionResponseMessage::new()
.content("🏓 | Pong!")
.ephemeral(true);
@@ -66,5 +81,5 @@ impl SlashCommand for Ping {
}
inventory::submit! {
- CommandEntry { create: || Box::new(Ping) }
+ CommandEntry { create: || Box::new(Ping::new()) }
}
diff --git a/src/database/bot.rs b/src/database/bot.rs
index c895ec3..5819933 100644
--- a/src/database/bot.rs
+++ b/src/database/bot.rs
@@ -1,17 +1,16 @@
use sqlx::{PgPool, query, query_as};
use crate::models::bot::{DbBot, BotPresence, BotActivity};
-use anyhow::Result;
const BOT_ID: i32 = 1;
-pub async fn init(db: &PgPool) -> Result<()> {
+pub async fn init(db: &PgPool) -> Result<(), sqlx::Error> {
query!("INSERT INTO bots (id) VALUES ($1) ON CONFLICT DO NOTHING", BOT_ID)
.execute(db)
.await?;
Ok(())
}
-pub async fn get(db: &PgPool) -> Result