From 7aedf14e700512de710df54edcd320ef0ca2f2b9 Mon Sep 17 00:00:00 2001 From: Sense T Date: Sun, 8 Oct 2023 08:25:15 +0000 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 2d42871df587b5a533a01dda9fc83a5350a922f2 Author: Sense T Date: Sun Oct 8 08:24:36 2023 +0000 增加自定义 tgapi uri 选项 --- README.en.md | 3 +++ README.md | 1 + src/main.rs | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.en.md b/README.en.md index 969dca8c..0e19b8d9 100644 --- a/README.en.md +++ b/README.en.md @@ -42,6 +42,8 @@ The compiled files are available at: `./target/release/rssbot` ## Run ``` +A simple Telegram RSS bot. + USAGE: rssbot [FLAGS] [OPTIONS] @@ -54,6 +56,7 @@ FLAGS: OPTIONS: --admin ... Private mode, only specified user can use this bot. This argument can be passed multiple times to allow multiple admins + --api-uri Custom telegram api URI [default: https://api.telegram.org/] -d, --database Path to database [default: ./rssbot.json] --max-feed-size Maximum feed size, 0 is unlimited [default: 2097152] --max-interval Maximum fetch interval [default: 43200] diff --git a/README.md b/README.md index 7149c99a..a2b8ec4c 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ FLAGS: OPTIONS: --admin ... Private mode, only specified user can use this bot. This argument can be passed multiple times to allow multiple admins + --api-uri Custom telegram api URI [default: https://api.telegram.org/] -d, --database Path to database [default: ./rssbot.json] --max-feed-size Maximum feed size, 0 is unlimited [default: 2097152] --max-interval Maximum fetch interval [default: 43200] diff --git a/src/main.rs b/src/main.rs index e2f47377..51852d36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 @@ -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, @@ -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()