cargo fmt

This commit is contained in:
mykola2312 2024-03-16 03:03:45 +02:00
parent 2910036a4c
commit 240b05c03c
5 changed files with 29 additions and 23 deletions

View file

@ -8,8 +8,8 @@ use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommand
use tracing::{event, Level}; use tracing::{event, Level};
use super::start::handle_new_chat_member; use super::start::handle_new_chat_member;
use super::version::cmd_version;
use super::types::*; use super::types::*;
use super::version::cmd_version;
use crate::db::DbPool; use crate::db::DbPool;
use crate::util::{parse_env, unwrap_env}; use crate::util::{parse_env, unwrap_env};
@ -109,7 +109,7 @@ enum Command {
#[command(alias = "dl")] #[command(alias = "dl")]
Download(String), Download(String),
#[command(alias = "op")] #[command(alias = "op")]
OP, OP,

View file

@ -6,10 +6,11 @@ use crate::db::{DbPool, User};
use super::types::HandlerResult; use super::types::HandlerResult;
pub async fn notify_admins(bot: &Bot, db: &DbPool, message: String) -> HandlerResult { pub async fn notify_admins(bot: &Bot, db: &DbPool, message: String) -> HandlerResult {
let admins: Vec<User> = let admins: Vec<User> = sqlx::query_as(
sqlx::query_as(r#"SELECT * FROM "user" WHERE is_admin = true AND has_private_chat = true;"#) r#"SELECT * FROM "user" WHERE is_admin = true AND has_private_chat = true;"#,
.fetch_all(db) )
.await?; .fetch_all(db)
.await?;
for admin in admins { for admin in admins {
let res = bot let res = bot

View file

@ -23,22 +23,25 @@ pub async fn cmd_request(bot: Bot, msg: Message, text: String, db: DbPool) -> Ha
reply_i18n_and_return!(bot, msg.chat.id, "already_can_download"); reply_i18n_and_return!(bot, msg.chat.id, "already_can_download");
} }
let requests: i64 = sqlx::query(r#"SELECT COUNT(1) FROM "request" WHERE requested_by = $1;"#) let requests: i64 =
.bind(user.id) sqlx::query(r#"SELECT COUNT(1) FROM "request" WHERE requested_by = $1;"#)
.fetch_one(&db) .bind(user.id)
.await? .fetch_one(&db)
.get(0); .await?
.get(0);
if requests > 0 { if requests > 0 {
reply_i18n_and_return!(bot, msg.chat.id, "already_has_requested"); reply_i18n_and_return!(bot, msg.chat.id, "already_has_requested");
} }
// put the request // put the request
sqlx::query(r#"INSERT INTO "request" (requested_by,message,is_approved) VALUES ($1,$2,$3);"#) sqlx::query(
.bind(user.id) r#"INSERT INTO "request" (requested_by,message,is_approved) VALUES ($1,$2,$3);"#,
.bind(text) )
.bind(false) .bind(user.id)
.execute(&db) .bind(text)
.await?; .bind(false)
.execute(&db)
.await?;
event!(Level::INFO, "added request for {}", user); event!(Level::INFO, "added request for {}", user);
// notify admins // notify admins

View file

@ -133,11 +133,13 @@ pub async fn cmd_approve_chat(bot: Bot, msg: Message, id: String, db: DbPool) ->
}; };
// approve request // approve request
sqlx::query(r#"UPDATE "request_chat" SET approved_by = $1, is_approved = true WHERE id = $2;"#) sqlx::query(
.bind(user.id) r#"UPDATE "request_chat" SET approved_by = $1, is_approved = true WHERE id = $2;"#,
.bind(request.request_id) )
.execute(&db) .bind(user.id)
.await?; .bind(request.request_id)
.execute(&db)
.await?;
event!( event!(
Level::INFO, Level::INFO,
"approved chat request {} by {} for {}", "approved chat request {} by {} for {}",

View file

@ -8,4 +8,4 @@ pub async fn cmd_version(bot: Bot, msg: Message) -> HandlerResult {
bot.send_message(msg.chat.id, VERSION).await?; bot.send_message(msg.chat.id, VERSION).await?;
Ok(()) Ok(())
} }