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 diff --git a/bot.py b/bot.py index a8ee1cc..8691f88 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("--user_id", type=int, help="Telegram ID of the bot owner.", default=None) args = parser.parse_args() logger.set_level(args.verbosity) @@ -52,12 +52,13 @@ exit(1) try: - args.alias = os.environ[_ENV_TELEGRAM_USER_ALIAS] + user_id = 1 + args.user_id = int(os.getenv('TELEGRAM_USER_ID',user_id)) except KeyError as key_error: - if not args.alias: + if not args.user_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 --user_id argument or %s environment variable.", + _ENV_TELEGRAM_USER_ID) exit(1) try: args.proxy = os.environ[_ENV_TELEGRAM_PROXY] @@ -81,7 +82,7 @@ pass args.token = args.token.strip() -args.alias = [alias.replace('@', '').strip() for alias in args.alias.split(',')] +args.user_id = args.user_id args.host = args.host.strip() args.port = args.port.strip() if args.password: @@ -93,7 +94,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.user_id) LOG.debug("ASF IPC host: %s", args.host) LOG.debug("ASF IPC port: %s", args.port) @@ -122,9 +123,8 @@ 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. """ + return message.chat.id == args.user_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):