summaryrefslogtreecommitdiff
path: root/src/commands.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-07-29 23:27:12 +0200
committerSanto Cariotti <santo@dcariotti.me>2021-07-29 23:27:12 +0200
commitbba0f862251c737e576c949320f2eecf15a74057 (patch)
tree9acc23d47ca5d59a68e2a6630361529772984f49 /src/commands.rs
parentffd892ad332c994b8ed9536ff473c3037e05bc4d (diff)
feat: run bot only if authorized
Diffstat (limited to 'src/commands.rs')
-rw-r--r--src/commands.rs12
1 files changed, 12 insertions, 0 deletions
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<AutoSend<Bot>, Message>,
) -> Result<(), Box<dyn Error + Send + Sync>> {
+ 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(());