Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila committed Dec 8, 2024
0 parents commit 41fa38b
Show file tree
Hide file tree
Showing 56 changed files with 9,707 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/commitlintrc.json",
"extends": ["@commitlint/config-conventional"]
}
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
tab_width = 2
indent_style = space
insert_final_newline = true
end_of_line = lf
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.lockb binary diff=lockb
eslint.config.* linguist-vendored
133 changes: 133 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Check Package

on:
pull_request_target:
workflow_call:
inputs:
cwd:
type: string
default: "."

jobs:
authorize:
name: Authorize
environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true

check_format:
name: Check formatting
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.cwd }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Cache tools cache
uses: actions/cache@v4
with:
path: .cache
key: tools-${{ runner.os }}-${{ github.sha }}
restore-keys: tools-${{ runner.os }}-

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Perform check
run: bun run format:check

check_types:
name: Check types
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.cwd }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Cache tools cache
uses: actions/cache@v4
with:
path: .cache
key: tools-${{ runner.os }}-${{ github.sha }}
restore-keys: tools-${{ runner.os }}-

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Perform check
run: bun run check-types

lint:
name: Lint code
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.cwd }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Cache tools cache
uses: actions/cache@v4
with:
path: .cache
key: tools-${{ runner.os }}-${{ github.sha }}
restore-keys: tools-${{ runner.os }}-

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Perform check
run: bun run lint

test:
name: Test code
runs-on: ubuntu-latest
needs: authorize
environment: testing
defaults:
run:
working-directory: ${{ inputs.cwd }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- name: Cache tools cache
uses: actions/cache@v4
with:
path: .cache
key: tools-${{ runner.os }}-${{ github.sha }}
restore-keys: tools-${{ runner.os }}-

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Perform check
run: bun run test
env:
SEARCH_SERVER_ADDRESS: ${{ secrets.SEARCH_SERVER_ADDRESS }}
SEARCH_SERVER_PASSWORD: ${{ secrets.SEARCH_SERVER_PASSWORD }}
TELEGRAM_USER_SESSION: ${{ secrets.TELEGRAM_USER_SESSION }}
TELEGRAM_API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
TELEGRAM_API_ID: ${{ secrets.TELEGRAM_API_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
ALLOWED_USERS: ${{ secrets.ALLOWED_USERS }}
63 changes: 63 additions & 0 deletions .github/workflows/deploy_bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Deploy Bot

on:
push:
branches:
- master
paths:
- packages/image-search-bot/src/**
- packages/image-search-bot/package.json
- packages/image-search-bot/wrangler.json

jobs:
check-token:
runs-on: ubuntu-latest
environment: production
outputs:
is_set: ${{ steps.check.outputs.is_set }}
steps:
- name: Check for Cloudflare API token
id: check
run: |
if [[ '${{ secrets.CLOUDFLARE_API_TOKEN }}' ]]; then
echo "is_set=true" >> "$GITHUB_OUTPUT"
else
echo "is_set=false" >> "$GITHUB_OUTPUT"
echo "Cloudflare API token is not set. Skipping deployment."
fi
check-package:
name: Check package
needs: check-token
if: ${{ needs.check-token.outputs.is_set == 'true' }}
uses: ./.github/workflows/check.yml
secrets: inherit
with:
cwd: packages/image-search-bot

deploy:
runs-on: ubuntu-latest
needs: check-package
environment: production
defaults:
run:
working-directory: packages/image-search-bot
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- name: Setup Bun
uses: oven-sh/setup-bun@f4d14e03ff726c06358e5557344e1da148b56cf7

- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
with:
node-version: lts/*

- name: Install dependencies
run: bun install --frozen-lockfile --production

- name: Build & Deploy
run: bun run deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
96 changes: 96 additions & 0 deletions .github/workflows/deploy_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Deploy Server

on:
push:
branches:
- master
paths:
- packages/image-search-server/src/**
- packages/image-search-server/package.json

jobs:
check-credentials:
name: Check credentials
runs-on: ubuntu-latest
environment: production
outputs:
is_set: ${{ steps.check.outputs.is_set }}
steps:
- name: Check SSH credentials
id: check
run: |
if [[ '${{ secrets.SSH_KEY }}' && '${{ secrets.SSH_HOST }}' && '${{ secrets.SSH_USERNAME }}' ]]; then
echo "is_set=true" >> "$GITHUB_OUTPUT"
else
echo "is_set=false" >> "$GITHUB_OUTPUT"
echo "SSH credentials are not set. Skipping deployment."
fi
check-package:
name: Check package
needs: check-credentials
if: ${{ needs.check-credentials.outputs.is_set == 'true' }}
uses: ./.github/workflows/check.yml
secrets: inherit
with:
cwd: packages/image-search-server

# blocker for commented: https://github.com/oven-sh/bun/issues/6567
deploy:
runs-on: ubuntu-latest
needs: check-package
environment: production
defaults:
run:
working-directory: packages/image-search-server
steps:
# - name: Checkout repo
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo '${{ secrets.SSH_KEY }}' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo 'StrictHostKeyChecking no' >> ~/.ssh/config
working-directory: .

# - name: Setup Bun
# uses: oven-sh/setup-bun@f4d14e03ff726c06358e5557344e1da148b56cf7

# - name: Install dependencies
# run: bun install --frozen-lockfile --production

# - name: Build
# run: bun run build

# - name: Deploy
# run: |
# scp dist/image-search-server '${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/image-search-server/image-search-server_new'
# ssh '${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}' /bin/bash << EOF
# pkill -f image-search-server || true
# cd ~/image-search-server
# mv image-search-server_new image-search-server
# nohup ./image-search-server > /dev/null 2>&1 &
# EOF

# temporary solution
- name: Deploy
uses: appleboy/ssh-action@66aa4d343bf909ac4fa0ac52f4e62a9adc354c95
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd
repository_name="$(basename '${{ github.repository }}')"
if [[ ! -d "$repository_name" ]]; then
git clone '${{ github.server_url }}/${{ github.repository }}'
fi
cd "$repository_name"
pkill -f 'bun run start$'
git fetch --all
git reset --hard origin/master
cd packages/image-search-server
bun install --frozen-lockfile --production
nohup bun run start > /dev/null 2>&1 &
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.env*
.cache/
6 changes: 6 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
remote_branch="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}')"

if [[ "$remote_branch" == "origin/master" ]]; then
bunx --bun commitlint --from="$remote_branch" --to=HEAD
bun run check-all
fi
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.cache/

# sadly, prettier picks up only .prettierignore in the cwd
packages/image-search-bot/src/types/wrangler/
packages/image-search-bot/.wrangler/
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"quoteProps": "consistent"
}
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"editorconfig.editorconfig",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"oven.bun-vscode",
"github.vscode-github-actions"
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[typescript][json][yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"npm.packageManager": "bun"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 SunsetTechuila

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# image-search-bot

A Telegram bot that uses Telegram servers as a proxy to bypass Yandex CAPTCHAs.

Works inline like `@pic` bot, but doesn't reject NSFW search queries and results.

Backend is built with [Bun](https://github.com/oven-sh/bun), [Elysia](https://github.com/elysiajs/elysia) and [mtcute](https://github.com/mtcute/mtcute), frontend is built with [grammY](https://github.com/grammyjs/grammY) and hosted on [Cloudflare Workers](https://workers.cloudflare.com).
Binary file added bun.lockb
Binary file not shown.
Loading

0 comments on commit 41fa38b

Please sign in to comment.