implement listrequests command
This commit is contained in:
parent
8e36fa1e08
commit
a320919596
4 changed files with 27 additions and 13 deletions
|
|
@ -10,4 +10,5 @@ already_can_download: "You already have permission to download, no need to reque
|
|||
already_has_requested: "Stop spamming requests. That ain't gonna grant ya the download perm"
|
||||
request_added: "Your requested has been added. Admins have been notifed. You should DM bot with /start to enable personal notifications"
|
||||
admin_notify_request: "User %{user} awaits request approval"
|
||||
not_an_admin: "You are not an admin. Back off"
|
||||
not_an_admin: "You are not an admin. Back off"
|
||||
request_list_header: "Current user requests for downloading:\n"
|
||||
|
|
@ -17,8 +17,8 @@ use crate::db::DbPool;
|
|||
|
||||
use super::dl::cmd_download;
|
||||
use super::op::cmd_op;
|
||||
use super::request::{cmd_listrequests, cmd_request};
|
||||
use super::start::{cmd_start, handle_my_chat_member};
|
||||
use super::request::{cmd_request, cmd_listrequests};
|
||||
|
||||
fn parse_env<T>(name: &str) -> T
|
||||
where
|
||||
|
|
@ -123,7 +123,7 @@ enum Command {
|
|||
Request(String),
|
||||
|
||||
#[command(alias = "listrequests")]
|
||||
ListRequests
|
||||
ListRequests,
|
||||
}
|
||||
|
||||
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ pub async fn cmd_op(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
|
|||
let user = find_or_create_user(&db, tg_user).await?;
|
||||
sqlx::query("UPDATE user SET can_download = 1, is_admin = 1 WHERE id = $1;")
|
||||
.bind(user.id)
|
||||
.execute(&db).await?;
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
event!(
|
||||
Level::INFO,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rust_i18n::t;
|
||||
use sqlx::Row;
|
||||
use teloxide::prelude::*;
|
||||
use teloxide::{prelude::*, requests};
|
||||
use tracing::{event, Level};
|
||||
|
||||
use super::notify::notify_admins;
|
||||
|
|
@ -48,7 +48,7 @@ pub async fn cmd_request(bot: Bot, msg: Message, text: String, db: DbPool) -> Ha
|
|||
t!("admin_notify_request", user = user.to_string()).to_string(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
bot.send_message(msg.chat.id, t!("request_added")).await?;
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ struct RequestWithUser {
|
|||
pub request_id: i64,
|
||||
pub message: String,
|
||||
#[sqlx(flatten)]
|
||||
pub user: User
|
||||
pub user: User,
|
||||
}
|
||||
|
||||
pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
|
||||
|
|
@ -70,14 +70,26 @@ pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResu
|
|||
reply_i18n_and_return!(bot, msg.chat.id, "not_an_admin");
|
||||
}
|
||||
|
||||
let mut list = String::new();
|
||||
let requests: Vec<RequestWithUser> = sqlx::query_as(
|
||||
"SELECT request.id AS request_id, request.message, user.*FROM request
|
||||
"SELECT request.id AS request_id, request.message, user.*
|
||||
FROM request
|
||||
INNER JOIN user ON request.requested_by = user.id
|
||||
WHERE request.is_approved = 0;")
|
||||
.fetch_all(&db).await?;
|
||||
dbg!(requests);
|
||||
WHERE request.is_approved = 0;",
|
||||
)
|
||||
.fetch_all(&db)
|
||||
.await?;
|
||||
|
||||
let mut list = String::new();
|
||||
list.push_str(t!("request_list_header").to_string().as_str());
|
||||
for request in requests {
|
||||
let fmt = format!(
|
||||
"{}: {}: {}\n",
|
||||
request.request_id, request.user, request.message
|
||||
);
|
||||
list.push_str(fmt.as_str());
|
||||
}
|
||||
bot.send_message(msg.chat.id, list).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue