move out secret command to admin file
This commit is contained in:
parent
9e95935ddc
commit
30117624c4
34
src/admin.rs
34
src/admin.rs
@ -3,6 +3,16 @@ use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, p
|
|||||||
use crate::db::DB;
|
use crate::db::DB;
|
||||||
use crate::LogMsg;
|
use crate::LogMsg;
|
||||||
|
|
||||||
|
// These are should not appear in /help
|
||||||
|
#[derive(BotCommands, Clone)]
|
||||||
|
#[command(rename_rule = "lowercase")]
|
||||||
|
pub enum SecretCommands {
|
||||||
|
/// Activate admin mode
|
||||||
|
Secret {
|
||||||
|
pass: String
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(BotCommands, Clone)]
|
#[derive(BotCommands, Clone)]
|
||||||
#[command(rename_rule = "lowercase")]
|
#[command(rename_rule = "lowercase")]
|
||||||
pub enum AdminCommands {
|
pub enum AdminCommands {
|
||||||
@ -42,3 +52,27 @@ pub async fn admin_command_handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn secret_command_handler(
|
||||||
|
mut db: DB,
|
||||||
|
//config: Config,
|
||||||
|
bot: Bot,
|
||||||
|
msg: Message,
|
||||||
|
cmd: SecretCommands,
|
||||||
|
admin_password: String
|
||||||
|
) -> Result<(), teloxide::RequestError> {
|
||||||
|
println!("Admin Pass: {}", admin_password);
|
||||||
|
let user = db.get_or_init_user(msg.from.clone().unwrap().id.0 as i64).await;
|
||||||
|
println!("MSG: {}", msg.html_text().unwrap());
|
||||||
|
match cmd {
|
||||||
|
SecretCommands::Secret { pass } => {
|
||||||
|
if user.is_admin == true {
|
||||||
|
bot.send_message(msg.from.unwrap().id, "You are an admin already").await?;
|
||||||
|
} else if pass == admin_password {
|
||||||
|
db.set_admin(user.id, true).await;
|
||||||
|
bot.send_message(msg.from.unwrap().id, "You are admin now!").await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
35
src/main.rs
35
src/main.rs
@ -3,6 +3,7 @@ pub mod admin;
|
|||||||
|
|
||||||
use crate::db::DB;
|
use crate::db::DB;
|
||||||
use crate::admin::{AdminCommands, admin_command_handler};
|
use crate::admin::{AdminCommands, admin_command_handler};
|
||||||
|
use crate::admin::{secret_command_handler, SecretCommands};
|
||||||
|
|
||||||
use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, prelude::*, types::InputFile, utils::{command::BotCommands, render::RenderMessageTextHelper}};
|
use teloxide::{dispatching::dialogue::GetChatId, payloads::SendMessageSetters, prelude::*, types::InputFile, utils::{command::BotCommands, render::RenderMessageTextHelper}};
|
||||||
use envconfig::Envconfig;
|
use envconfig::Envconfig;
|
||||||
@ -26,16 +27,6 @@ enum UserCommands {
|
|||||||
Help,
|
Help,
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are should not appear in /help
|
|
||||||
#[derive(BotCommands, Clone)]
|
|
||||||
#[command(rename_rule = "lowercase")]
|
|
||||||
enum SecretCommands {
|
|
||||||
/// Activate admin mode
|
|
||||||
Secret {
|
|
||||||
pass: String
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
trait LogMsg {
|
trait LogMsg {
|
||||||
fn log(self) -> Self;
|
fn log(self) -> Self;
|
||||||
}
|
}
|
||||||
@ -115,30 +106,6 @@ async fn user_command_handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn secret_command_handler(
|
|
||||||
mut db: DB,
|
|
||||||
//config: Config,
|
|
||||||
bot: Bot,
|
|
||||||
msg: Message,
|
|
||||||
cmd: SecretCommands,
|
|
||||||
admin_password: String
|
|
||||||
) -> Result<(), teloxide::RequestError> {
|
|
||||||
println!("Admin Pass: {}", admin_password);
|
|
||||||
let user = db.get_or_init_user(msg.from.clone().unwrap().id.0 as i64).await;
|
|
||||||
println!("MSG: {}", msg.html_text().unwrap());
|
|
||||||
match cmd {
|
|
||||||
SecretCommands::Secret { pass } => {
|
|
||||||
if user.is_admin == true {
|
|
||||||
bot.send_message(msg.from.unwrap().id, "You are an admin already").await?;
|
|
||||||
} else if pass == admin_password {
|
|
||||||
db.set_admin(user.id, true).await;
|
|
||||||
bot.send_message(msg.from.unwrap().id, "You are admin now!").await?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn echo(
|
async fn echo(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user