From 7a18d9ea417d5ba21c103a04b7cecb3960580cd7 Mon Sep 17 00:00:00 2001 From: Sense T Date: Sun, 8 Oct 2023 08:25:15 +0000 Subject: [PATCH 1/3] 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() From c376cd2c25e992bab7765a3a1e3d8e219084640e Mon Sep 17 00:00:00 2001 From: Sense T Date: Mon, 9 Oct 2023 03:46:58 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=8C=96=E5=8F=98?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加 Dockerfile 及 github action 配置 自动构建 zh 及 en 两种语言的 arm64 及 aarch64 版本的镜像 --- .github/workflows/docker.yml | 75 ++++++++++++++++++++++++++++++++++++ Dockerfile | 15 ++++++++ 2 files changed, 90 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..dd33acc5 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,75 @@ +name: Package Image + +on: + push: + tags: + - 'v*' + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@7e0881f8fe90b25e305bbf0309761e9314607e25 + with: + cosign-release: 'v1.9.0' + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image - Chinese + id: build-and-push-zh + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + build-args: LOCALE=zh + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:zh,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:zh-${{ github.ref_name }} + platforms: linux/amd64,linux/arm64 + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image - English + id: build-and-push-en + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + build-args: LOCALE=en + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:en,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:en-${{ github.ref_name }} + platforms: linux/amd64,linux/arm64 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0b219942 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine as build + +ARG LOCALE=zh + +ENV RUSTFLAGS="-C target-feature=-crt-static" LOCALE=${LOCALE} +WORKDIR /usr/src/rssbot +COPY . . +RUN apk add --no-cache rustup openssl-dev build-base && rustup-init -y --default-toolchain nightly && source ${HOME}/.cargo/env && cargo build --release + +FROM alpine + +RUN apk add --no-cache ca-certificates openssl libgcc +ENTRYPOINT [ "/rssbot" ] + +COPY --from=build /usr/src/rssbot/target/release/rssbot ./ \ No newline at end of file From 040da696ee04a85634a94cea572dc40c1d587e28 Mon Sep 17 00:00:00 2001 From: iovxw Date: Mon, 16 Oct 2023 23:31:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"=E5=AE=B9=E5=99=A8=E5=8C=96?= =?UTF-8?q?=E5=8F=98=E6=9B=B4"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c376cd2c25e992bab7765a3a1e3d8e219084640e. --- .github/workflows/docker.yml | 75 ------------------------------------ Dockerfile | 15 -------- 2 files changed, 90 deletions(-) delete mode 100644 .github/workflows/docker.yml delete mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index dd33acc5..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Package Image - -on: - push: - tags: - - 'v*' - -env: - # Use docker.io for Docker Hub if empty - REGISTRY: ghcr.io - # github.repository as / - IMAGE_NAME: ${{ github.repository }} - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - # This is used to complete the identity challenge - # with sigstore/fulcio when running outside of PRs. - id-token: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Install the cosign tool except on PR - # https://github.com/sigstore/cosign-installer - - name: Install cosign - if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@7e0881f8fe90b25e305bbf0309761e9314607e25 - with: - cosign-release: 'v1.9.0' - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - # Workaround: https://github.com/docker/build-push-action/issues/461 - - name: Setup Docker buildx - uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf - - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - Chinese - id: build-and-push-zh - uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a - with: - context: . - build-args: LOCALE=zh - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:zh,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:zh-${{ github.ref_name }} - platforms: linux/amd64,linux/arm64 - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - English - id: build-and-push-en - uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a - with: - context: . - build-args: LOCALE=en - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:en,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:en-${{ github.ref_name }} - platforms: linux/amd64,linux/arm64 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0b219942..00000000 --- a/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM alpine as build - -ARG LOCALE=zh - -ENV RUSTFLAGS="-C target-feature=-crt-static" LOCALE=${LOCALE} -WORKDIR /usr/src/rssbot -COPY . . -RUN apk add --no-cache rustup openssl-dev build-base && rustup-init -y --default-toolchain nightly && source ${HOME}/.cargo/env && cargo build --release - -FROM alpine - -RUN apk add --no-cache ca-certificates openssl libgcc -ENTRYPOINT [ "/rssbot" ] - -COPY --from=build /usr/src/rssbot/target/release/rssbot ./ \ No newline at end of file