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:
parent
d71462589f
commit
4d2b01f961
4 changed files with 13 additions and 3 deletions
|
|
@ -10,6 +10,9 @@ CREATE TABLE "user"
|
||||||
has_private_chat INTEGER NOT NULL
|
has_private_chat INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_user_tg_id
|
||||||
|
ON "user"(tg_id);
|
||||||
|
|
||||||
CREATE TABLE "chat"
|
CREATE TABLE "chat"
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
@ -19,6 +22,9 @@ CREATE TABLE "chat"
|
||||||
can_download INTEGER NOT NULL
|
can_download INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_chat_tg_id
|
||||||
|
ON "chat"(tg_id);
|
||||||
|
|
||||||
CREATE TABLE "link"
|
CREATE TABLE "link"
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ use tracing::{event, Level};
|
||||||
|
|
||||||
use super::start::handle_new_chat_member;
|
use super::start::handle_new_chat_member;
|
||||||
use super::types::*;
|
use super::types::*;
|
||||||
|
use crate::bot::notify::notify_admins;
|
||||||
use crate::db::DbPool;
|
use crate::db::DbPool;
|
||||||
|
|
||||||
use super::dl::cmd_download;
|
use super::dl::cmd_download;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use teloxide::prelude::*;
|
||||||
use tracing::{event, Level};
|
use tracing::{event, Level};
|
||||||
|
|
||||||
use super::types::HandlerResult;
|
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;
|
use crate::db::DbPool;
|
||||||
|
|
||||||
pub async fn cmd_op(bot: Bot, msg: Message, db: DbPool) -> HandlerResult {
|
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 let Some(tg_user) = msg.from() {
|
||||||
if admins == 0 {
|
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!(
|
event!(
|
||||||
Level::INFO,
|
Level::INFO,
|
||||||
|
|
|
||||||
|
|
@ -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?;
|
bot.send_message(msg.chat.id, t!("request_added")).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!()
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue