Skip to content

Commit

Permalink
feat: Support multi-user mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KunoiSayami authored and iovxw committed Jul 31, 2021
1 parent d098c6e commit d2c7f08
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rssbot"
version = "2.0.0-alpha.9"
version = "2.0.0-alpha.10"
authors = ["iovxw <iovxw@outlook.com>"]
edition = "2018"

Expand Down
1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
--admins <users id> Multi-user mode, only specified users can use this bot, split users with `,'
-d, --database <path> Path to database [default: ./rssbot.json]
--max-feed-size <bytes> Maximum feed size, 0 is unlimited [default: 2097152]
--max-interval <seconds> Maximum fetch interval [default: 43200]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
--admins <users id> Multi-user mode, only specified users can use this bot, split users with `,'
-d, --database <path> Path to database [default: ./rssbot.json]
--max-feed-size <bytes> Maximum feed size, 0 is unlimited [default: 2097152]
--max-interval <seconds> Maximum fetch interval [default: 43200]
Expand Down
5 changes: 4 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub use sub::sub;
pub use unsub::unsub;

pub async fn check_command(opt: &crate::Opt, cmd: Arc<Command<Text>>) -> bool {
use std::str::FromStr;
use tbot::contexts::fields::Message;
use tbot::types::chat::Kind::*;
let target = &mut MsgTarget::new(cmd.chat.id, cmd.message_id);
Expand All @@ -30,7 +31,9 @@ pub async fn check_command(opt: &crate::Opt, cmd: Arc<Command<Text>>) -> bool {
.unwrap_or_else(|| cmd.chat.id.0);

// Single user mode
if matches!(opt.single_user, Some(owner) if owner != from) {
if matches!(opt.single_user, Some(owner) if owner != from)
|| matches!(&opt.admins, Some(admins) if admins.split(",").into_iter().map(|x| i64::from_str(x.trim()).expect("Not valid number")).all(|admin| admin != from))
{
eprintln!(
"Unauthenticated request from user/channel: {}, command: {}, args: {}",
from, cmd.command, cmd.text.value
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct Opt {
/// Single user mode, only specified user can use this bot
#[structopt(long, value_name = "user id")]
single_user: Option<i64>,
/// Multi-user mode, only specified users can use this bot, split users with `,'
#[structopt(long, value_name = "users id")]
admins: Option<String>,
/// Make bot commands only accessible for group admins.
#[structopt(long)]
restricted: bool,
Expand Down

0 comments on commit d2c7f08

Please sign in to comment.