Compare commits
3 Commits
4277fc5523
...
c2aebcd509
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2aebcd509 | ||
|
|
f6adaea70c | ||
|
|
6088050d1a |
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -67,7 +67,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f50776554130342de4836ba542aa85a4ddb361690d7e8df13774d7284c3d5c2"
|
||||
dependencies = [
|
||||
"include_dir",
|
||||
"itertools",
|
||||
"itertools 0.10.5",
|
||||
"proc-macro-error2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -852,6 +852,7 @@ dependencies = [
|
||||
"enum_stringify",
|
||||
"envconfig",
|
||||
"futures",
|
||||
"itertools 0.14.0",
|
||||
"log",
|
||||
"mongodb",
|
||||
"pretty_env_logger",
|
||||
@ -1336,6 +1337,15 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
|
||||
@ -14,6 +14,7 @@ dotenvy = "0.15.7"
|
||||
enum_stringify = "0.6.3"
|
||||
envconfig = "0.11.0"
|
||||
futures = "0.3.31"
|
||||
itertools = "0.14.0"
|
||||
log = "0.4.27"
|
||||
mongodb = "3.2.3"
|
||||
pretty_env_logger = "0.5.0"
|
||||
|
||||
36
src/admin.rs
36
src/admin.rs
@ -1,3 +1,4 @@
|
||||
use itertools::Itertools;
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
utils::{command::BotCommands, render::RenderMessageTextHelper},
|
||||
@ -36,6 +37,10 @@ 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,
|
||||
/// Cancel current action and sets user state to default
|
||||
Cancel,
|
||||
}
|
||||
|
||||
pub async fn admin_command_handler(
|
||||
@ -120,6 +125,37 @@ 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(())
|
||||
}
|
||||
AdminCommands::Cancel => {
|
||||
dialogue.exit().await?;
|
||||
bot.send_message(msg.chat.id, "canceled current action")
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user