fix bug when op wasn't setting admin access (when user was already created), add indecies on telegram ids in database

This commit is contained in:
mykola2312 2024-03-03 20:02:50 +02:00
parent d71462589f
commit 4d2b01f961
4 changed files with 13 additions and 3 deletions

View file

@ -10,6 +10,9 @@ CREATE TABLE "user"
has_private_chat INTEGER NOT NULL
);
CREATE INDEX idx_user_tg_id
ON "user"(tg_id);
CREATE TABLE "chat"
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -19,6 +22,9 @@ CREATE TABLE "chat"
can_download INTEGER NOT NULL
);
CREATE INDEX idx_chat_tg_id
ON "chat"(tg_id);
CREATE TABLE "link"
(
id INTEGER PRIMARY KEY AUTOINCREMENT,

View file

@ -12,6 +12,7 @@ use tracing::{event, Level};
use super::start::handle_new_chat_member;
use super::types::*;
use crate::bot::notify::notify_admins;
use crate::db::DbPool;
use super::dl::cmd_download;

View file

@ -4,7 +4,7 @@ use teloxide::prelude::*;
use tracing::{event, Level};
use super::types::HandlerResult;
use crate::db::user::{create_user, find_or_create_user};
use crate::db::user::find_or_create_user;
use crate::db::DbPool;
pub async fn cmd_op(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
@ -15,7 +15,10 @@ pub async fn cmd_op(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
if let Some(tg_user) = msg.from() {
if admins == 0 {
let user = create_user(&db, tg_user, true, true).await?;
let user = find_or_create_user(&db, tg_user).await?;
sqlx::query("UPDATE user SET can_download = 1 AND is_admin = 1 WHERE id = $1;")
.bind(user.id)
.execute(&db).await?;
event!(
Level::INFO,

View file

@ -52,5 +52,5 @@ pub async fn cmd_request(bot: Bot, msg: Message, text: String, db: DbPool) -> Ha
bot.send_message(msg.chat.id, t!("request_added")).await?;
}
todo!()
Ok(())
}