Add statistics command
This commit is contained in:
Generated
+1
-1
@@ -1437,7 +1437,7 @@ checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "payphone"
|
||||
version = "4.2.17"
|
||||
version = "4.2.18"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "payphone"
|
||||
version = "4.2.17"
|
||||
version = "4.2.18"
|
||||
edition = "2024"
|
||||
default-run = "payphone"
|
||||
|
||||
|
||||
+36
-1
@@ -287,7 +287,7 @@ impl User {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn count(&self, session: &Session) -> Result<usize, DatabaseError> {
|
||||
pub async fn count(session: &Session) -> Result<usize, DatabaseError> {
|
||||
let result = session
|
||||
.query_unpaged(
|
||||
r#"
|
||||
@@ -1060,6 +1060,25 @@ impl Call {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn count(session: &Session) -> Result<usize, DatabaseError> {
|
||||
let result = session
|
||||
.query_unpaged(
|
||||
r#"
|
||||
SELECT
|
||||
call_id
|
||||
FROM
|
||||
payphone.calls;
|
||||
"#,
|
||||
(),
|
||||
)
|
||||
.await
|
||||
.map_err(DatabaseError::QueryError)?
|
||||
.into_rows_result()
|
||||
.map_err(|_| DatabaseError::ResultNotRows)?;
|
||||
|
||||
Ok(result.rows_num())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, SerializeValue, DeserializeValue)]
|
||||
@@ -1325,6 +1344,22 @@ impl Message {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn count(session: &Session) -> Result<usize, DatabaseError> {
|
||||
let result = session
|
||||
.query_unpaged(
|
||||
r#"
|
||||
SELECT message_id FROM payphone.messages;
|
||||
"#,
|
||||
(),
|
||||
)
|
||||
.await
|
||||
.map_err(DatabaseError::QueryError)?
|
||||
.into_rows_result()
|
||||
.map_err(|_| DatabaseError::ResultNotRows)?;
|
||||
|
||||
Ok(result.rows_num())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MessageByPropagationId {
|
||||
|
||||
@@ -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