Skip to content

Commit

Permalink
fix: permission check
Browse files Browse the repository at this point in the history
  • Loading branch information
itsusinn committed Oct 19, 2021
1 parent f7d4b33 commit c82ae61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
# bot
teloxide ={ version = "0.5.2",default-features = false,features = ["frunk", "macros", "auto-send","ctrlc_handler","rustls"] }
teloxide-core = { version = "0.3.3",default-features = false, features = ["rustls"] }
teloxide-macros = "0.4"
teloxide-macros = "0.4.1"

# logging
env_logger = "0.9.0"
Expand Down
25 changes: 19 additions & 6 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::config::CONFIG;
use std::sync::Arc;
use arcstr::ArcStr;
use teloxide::dispatching::UpdateWithCx;
use teloxide::prelude::*;
use teloxide::utils::command::BotCommand;
Expand Down Expand Up @@ -33,11 +32,25 @@ pub async fn answer(
cx.answer("Mesagisto信使已禁用").await?;
}
Command::SetAddress { address } => {
// fixme check permission
CONFIG
.target_address_mapper
.insert(cx.chat_id(), ArcStr::from(address));
cx.answer("成功设置当前Group的信使地址").await?;
let sender_id = cx.update.from().unwrap().id;
let chat_id = cx.chat_id();
let admins =cx.requester.get_chat_administrators(chat_id).await?;
let mut is_admin = false;
for admin in admins {
if admin.user.id == sender_id {
is_admin = true;
break;
}
}
if is_admin {
CONFIG
.target_address_mapper
.insert(chat_id, address.into());
cx.answer("成功设置当前Group的信使地址").await?;
} else {
cx.answer("权限不足,拒绝设置信使频道").await?;
}

}
};
Ok(())
Expand Down

0 comments on commit c82ae61

Please sign in to comment.