create /users admin command
This commit is contained in:
parent
6088050d1a
commit
f6adaea70c
28
src/admin.rs
28
src/admin.rs
@ -1,3 +1,4 @@
|
||||
use itertools::Itertools;
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
utils::{command::BotCommands, render::RenderMessageTextHelper},
|
||||
@ -36,6 +37,8 @@ pub enum AdminCommands {
|
||||
SetAlternative { literal: String, variant: String },
|
||||
/// Sets chat where this message entered as support's chats
|
||||
SetChat,
|
||||
/// Shows user count and lists some of them
|
||||
Users,
|
||||
}
|
||||
|
||||
pub async fn admin_command_handler(
|
||||
@ -120,6 +123,31 @@ pub async fn admin_command_handler(
|
||||
bot.send_message(msg.chat.id, "ChatId is set!").await?;
|
||||
Ok(())
|
||||
}
|
||||
AdminCommands::Users => {
|
||||
let users = db.get_users().await?;
|
||||
let count = users.len();
|
||||
let user_list = users
|
||||
.into_iter()
|
||||
.take(5)
|
||||
.map(|u| {
|
||||
format!(
|
||||
" {}{}{}",
|
||||
u.first_name,
|
||||
u.last_name.map_or("".into(), |l| format!(" {l}")),
|
||||
u.username
|
||||
.map_or("".into(), |username| format!(" ({username})")),
|
||||
)
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
bot.send_message(
|
||||
msg.chat.id,
|
||||
format!("Users count: {count}\nList:\n{user_list}"),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user