Compare commits

...

3 Commits

Author SHA1 Message Date
Akulij
c2aebcd509 create /cancel admin command
All checks were successful
Build && Deploy / cargo build (push) Successful in 1m4s
2025-05-05 18:46:05 +03:00
Akulij
f6adaea70c create /users admin command 2025-05-05 18:44:05 +03:00
Akulij
6088050d1a cargo add itertools 2025-05-05 18:43:50 +03:00
3 changed files with 48 additions and 1 deletions

12
Cargo.lock generated
View File

@ -67,7 +67,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f50776554130342de4836ba542aa85a4ddb361690d7e8df13774d7284c3d5c2" checksum = "0f50776554130342de4836ba542aa85a4ddb361690d7e8df13774d7284c3d5c2"
dependencies = [ dependencies = [
"include_dir", "include_dir",
"itertools", "itertools 0.10.5",
"proc-macro-error2", "proc-macro-error2",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -852,6 +852,7 @@ dependencies = [
"enum_stringify", "enum_stringify",
"envconfig", "envconfig",
"futures", "futures",
"itertools 0.14.0",
"log", "log",
"mongodb", "mongodb",
"pretty_env_logger", "pretty_env_logger",
@ -1336,6 +1337,15 @@ dependencies = [
"either", "either",
] ]
[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.15" version = "1.0.15"

View File

@ -14,6 +14,7 @@ dotenvy = "0.15.7"
enum_stringify = "0.6.3" enum_stringify = "0.6.3"
envconfig = "0.11.0" envconfig = "0.11.0"
futures = "0.3.31" futures = "0.3.31"
itertools = "0.14.0"
log = "0.4.27" log = "0.4.27"
mongodb = "3.2.3" mongodb = "3.2.3"
pretty_env_logger = "0.5.0" pretty_env_logger = "0.5.0"

View File

@ -1,3 +1,4 @@
use itertools::Itertools;
use teloxide::{ use teloxide::{
prelude::*, prelude::*,
utils::{command::BotCommands, render::RenderMessageTextHelper}, utils::{command::BotCommands, render::RenderMessageTextHelper},
@ -36,6 +37,10 @@ pub enum AdminCommands {
SetAlternative { literal: String, variant: String }, SetAlternative { literal: String, variant: String },
/// Sets chat where this message entered as support's chats /// Sets chat where this message entered as support's chats
SetChat, 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( 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?; bot.send_message(msg.chat.id, "ChatId is set!").await?;
Ok(()) 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(())
}
} }
} }