add secret command handler
This commit is contained in:
parent
bdb7022fef
commit
b858b802fd
41
src/main.rs
41
src/main.rs
@ -10,6 +10,8 @@ struct Config {
|
||||
pub bot_token: String,
|
||||
#[envconfig(from = "DATABASE_URL")]
|
||||
pub db_url: String,
|
||||
#[envconfig(from = "ADMIN_PASS")]
|
||||
pub admin_password: String,
|
||||
}
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
@ -21,6 +23,16 @@ enum UserCommands {
|
||||
Help,
|
||||
}
|
||||
|
||||
// These are should not appear in /help
|
||||
#[derive(BotCommands, Clone)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum SecretCommands {
|
||||
/// Activate admin mode
|
||||
Secret {
|
||||
pass: String
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum AdminCommands {
|
||||
@ -45,6 +57,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>>{
|
||||
.branch(
|
||||
dptree::entry().filter_command::<UserCommands>().endpoint(user_command_handler)
|
||||
)
|
||||
.branch(
|
||||
dptree::entry().filter_command::<SecretCommands>()
|
||||
.map(move || config.admin_password.clone())
|
||||
.endpoint(secret_command_handler)
|
||||
)
|
||||
.branch(
|
||||
dptree::entry().filter_async(async |msg: Message, mut db: DB| {
|
||||
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await;
|
||||
@ -87,6 +104,30 @@ 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.make_admin(user.id).await;
|
||||
bot.send_message(msg.from.unwrap().id, "You are admin now!").await?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async fn admin_command_handler(
|
||||
mut db: DB,
|
||||
bot: Bot,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user