From bba0f862251c737e576c949320f2eecf15a74057 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 29 Jul 2021 23:27:12 +0200 Subject: feat: run bot only if authorized --- src/commands.rs | 12 ++++++++++++ src/config.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index e498916..a3a3694 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,3 +1,4 @@ +use crate::config::Config; use std::error::Error; use teloxide::payloads::SendMessageSetters; use teloxide::prelude::{AutoSend, Bot, Message, UpdateWithCx}; @@ -16,6 +17,17 @@ pub enum Command { pub async fn handler( cx: UpdateWithCx, Message>, ) -> Result<(), Box> { + let username = Config::from_env().unwrap().username; + + if let Some(author) = &cx.update.from().unwrap().username { + if *author != username { + cx.reply_to("You are not allowed to do this action!") + .await?; + + return Ok(()); + } + } + let txt = cx.update.text(); if txt.is_none() { return Ok(()); diff --git a/src/config.rs b/src/config.rs index 3199c62..668dda7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,6 +6,7 @@ pub struct Config { pub cf: String, pub password: String, pub driver_url: String, + pub username: String, } impl Config { -- cgit v1.2.3-18-g5258