implement listrequests command
This commit is contained in:
parent
8e36fa1e08
commit
a320919596
4 changed files with 27 additions and 13 deletions
|
|
@ -11,3 +11,4 @@ already_has_requested: "Stop spamming requests. That ain't gonna grant ya the do
|
||||||
request_added: "Your requested has been added. Admins have been notifed. You should DM bot with /start to enable personal notifications"
|
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"
|
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::dl::cmd_download;
|
||||||
use super::op::cmd_op;
|
use super::op::cmd_op;
|
||||||
|
use super::request::{cmd_listrequests, cmd_request};
|
||||||
use super::start::{cmd_start, handle_my_chat_member};
|
use super::start::{cmd_start, handle_my_chat_member};
|
||||||
use super::request::{cmd_request, cmd_listrequests};
|
|
||||||
|
|
||||||
fn parse_env<T>(name: &str) -> T
|
fn parse_env<T>(name: &str) -> T
|
||||||
where
|
where
|
||||||
|
|
@ -123,7 +123,7 @@ enum Command {
|
||||||
Request(String),
|
Request(String),
|
||||||
|
|
||||||
#[command(alias = "listrequests")]
|
#[command(alias = "listrequests")]
|
||||||
ListRequests
|
ListRequests,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
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?;
|
let user = find_or_create_user(&db, tg_user).await?;
|
||||||
sqlx::query("UPDATE user SET can_download = 1, is_admin = 1 WHERE id = $1;")
|
sqlx::query("UPDATE user SET can_download = 1, is_admin = 1 WHERE id = $1;")
|
||||||
.bind(user.id)
|
.bind(user.id)
|
||||||
.execute(&db).await?;
|
.execute(&db)
|
||||||
|
.await?;
|
||||||
|
|
||||||
event!(
|
event!(
|
||||||
Level::INFO,
|
Level::INFO,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use rust_i18n::t;
|
use rust_i18n::t;
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
use teloxide::prelude::*;
|
use teloxide::{prelude::*, requests};
|
||||||
use tracing::{event, Level};
|
use tracing::{event, Level};
|
||||||
|
|
||||||
use super::notify::notify_admins;
|
use super::notify::notify_admins;
|
||||||
|
|
@ -60,7 +60,7 @@ struct RequestWithUser {
|
||||||
pub request_id: i64,
|
pub request_id: i64,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
#[sqlx(flatten)]
|
#[sqlx(flatten)]
|
||||||
pub user: User
|
pub user: User,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
|
pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
|
||||||
|
|
@ -70,13 +70,25 @@ pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResu
|
||||||
reply_i18n_and_return!(bot, msg.chat.id, "not_an_admin");
|
reply_i18n_and_return!(bot, msg.chat.id, "not_an_admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut list = String::new();
|
|
||||||
let requests: Vec<RequestWithUser> = sqlx::query_as(
|
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
|
INNER JOIN user ON request.requested_by = user.id
|
||||||
WHERE request.is_approved = 0;")
|
WHERE request.is_approved = 0;",
|
||||||
.fetch_all(&db).await?;
|
)
|
||||||
dbg!(requests);
|
.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(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue