Add statistics command

This commit is contained in:
2025-08-23 13:28:52 -03:00
parent 6c72c27911
commit 35f3504c00
4 changed files with 75 additions and 3 deletions
+37
View File
@@ -1,6 +1,7 @@
use async_trait::async_trait;
use crate::{
database::models::{Call, Message, User},
extras::Extras,
framework::{
commands::{
@@ -146,3 +147,39 @@ impl Command<State, Extras> for IncidentsCommand {
Ok(())
}
}
#[derive(Debug)]
pub struct StatsCommand;
#[async_trait]
impl Command<State, Extras> for StatsCommand {
fn name(&self) -> &'static str {
"stats"
}
fn permissions(&self) -> Vec<Box<dyn Permission<State, Extras> + Send + Sync + 'static>> {
vec![Box::new(BotOwnerPermission)]
}
fn show_in_help(&self, rt: &Runtime<State, Extras>, extras: &Extras) -> bool {
extras.user.id == rt.state.bot_owner_id
}
async fn execute(
&self,
ctx: CommandContext<'_, State, Extras>,
_args: &str,
) -> Result<(), CommandError> {
let users = User::count(&ctx.rt.state.db).await?;
let calls = Call::count(&ctx.rt.state.db).await?;
let messages = Message::count(&ctx.rt.state.db).await?;
ctx.send()
.content(format!(
"```\nUsers: {users}\nCalls: {calls}\nMessages: {messages}\n```"
))
.await?;
Ok(())
}
}