Add statistics command
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user