From 36811201785f6fba7bb59464059418ae0749e5c1 Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:51:50 +0300 Subject: [PATCH 1/8] User alias -> user ID --- bot.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/bot.py b/bot.py index a8ee1cc..1ea5d60 100755 --- a/bot.py +++ b/bot.py @@ -16,7 +16,7 @@ _REGEX_COMMAND_RAW = r'^[/!](?P(?P\w+).*)' _REGEX_COMMAND = r'^[/!]\w+\s*(?P\w+)?' _ENV_TELEGRAM_BOT_TOKEN = "TELEGRAM_BOT_TOKEN" -_ENV_TELEGRAM_USER_ALIAS = "TELEGRAM_USER_ALIAS" +_ENV_TELEGRAM_USER_ID = "TELEGRAM_USER_ID" _ENV_TELEGRAM_PROXY = "TELEGRAM_PROXY" _ENV_ASF_IPC_HOST = "ASF_IPC_HOST" _ENV_ASF_IPC_PORT = "ASF_IPC_PORT" @@ -36,7 +36,7 @@ parser.add_argument("--proxy", help="Use a proxy to connect to Telegram. Format: " "://:. For example: http://192.168.1.1:7890" , default=None) -parser.add_argument("--alias", type=str, help="Telegram alias of the bot owner.", default=None) +parser.add_argument("--id", type=str, help="Telegram ID of the bot owner.", default=None) args = parser.parse_args() logger.set_level(args.verbosity) @@ -52,12 +52,12 @@ exit(1) try: - args.alias = os.environ[_ENV_TELEGRAM_USER_ALIAS] + args.id = os.environ[_ENV_TELEGRAM_USER_ID] except KeyError as key_error: - if not args.alias: + if not args.id: LOG.critical( - "No telegram user alias provided. Please do so using --alias argument or %s environment variable.", - _ENV_TELEGRAM_USER_ALIAS) + "No telegram user ID provided. Please do so using --id argument or %s environment variable.", + _ENV_TELEGRAM_USER_ID) exit(1) try: args.proxy = os.environ[_ENV_TELEGRAM_PROXY] @@ -81,7 +81,7 @@ pass args.token = args.token.strip() -args.alias = [alias.replace('@', '').strip() for alias in args.alias.split(',')] +args.id = id args.host = args.host.strip() args.port = args.port.strip() if args.password: @@ -93,7 +93,7 @@ LOG.info("Starting up bot...") LOG.debug("Telegram token: %s", args.token) LOG.debug("Telegram Proxy %s", args.proxy) -LOG.debug("User alias: %s", args.alias) +LOG.debug("User ID: %s", args.id) LOG.debug("ASF IPC host: %s", args.host) LOG.debug("ASF IPC port: %s", args.port) @@ -122,9 +122,9 @@ def is_user_message(message): - """ Returns if a message is from the owner of the bot comparing it to the user alias provided on startup. """ - username = message.chat.username - return username in args.alias + """ Returns if a message is from the owner of the bot comparing it to the user id provided on startup. """ + id = message.chat.id + return id in args.id @bot.message_handler(func=is_user_message, commands=['status']) @@ -199,8 +199,8 @@ def check_for_cdkeys(message): response = asf_connector.bot_redeem('ASF', cdkeys) reply_to(message, "" + str(response) + "") else: - LOG.debug("Bypassed message: %s \n from user alias %s.", - message.text, message.chat.username) + LOG.debug("Bypassed message: %s \n from user ID %s.", + message.text, message.chat.id) def reply_to(message, text, sanitize=False, **kwargs): From 58df61229e54b1d44bf7dba9b507144a063814e9 Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 21:05:05 +0300 Subject: [PATCH 2/8] Update docker.yml --- .github/workflows/docker.yml | 93 +++++++++--------------------------- 1 file changed, 22 insertions(+), 71 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0ff4470..39577fb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,78 +1,29 @@ -# This is a basic workflow to help you get started with Actions -name: Docker Build Action - -# Controls when the workflow will run +name: Build and publish a Docker image to ghcr.io on: - # Triggers the workflow on push or pull request events but only for the master and develop branch - workflow_dispatch: - push: - branches: - - 'master' - - 'develop' - tags: - - 'v*.*.*' - pull_request: - branches: - - 'master' - - 'develop' -permissions: - contents: read - packages: write + # publish on releases, e.g. v2.1.13 (image tagged as "2.1.13" - "v" prefix is removed) + release: + types: [ published ] + # publish on pushes to the main branch (image tagged as "latest") + push: + branches: + - master jobs: - build: - runs-on: ubuntu-latest - env: - DOCKER_IMAGE_NAME: asfbot + docker_publish: + runs-on: "ubuntu-20.04" + steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Sets env vars for tag latest - run: | - echo "DOCKER_IMAGE_TAG=:latest" >> $GITHUB_ENV - if: github.ref_name == 'master' && github.event_name != 'pull_request' - - name: Sets env vars for other branches - run: | - echo "DOCKER_IMAGE_TAG=:$GITHUB_REF_NAME" >> $GITHUB_ENV - if: github.ref_name != 'master' && github.event_name != 'pull_request' - # https://github.com/docker/setup-qemu-action - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - name: Login to GHCR - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Login to DockerHub - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push - id: docker_build_GHCR - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: ${{ github.event_name != 'pull_request' }} - file: Dockerfile - tags: | - ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}${{ env.DOCKER_IMAGE_TAG }} - ${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}${{ env.DOCKER_IMAGE_TAG }} - - name: Docker Hub Description - if: github.event_name != 'pull_request' && github.ref_name == 'master' - uses: peter-evans/dockerhub-description@v3 + - uses: actions/checkout@v2 + + # https://github.com/marketplace/actions/push-to-ghcr + - name: Build and publish a Docker image for ${{ github.repository }} + uses: macbre/push-to-ghcr@master with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ${{ secrets.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }} - readme-filepath: ./README.md + image_name: ${{ github.repository }} # it will be lowercased internally + github_token: ${{ secrets.GITHUB_TOKEN }} + # optionally push to the Docker Hub (docker.io) + # docker_io_token: ${{ secrets.DOCKER_IO_ACCESS_TOKEN }} # see https://hub.docker.com/settings/security + # customize the username to be used when pushing to the Docker Hub + # docker_io_user: foobar # see https://github.com/macbre/push-to-ghcr/issues/14 From 9cbdb6f10590d78942fd2662a5c892fe4ecb734d Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 21:11:09 +0300 Subject: [PATCH 3/8] oopsie --- bot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot.py b/bot.py index 1ea5d60..bdbeb6d 100755 --- a/bot.py +++ b/bot.py @@ -81,7 +81,6 @@ pass args.token = args.token.strip() -args.id = id args.host = args.host.strip() args.port = args.port.strip() if args.password: From 3dcbfd2eefd117fa427c24e3db2d8408b5021ca2 Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 21:18:25 +0300 Subject: [PATCH 4/8] whoopsie --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index bdbeb6d..ccd4182 100755 --- a/bot.py +++ b/bot.py @@ -122,7 +122,7 @@ def is_user_message(message): """ Returns if a message is from the owner of the bot comparing it to the user id provided on startup. """ - id = message.chat.id + id = (message.chat.id, " ") return id in args.id From 0186ba449a0a5bac48be4122da224cb7f45747fd Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 21:24:25 +0300 Subject: [PATCH 5/8] erm what the sigma --- bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index ccd4182..71e6054 100755 --- a/bot.py +++ b/bot.py @@ -122,8 +122,8 @@ def is_user_message(message): """ Returns if a message is from the owner of the bot comparing it to the user id provided on startup. """ - id = (message.chat.id, " ") - return id in args.id + id = message.chat.id + return id in (args.id, " ") @bot.message_handler(func=is_user_message, commands=['status']) From 53bdd749ded68b43e754ffd45ce2c3e77e6f7564 Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 21:29:58 +0300 Subject: [PATCH 6/8] i should go work in mcdonalds --- bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 71e6054..f95d307 100755 --- a/bot.py +++ b/bot.py @@ -123,7 +123,7 @@ def is_user_message(message): """ Returns if a message is from the owner of the bot comparing it to the user id provided on startup. """ id = message.chat.id - return id in (args.id, " ") + return id == args.id @bot.message_handler(func=is_user_message, commands=['status']) From c9438f2d16c58c852087c897dac1d57d29c27af4 Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:31:36 +0300 Subject: [PATCH 7/8] finally --- bot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index f95d307..b8da76f 100755 --- a/bot.py +++ b/bot.py @@ -36,7 +36,7 @@ parser.add_argument("--proxy", help="Use a proxy to connect to Telegram. Format: " "://:. For example: http://192.168.1.1:7890" , default=None) -parser.add_argument("--id", type=str, help="Telegram ID of the bot owner.", default=None) +parser.add_argument("--user_id", type=int, help="Telegram ID of the bot owner.", default=None) args = parser.parse_args() logger.set_level(args.verbosity) @@ -52,11 +52,11 @@ exit(1) try: - args.id = os.environ[_ENV_TELEGRAM_USER_ID] + args.user_id = os.environ[_ENV_TELEGRAM_USER_ID] except KeyError as key_error: - if not args.id: + if not args.user_id: LOG.critical( - "No telegram user ID provided. Please do so using --id argument or %s environment variable.", + "No telegram user ID provided. Please do so using --user_id argument or %s environment variable.", _ENV_TELEGRAM_USER_ID) exit(1) try: @@ -81,6 +81,7 @@ pass args.token = args.token.strip() +args.user_id = args.user_id args.host = args.host.strip() args.port = args.port.strip() if args.password: @@ -92,7 +93,7 @@ LOG.info("Starting up bot...") LOG.debug("Telegram token: %s", args.token) LOG.debug("Telegram Proxy %s", args.proxy) -LOG.debug("User ID: %s", args.id) +LOG.debug("User ID: %s", args.user_id) LOG.debug("ASF IPC host: %s", args.host) LOG.debug("ASF IPC port: %s", args.port) @@ -122,8 +123,7 @@ def is_user_message(message): """ Returns if a message is from the owner of the bot comparing it to the user id provided on startup. """ - id = message.chat.id - return id == args.id + return message.chat.id == args.user_id @bot.message_handler(func=is_user_message, commands=['status']) From f33761e4634655c8280a04334631a2bb0de41294 Mon Sep 17 00:00:00 2001 From: akairose <47789168+akairose@users.noreply.github.com> Date: Wed, 2 Apr 2025 23:24:39 +0300 Subject: [PATCH 8/8] whoooppps --- bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index b8da76f..8691f88 100755 --- a/bot.py +++ b/bot.py @@ -52,7 +52,8 @@ exit(1) try: - args.user_id = os.environ[_ENV_TELEGRAM_USER_ID] + user_id = 1 + args.user_id = int(os.getenv('TELEGRAM_USER_ID',user_id)) except KeyError as key_error: if not args.user_id: LOG.critical(