Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加自定义 bot uri 选项及容器化 #430

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ The compiled files are available at: `./target/release/rssbot`
## Run

```
A simple Telegram RSS bot.

USAGE:
rssbot [FLAGS] [OPTIONS] <token>

Expand All @@ -54,6 +56,7 @@ FLAGS:
OPTIONS:
--admin <user id>... Private mode, only specified user can use this bot. This argument can be passed
multiple times to allow multiple admins
--api-uri <tgapi-uri> Custom telegram api URI [default: https://api.telegram.org/]
-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 @@ -54,6 +54,7 @@ FLAGS:
OPTIONS:
--admin <user id>... Private mode, only specified user can use this bot. This argument can be passed
multiple times to allow multiple admins
--api-uri <tgapi-uri> Custom telegram api URI [default: https://api.telegram.org/]
-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
16 changes: 12 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use hyper_proxy::{Intercept, Proxy};
use once_cell::sync::OnceCell;
use structopt::StructOpt;
use tbot;
use tbot::bot::Uri;
use tokio::{self, sync::Mutex};

// Include the tr! macro and localizations
Expand Down Expand Up @@ -82,6 +83,13 @@ pub struct Opt {
/// Make bot commands only accessible for group admins.
#[structopt(long)]
restricted: bool,
/// Custom telegram api URI
#[structopt(
long,
value_name = "tgapi-uri",
default_value = "https://api.telegram.org/"
)]
api_uri: Uri,
/// DANGER: Insecure mode, accept invalid TLS certificates
#[structopt(long)]
insecure: bool,
Expand All @@ -103,12 +111,12 @@ async fn main() -> anyhow::Result<()> {

let opt = Opt::from_args();
let db = Arc::new(Mutex::new(Database::open(opt.database.clone())?));
let bot_builder = tbot::bot::Builder::with_string_token(opt.token.clone())
.server_uri(opt.api_uri.clone());
let bot = if let Some(proxy) = init_proxy() {
tbot::bot::Builder::with_string_token(opt.token.clone())
.proxy(proxy)
.build()
bot_builder.proxy(proxy).build()
} else {
tbot::Bot::new(opt.token.clone())
bot_builder.build()
};
let me = bot
.get_me()
Expand Down