begin implementing request listing
This commit is contained in:
parent
66cdc74a4b
commit
8e36fa1e08
3 changed files with 38 additions and 6 deletions
|
|
@ -8,5 +8,6 @@ request_text_is_too_short: "Fuck off unless you write meaningful request message
|
|||
request_text_is_too_long: "I ain't reading allat"
|
||||
already_can_download: "You already have permission to download, no need to request it then"
|
||||
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"
|
||||
admin_notify_request: "User %{user} awaits request approval"
|
||||
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"
|
||||
|
|
@ -18,7 +18,7 @@ use crate::db::DbPool;
|
|||
use super::dl::cmd_download;
|
||||
use super::op::cmd_op;
|
||||
use super::start::{cmd_start, handle_my_chat_member};
|
||||
use super::request::cmd_request;
|
||||
use super::request::{cmd_request, cmd_listrequests};
|
||||
|
||||
fn parse_env<T>(name: &str) -> T
|
||||
where
|
||||
|
|
@ -64,7 +64,8 @@ fn schema() -> UpdateHandler<HandlerErr> {
|
|||
.branch(case![Command::Start].endpoint(cmd_start))
|
||||
.branch(case![Command::Download(url)].endpoint(cmd_download))
|
||||
.branch(case![Command::OP].endpoint(cmd_op))
|
||||
.branch(case![Command::Request(text)].endpoint(cmd_request));
|
||||
.branch(case![Command::Request(text)].endpoint(cmd_request))
|
||||
.branch(case![Command::ListRequests].endpoint(cmd_listrequests));
|
||||
|
||||
let message_handler = Update::filter_message().branch(command_handler);
|
||||
let raw_message_handler = Update::filter_message().branch(dptree::endpoint(handle_message));
|
||||
|
|
@ -119,7 +120,10 @@ enum Command {
|
|||
OP,
|
||||
|
||||
#[command(alias = "request")]
|
||||
Request(String)
|
||||
Request(String),
|
||||
|
||||
#[command(alias = "listrequests")]
|
||||
ListRequests
|
||||
}
|
||||
|
||||
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use super::notify::notify_admins;
|
|||
use super::types::HandlerResult;
|
||||
use crate::db::chat::find_or_create_chat;
|
||||
use crate::db::user::find_or_create_user;
|
||||
use crate::db::DbPool;
|
||||
use crate::db::{DbPool, User};
|
||||
use crate::reply_i18n_and_return;
|
||||
|
||||
pub async fn cmd_request(bot: Bot, msg: Message, text: String, db: DbPool) -> HandlerResult {
|
||||
|
|
@ -54,3 +54,30 @@ pub async fn cmd_request(bot: Bot, msg: Message, text: String, db: DbPool) -> Ha
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow, Debug)]
|
||||
struct RequestWithUser {
|
||||
pub request_id: i64,
|
||||
pub message: String,
|
||||
#[sqlx(flatten)]
|
||||
pub user: User
|
||||
}
|
||||
|
||||
pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
|
||||
if let Some(user) = msg.from() {
|
||||
let user = find_or_create_user(&db, user).await?;
|
||||
if user.is_admin != 1 {
|
||||
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
|
||||
INNER JOIN user ON request.requested_by = user.id
|
||||
WHERE request.is_approved = 0;")
|
||||
.fetch_all(&db).await?;
|
||||
dbg!(requests);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue