diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..871e217 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,41 @@ +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: "11 18 * * 6" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ go ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 61b3ec9..86d8580 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,11 +9,11 @@ jobs: ci: name: CI runs-on: ubuntu-latest - timeout-minutes: 10 - container: golang:1.21-bookworm + timeout-minutes: 15 + container: golang:1 services: db: - image: postgres:15-bookworm + image: postgres:15 ports: - 5432:5432 env: @@ -22,20 +22,20 @@ jobs: POSTGRES_DB: captcha options: >- --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s + --health-interval 30s + --health-timeout 20s --health-retries 5 cache: - image: redis:7-bookworm + image: redis:7 ports: - 6379:6379 options: >- --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s + --health-interval 30s + --health-timeout 20s --health-retries 5 mongo: - image: mongo:5 + image: mongo:6 ports: - 27017:27017 env: @@ -43,9 +43,9 @@ jobs: MONGO_INITDB_ROOT_PASSWORD: password MONGO_INITDB_DATABASE: captcha options: >- - --health-cmd "echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u root -p password --quiet" - --health-interval 10s - --health-timeout 5s + --health-cmd "echo 'db.runCommand(\"ping\").ok' | mongosh mongodb://localhost:27017/test --quiet" + --health-interval 30s + --health-timeout 20s --health-retries 5 steps: - name: Checkout code @@ -74,64 +74,49 @@ jobs: MONGO_DBNAME: captcha TZ: UTC - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: go - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - uses: codecov/codecov-action@v3 cd: name: CD + runs-on: ubuntu-latest + timeout-minutes: 30 needs: - ci - runs-on: ubuntu-latest - container: debian:bookworm - timeout-minutes: 120 + permissions: + contents: read + packages: write steps: - - name: Install required packages - run: apt-get update && apt-get upgrade -y && apt-get install -y tar gzip curl ssh - - - name: Register SSH key - uses: shimataro/ssh-key-action@v2 - with: - key: ${{ secrets.SSH_KEY }} - name: id_ed25519 - known_hosts: ${{ secrets.SSH_IP }} - if_key_exists: replace + - name: Checkout code + uses: actions/checkout@v3 - - name: SSH Keyscan - run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_IP }} >> /root/.ssh/known_hosts + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - name: Pull latest code - run: > - ssh - -i /root/.ssh/id_ed25519 - -p ${{ secrets.SSH_PORT }} - -t ${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }} - 'ssh captcha "cd ${{ secrets.SSH_WORKDIR }}/captcha && git pull" ' + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Build Docker images - run: > - ssh - -i /root/.ssh/id_ed25519 - -p ${{ secrets.SSH_PORT }} - -t ${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }} - "ssh captcha 'echo ${{ secrets.SSH_PASSWORD }} | sudo -S bash -c '\"'cd ${{ secrets.SSH_WORKDIR }}/captcha && - docker compose up -d --build'\"' ' " + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + flavor: | + latest=false + tags: | + type=edge + type=sha - - name: Clean up docker artifacts - run: > - ssh - -i /root/.ssh/id_ed25519 - -p ${{ secrets.SSH_PORT }} - -t ${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }} - "ssh captcha 'echo ${{ secrets.SSH_PASSWORD }} | sudo -S bash -c '\"'docker container prune -f && - docker image prune -f && - docker builder prune -f '\"' ' " + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: "{{defaultContext}}" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} - name: Create Sentry release uses: getsentry/action-release@v1 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 00249b7..ca31b96 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -10,10 +10,10 @@ jobs: name: CI runs-on: ubuntu-latest timeout-minutes: 10 - container: golang:1.21-bookworm + container: golang:1 services: db: - image: postgres:15-bookworm + image: postgres:15 ports: - 5432:5432 env: @@ -22,20 +22,20 @@ jobs: POSTGRES_DB: captcha options: >- --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s + --health-interval 30s + --health-timeout 20s --health-retries 5 cache: - image: redis:7-bookworm + image: redis:7 ports: - 6379:6379 options: >- --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s + --health-interval 30s + --health-timeout 20s --health-retries 5 mongo: - image: mongo:5 + image: mongo:6 ports: - 27017:27017 env: @@ -43,9 +43,9 @@ jobs: MONGO_INITDB_ROOT_PASSWORD: password MONGO_INITDB_DATABASE: captcha options: >- - --health-cmd "echo 'db.runCommand({serverStatus:1}).ok' | mongo admin -u root -p password --quiet" - --health-interval 10s - --health-timeout 5s + --health-cmd "echo 'db.runCommand(\"ping\").ok' | mongosh mongodb://localhost:27017/test --quiet" + --health-interval 30s + --health-timeout 20s --health-retries 5 steps: - name: Checkout code @@ -74,12 +74,4 @@ jobs: MONGO_DBNAME: captcha TZ: UTC - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: go - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - - uses: codecov/codecov-action@v3 diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..66c4b97 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9715c22..6e86672 100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,5 @@ - - - - - + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1e84942..a923aac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,25 @@ FROM golang:1.21-bookworm AS builder -ARG PORT=8080 - WORKDIR /app COPY . . -RUN go build . +RUN go build -o teknologi-umum-captcha . -FROM debian:bookworm AS runtime +FROM debian:bookworm-slim AS runtime WORKDIR /app +ARG PORT=8080 + RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y curl ca-certificates openssl -COPY --from=builder /app/ . +COPY . . + +COPY --from=builder /app/teknologi-umum-captcha . EXPOSE ${PORT} -CMD [ "/app/teknologi-umum-bot" ] +CMD [ "/app/teknologi-umum-captcha" ] diff --git a/README.md b/README.md index 96f3689..1fe1201 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Captcha -This repository provides a captcha bot for Telegram messaging app. To self host your own captcha bot, +This repository provides a captcha bot for Telegram messaging app. To self-host your own captcha bot, please use the [captcha-lite](https://github.com/teknologi-umum/captcha-lite) as it has no analytics and database dependency whatsoever, it only needs a single small VM. @@ -10,7 +10,7 @@ Telebot repository and documentation: https://github.com/tucnak/telebot/tree/v3 ``` Teknologi Umum Captcha Bot -Copyright (C) 2021 Teknologi Umum +Copyright (C) 2023 Teknologi Umum This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,3 +25,5 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` + +See [LICENSE](./LICENSE) diff --git a/analytics/analytics_test.go b/analytics/analytics_test.go index a9a28ca..552f37d 100644 --- a/analytics/analytics_test.go +++ b/analytics/analytics_test.go @@ -5,10 +5,11 @@ import ( "database/sql" "log" "os" - "teknologi-umum-bot/analytics" "testing" "time" + "teknologi-umum-captcha/analytics" + "github.com/allegro/bigcache/v3" "github.com/getsentry/sentry-go" "github.com/jmoiron/sqlx" diff --git a/analytics/fetch.go b/analytics/fetch.go index 0e62d0a..888b146 100644 --- a/analytics/fetch.go +++ b/analytics/fetch.go @@ -3,7 +3,8 @@ package analytics import ( "context" "database/sql" - "teknologi-umum-bot/shared" + + "teknologi-umum-captcha/shared" "github.com/jmoiron/sqlx" "github.com/pkg/errors" diff --git a/analytics/incr.go b/analytics/incr.go index b006e3c..8cc20a0 100644 --- a/analytics/incr.go +++ b/analytics/incr.go @@ -4,9 +4,10 @@ import ( "context" "database/sql" "fmt" - "teknologi-umum-bot/shared" "time" + "teknologi-umum-captcha/shared" + "github.com/jmoiron/sqlx" "github.com/pkg/errors" diff --git a/analytics/incr_test.go b/analytics/incr_test.go index 6ca8929..ff94a12 100644 --- a/analytics/incr_test.go +++ b/analytics/incr_test.go @@ -2,9 +2,10 @@ package analytics_test import ( "context" - "teknologi-umum-bot/analytics" "testing" "time" + + "teknologi-umum-captcha/analytics" ) func TestIncrementUsrDB(t *testing.T) { diff --git a/analytics/join.go b/analytics/join.go index d03492d..9b27219 100644 --- a/analytics/join.go +++ b/analytics/join.go @@ -4,10 +4,11 @@ import ( "context" "database/sql" "strconv" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" + "github.com/jmoiron/sqlx" "github.com/pkg/errors" diff --git a/analytics/migration.go b/analytics/migration.go index 44956d1..08c70e4 100644 --- a/analytics/migration.go +++ b/analytics/migration.go @@ -3,9 +3,10 @@ package analytics import ( "context" "database/sql" - "teknologi-umum-bot/shared" "time" + "teknologi-umum-captcha/shared" + "github.com/jmoiron/sqlx" "github.com/pkg/errors" ) diff --git a/analytics/parser.go b/analytics/parser.go index 1a5f0f8..ba4b693 100644 --- a/analytics/parser.go +++ b/analytics/parser.go @@ -5,9 +5,10 @@ import ( "database/sql/driver" "encoding/json" "reflect" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/utils" + tb "gopkg.in/telebot.v3" ) diff --git a/analytics/parser_test.go b/analytics/parser_test.go index 6da964b..94289f3 100644 --- a/analytics/parser_test.go +++ b/analytics/parser_test.go @@ -1,9 +1,10 @@ package analytics_test import ( - "teknologi-umum-bot/analytics" "testing" + "teknologi-umum-captcha/analytics" + tb "gopkg.in/telebot.v3" ) diff --git a/analytics/server/repo.go b/analytics/server/repo.go index a989a78..9cda5eb 100644 --- a/analytics/server/repo.go +++ b/analytics/server/repo.go @@ -5,10 +5,11 @@ import ( "encoding/json" "errors" "strconv" - "teknologi-umum-bot/analytics" - "teknologi-umum-bot/dukun" "time" + "teknologi-umum-captcha/analytics" + "teknologi-umum-captcha/dukun" + "github.com/allegro/bigcache/v3" ) diff --git a/analytics/server/repo_test.go b/analytics/server/repo_test.go index cc9ee5f..4a28690 100644 --- a/analytics/server/repo_test.go +++ b/analytics/server/repo_test.go @@ -4,9 +4,10 @@ import ( "context" "encoding/json" "errors" - "teknologi-umum-bot/analytics/server" "testing" "time" + + "teknologi-umum-captcha/analytics/server" ) func TestGetAll(t *testing.T) { diff --git a/analytics/server/server.go b/analytics/server/server.go index 3c3cc31..3875294 100644 --- a/analytics/server/server.go +++ b/analytics/server/server.go @@ -7,8 +7,8 @@ import ( "os" "time" - "teknologi-umum-bot/analytics" - "teknologi-umum-bot/shared" + "teknologi-umum-captcha/analytics" + "teknologi-umum-captcha/shared" "github.com/allegro/bigcache/v3" "github.com/getsentry/sentry-go" diff --git a/analytics/server/server_test.go b/analytics/server/server_test.go index ccc4453..1dd8cff 100644 --- a/analytics/server/server_test.go +++ b/analytics/server/server_test.go @@ -6,12 +6,13 @@ import ( "errors" "log" "os" - "teknologi-umum-bot/analytics" - "teknologi-umum-bot/analytics/server" - "teknologi-umum-bot/dukun" "testing" "time" + "teknologi-umum-captcha/analytics" + "teknologi-umum-captcha/analytics/server" + "teknologi-umum-captcha/dukun" + "github.com/allegro/bigcache/v3" "github.com/jmoiron/sqlx" "github.com/lib/pq" diff --git a/analytics/swarm.go b/analytics/swarm.go index e9b2bc5..70e88dd 100644 --- a/analytics/swarm.go +++ b/analytics/swarm.go @@ -5,10 +5,11 @@ import ( "database/sql" "fmt" "strconv" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" + tb "gopkg.in/telebot.v3" ) diff --git a/ascii/ascii.go b/ascii/ascii.go index 1021218..4d58cf9 100644 --- a/ascii/ascii.go +++ b/ascii/ascii.go @@ -3,8 +3,9 @@ package ascii import ( "context" "errors" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" + + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" "github.com/getsentry/sentry-go" tb "gopkg.in/telebot.v3" diff --git a/badwords/badwords_test.go b/badwords/badwords_test.go index eaafa99..47b3913 100644 --- a/badwords/badwords_test.go +++ b/badwords/badwords_test.go @@ -4,10 +4,11 @@ import ( "context" "log" "os" - "teknologi-umum-bot/badwords" "testing" "time" + "teknologi-umum-captcha/badwords" + "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref" diff --git a/captcha/answer.go b/captcha/answer.go index ae145f5..c6e2a22 100644 --- a/captcha/answer.go +++ b/captcha/answer.go @@ -8,7 +8,8 @@ import ( "time" "github.com/getsentry/sentry-go" - "teknologi-umum-bot/shared" + + "teknologi-umum-captcha/shared" "github.com/allegro/bigcache/v3" "github.com/pkg/errors" diff --git a/captcha/captcha.go b/captcha/captcha.go index 095644d..8477bfb 100644 --- a/captcha/captcha.go +++ b/captcha/captcha.go @@ -1,7 +1,7 @@ package captcha import ( - "teknologi-umum-bot/analytics" + "teknologi-umum-captcha/analytics" "github.com/allegro/bigcache/v3" "github.com/getsentry/sentry-go" diff --git a/captcha/delete.go b/captcha/delete.go index e4e2ebb..7e1c9e1 100644 --- a/captcha/delete.go +++ b/captcha/delete.go @@ -5,9 +5,10 @@ import ( "fmt" "strconv" "strings" - "teknologi-umum-bot/shared" "time" + "teknologi-umum-captcha/shared" + tb "gopkg.in/telebot.v3" ) diff --git a/captcha/join.go b/captcha/join.go index 4fc2630..c26c859 100644 --- a/captcha/join.go +++ b/captcha/join.go @@ -8,10 +8,11 @@ import ( "github.com/getsentry/sentry-go" "strconv" "strings" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" + "github.com/allegro/bigcache/v3" tb "gopkg.in/telebot.v3" @@ -45,8 +46,8 @@ const ( // DefaultQuestion contains the default captcha questions. var DefaultQuestion = "Halo, {user}!\n\n" + - "Sebelum lanjut, selesaikan captcha ini dulu ya. Kombinasi angka dengan huruf V, W, X, dan Y. Kamu punya waktu 1 menit dari sekarang!\n\n" + - "Kalau tulisannya pecah, dirotate layarnya kebentuk landscape ya.\n\n" + + "Sebelum lanjut, selesaikan captcha ini dulu agar bisa chat di grup ini. Ubah teks besar yang kamu lihat dibawah pesan ini menjadi teks biasa. Teks tersebut hanya berupa kombinasi angka 1-9 dengan huruf V, W, X, dan Y, jangan salah ketik ya!\n\n" + + "Ini teksnya 👇, kamu punya waktu 1 menit dari sekarang! Kalau tulisannya pecah, dirotate layarnya kebentuk landscape ya.\n\n" + "
{captcha}
" // CaptchaUserJoin is the most frustrating function that I've written diff --git a/captcha/leave.go b/captcha/leave.go index 3166800..3d6ad5c 100644 --- a/captcha/leave.go +++ b/captcha/leave.go @@ -5,8 +5,9 @@ import ( "encoding/json" "github.com/getsentry/sentry-go" "strconv" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" + + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" tb "gopkg.in/telebot.v3" ) diff --git a/captcha/non.go b/captcha/non.go index f21d787..cd501be 100644 --- a/captcha/non.go +++ b/captcha/non.go @@ -5,10 +5,11 @@ import ( "encoding/json" "github.com/getsentry/sentry-go" "strconv" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" + tb "gopkg.in/telebot.v3" ) diff --git a/captcha/wait.go b/captcha/wait.go index facca8a..7e1de4f 100644 --- a/captcha/wait.go +++ b/captcha/wait.go @@ -5,10 +5,11 @@ import ( "encoding/json" "strconv" "strings" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" + "github.com/allegro/bigcache/v3" "github.com/pkg/errors" tb "gopkg.in/telebot.v3" diff --git a/captcha/welcome.go b/captcha/welcome.go index 96d32e8..9dd05b4 100644 --- a/captcha/welcome.go +++ b/captcha/welcome.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "teknologi-umum-bot/utils" + "teknologi-umum-captcha/utils" tb "gopkg.in/telebot.v3" ) @@ -18,7 +18,7 @@ import ( // that have a dynamic user value, written as {user}. // // This should be sent to the user with a random pick. -var currentWelcomeMessages = [11]string{ +var currentWelcomeMessages = [10]string{ "Halo, {user}\n\n" + "Selamat datang di grup {groupname}. Disini kita berisik banget, jadi langsung matiin notificationnya ya. " + "Disini sebenernya nggak ada aturan, tapi ya wajar-wajar aja lah. Mau ngomongin apa aja juga boleh kok. " + @@ -27,11 +27,8 @@ var currentWelcomeMessages = [11]string{ "Selamat datang di grup {groupname}. Disini kita berisik banget, jadi langsung matiin notificationnya ya. " + "Disini sebenernya nggak ada aturan, tapi ya wajar-wajar aja lah. Jangan bikin kita diciduk tukang bakso bawa HT. " + "Kalo mau OOT juga ga perlu izin, toh ini grup buat OOT.", - "Welcome {user}!\n\n" + - "Saya ngga tau mau ngomong apa lagi selain jangan lupa matiin notification, grup ini berisik banget.", "Haloo {user}!\n\n" + - "Selamat datang di grup {groupname}, yuk langsung matiin notification biar hidup kamu ngga sengsara. " + - "Tapi grup ini akur kok, sejauh ini ngga pernah ada drama. Semoga betah ya!", + "Agar silaturahmi tidak terputus, bolehkah pinjam seratus?", "Hai, {user}!\n\n" + "Selamat datang di grup {groupname}!\n\n" + "Coba ketik (dan kirim) /joke@TeknologiUmumBot deh, nanti grup ini tiba-tiba hidup.\n\n" + @@ -58,9 +55,8 @@ var currentWelcomeMessages = [11]string{ "kuis-kuis yang ada. Kebanyakan kuisnya anonim kok, jadi kamu nggak perlu takut salah-benar.\n\n" + "Semoga harimu menyenangkan!", "Hai {user}!\n\n" + - "Saya nggak tau mau ngomong apa, jadi saya kasih quotes aja:\n\n" + - "\"Learn to light a candle in the darkest moments of someone's life. Be the light that helps others see; " + - "it is what gives life its deepest significance\" - Roy T. Bennet", + "Yeay! Kamu bisa menyelesaikan captcha super aneh itu. Selamat datang di {groupname} ya.\n\n" + + "Cerita sedikit soal diri kamu dong, sekarang kerjaannya apa dan suka melakukan apa pas senggang?", } var regularWelcomeMessage = "Halo, {user}!\n\n" + diff --git a/cmd/cmd.go b/cmd/cmd.go index e19574a..0acc613 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -6,15 +6,16 @@ import ( "os" "strconv" "strings" - "teknologi-umum-bot/analytics" - "teknologi-umum-bot/ascii" - "teknologi-umum-bot/badwords" - "teknologi-umum-bot/captcha" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/underattack" - "teknologi-umum-bot/utils" "time" + "teknologi-umum-captcha/analytics" + "teknologi-umum-captcha/ascii" + "teknologi-umum-captcha/badwords" + "teknologi-umum-captcha/captcha" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/underattack" + "teknologi-umum-captcha/utils" + "github.com/allegro/bigcache/v3" "github.com/getsentry/sentry-go" "github.com/jmoiron/sqlx" diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml deleted file mode 100644 index b1f0fb2..0000000 --- a/docker-compose.dev.yml +++ /dev/null @@ -1,21 +0,0 @@ -services: - db: - image: postgres:14-alpine - ports: - - 5432:5432 - environment: - POSTGRES_PASSWORD: password - POSTGRES_USER: postgres - POSTGRES_DB: captcha - cache: - image: redis:6-alpine - ports: - - 6379:6379 - mongo: - image: mongo:6-focal - ports: - - 27017:27017 - environment: - MONGO_INITDB_ROOT_USERNAME: root - MONGO_INITDB_ROOT_PASSWORD: password - MONGO_INITDB_DATABASE: captcha diff --git a/docker-compose.yml b/docker-compose.yml index f9b92ca..0a488a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,102 +1,48 @@ services: - postgres: - image: postgres:15.0-bookworm + db: + image: postgres:15-alpine + ports: + - 5432:5432 environment: - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_DB: ${POSTGRES_DB} - TZ: UTC - platform: linux/amd64 + POSTGRES_PASSWORD: password + POSTGRES_USER: postgres + POSTGRES_DB: captcha healthcheck: - test: pg_isready + test: "pg_isready" + interval: 30s + timeout: 20s + retries: 5 + logging: + driver: local + options: + max-size: 10M + cache: + image: redis:6-alpine + ports: + - 6379:6379 + healthcheck: + test: "redis-cli ping | grep PONG" interval: 15s timeout: 10s retries: 5 - deploy: - mode: replicated - replicas: 1 - restart_policy: - condition: unless-stopped - delay: 30s - window: 120s - resources: - limits: - memory: 2GB - cpus: '2' - reservations: - memory: 50MB - cpus: '0.10' - networks: - - captcha logging: - driver: json-file + driver: local options: - max-size: 100M - max-file: 3 - application: - build: . + max-size: 10M + mongo: + image: mongo:6-focal + ports: + - 27017:27017 environment: - ENVIRONMENT: production - BOT_TOKEN: ${BOT_TOKEN} - SENTRY_DSN: ${SENTRY_DSN} - DATABASE_URL: ${DATABASE_URL} - MONGO_URL: ${MONGO_URL} - TZ: UTC - TEKNUM_ID: ${TEKNUM_ID} - ADMIN_ID: ${ADMIN_ID} - PORT: 8080 - labels: - - "traefik.enable=true" - - "traefik.http.routers.captcha_bot.entrypoints=web,websecure" - - "traefik.http.routers.captcha_bot.rule=Host(`captcha.teknologiumum.com`)" - - "traefik.http.routers.captcha_bot.tls.certresolver=tlsresolver" - - "traefik.http.routers.captcha_bot.middlewares=captcha_bot-header,captcha_bot-rate,captcha_bot-redirectscheme" - - "traefik.http.services.captcha_bot.loadbalancer.server.port=8080" - - "traefik.http.services.captcha_bot.loadbalancer.server.scheme=http" - - "traefik.http.services.captcha_bot.loadbalancer.healthcheck.interval=30s" - - "traefik.http.services.captcha_bot.loadbalancer.healthcheck.path=/" - - "traefik.http.middlewares.captcha_bot-rate.ratelimit.average=100" - - "traefik.http.middlewares.captcha_bot-rate.ratelimit.burst=20" - - "traefik.http.middlewares.captcha_bot-rate.ratelimit.period=1m" - - "traefik.http.middlewares.captcha_bot-header.headers.addvaryheader=true" - - "traefik.http.middlewares.captcha_bot-header.headers.frameDeny=true" - - "traefik.http.middlewares.captcha_bot-header.headers.browserxssfilter=true" - - "traefik.http.middlewares.captcha_bot-header.headers.stsSeconds=604800" - - "traefik.http.middlewares.captcha_bot-header.headers.stsIncludeSubdomains=true" - - "traefik.http.middlewares.captcha_bot-header.headers.browserXssFilter=true" - - "traefik.http.middlewares.captcha_bot-header.headers.contentTypeNosniff=true" - - "traefik.http.middlewares.captcha_bot-header.headers.customResponseHeaders.server=Teknologi Umum" - - "traefik.http.middlewares.captcha_bot-redirectscheme.redirectscheme.scheme=https" - - "traefik.http.middlewares.captcha_bot-redirectscheme.redirectscheme.permanent=true" - platform: linux/amd64 + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: password + MONGO_INITDB_DATABASE: captcha healthcheck: - test: curl -f http://application:8080 || exit 1 - interval: 15s - timeout: 10s + test: "echo 'db.runCommand(\"ping\").ok' | mongosh mongodb://localhost:27017/test --quiet" + interval: 30s + timeout: 20s retries: 5 - deploy: - mode: replicated - replicas: 1 - restart_policy: - condition: unless-stopped - delay: 30s - window: 120s - resources: - limits: - memory: 500MB - cpus: '1' - reservations: - memory: 25MB - cpus: '0.10' - networks: - - captcha logging: - driver: json-file + driver: local options: - max-size: 100M - max-file: 3 - -networks: - captcha: - driver: bridge - external: true + max-size: 10M diff --git a/dukun/dukun.go b/dukun/dukun.go index 3ac531b..687ae0c 100644 --- a/dukun/dukun.go +++ b/dukun/dukun.go @@ -8,7 +8,7 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -// MongoDB collection schema as taken from +// MongoDB's collection schema as taken from // https://github.com/teknologi-umum/bot/blob/5b6df1e179b878f597efde10e20612d04ba0df02/src/services/dukun/index.js#L19-L31 // // const dukunSchema = new mongoose.Schema( diff --git a/dukun/dukun_test.go b/dukun/dukun_test.go index ced82cf..3b72ee2 100644 --- a/dukun/dukun_test.go +++ b/dukun/dukun_test.go @@ -4,10 +4,11 @@ import ( "context" "log" "os" - "teknologi-umum-bot/dukun" "testing" "time" + "teknologi-umum-captcha/dukun" + "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref" diff --git a/go.mod b/go.mod index d12dd57..2600f61 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module teknologi-umum-bot +module teknologi-umum-captcha go 1.20 diff --git a/go.sum b/go.sum index f426955..e2aabcb 100644 --- a/go.sum +++ b/go.sum @@ -118,13 +118,9 @@ github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/getsentry/sentry-go v0.20.0 h1:bwXW98iMRIWxn+4FgPW7vMrjmbym6HblXALmhjHmQaQ= -github.com/getsentry/sentry-go v0.20.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI= github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= -github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -264,8 +260,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= -github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= -github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -289,16 +283,12 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.10.8 h1:3fdt97i/cwSU83+E0hZTC/Xpc9mTZxc6UWSCRcSbxiE= -github.com/lib/pq v1.10.8/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -369,10 +359,7 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rs/cors v1.8.3 h1:O+qNyWn7Z+F9M0ILBHgMVPuB1xTOucVd5gtaYyXBpRo= -github.com/rs/cors v1.8.3/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo= github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -401,19 +388,13 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/unrolled/secure v1.13.0 h1:sdr3Phw2+f8Px8HE5sd1EHdj1aV3yUwed/uZXChLFsk= github.com/unrolled/secure v1.13.0/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= -github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= -github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= -github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= @@ -429,8 +410,6 @@ go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dY go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.4/go.mod h1:Ud+VUwIi9/uQHOMA+4ekToJ12lTxlv0zB/+DHwTGEbU= go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= -go.mongodb.org/mongo-driver v1.11.4 h1:4ayjakA013OdpGyL2K3ZqylTac/rMjrJOMZ1EHizXas= -go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.mongodb.org/mongo-driver v1.13.1 h1:YIc7HTYsKndGK4RFzJ3covLz1byri52x0IoMB0Pt/vk= go.mongodb.org/mongo-driver v1.13.1/go.mod h1:wcDf1JBCXy2mOW0bWHwO/IOYqdca1MPCwDtFu/Z9+eo= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -656,8 +635,6 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -673,8 +650,6 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -917,8 +892,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/telebot.v3 v3.1.3 h1:T+CTyOWpZMqp3ALHSweNgp1awQ9nMXdRAMpe/r6x9/s= -gopkg.in/telebot.v3 v3.1.3/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko= gopkg.in/telebot.v3 v3.2.1 h1:3I4LohaAyJBiivGmkfB+CiVu7QFOWkuZ4+KHgO/G3rs= gopkg.in/telebot.v3 v3.2.1/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index b636021..7994031 100644 --- a/main.go +++ b/main.go @@ -27,11 +27,11 @@ import ( "time" // Internals - "teknologi-umum-bot/analytics" - "teknologi-umum-bot/analytics/server" - "teknologi-umum-bot/cmd" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/underattack" + "teknologi-umum-captcha/analytics" + "teknologi-umum-captcha/analytics/server" + "teknologi-umum-captcha/cmd" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/underattack" // Database and cache "github.com/allegro/bigcache/v3" diff --git a/shared/error.go b/shared/error.go index 0d91390..9d45754 100644 --- a/shared/error.go +++ b/shared/error.go @@ -91,7 +91,7 @@ func HandleHttpError(ctx context.Context, e error, r *http.Request) { sentry.CaptureException(errors.WithStack(e)) return } - + scope := hub.Scope() scope.SetContext("http:request", map[string]interface{}{ "method": r.Method, diff --git a/underattack/handler.go b/underattack/handler.go index fc18b77..2c44b40 100644 --- a/underattack/handler.go +++ b/underattack/handler.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "teknologi-umum-bot/shared" - "teknologi-umum-bot/utils" + "teknologi-umum-captcha/shared" + "teknologi-umum-captcha/utils" "github.com/getsentry/sentry-go" tb "gopkg.in/telebot.v3" diff --git a/underattack/migration.go b/underattack/migration.go index 2198e8c..6360671 100644 --- a/underattack/migration.go +++ b/underattack/migration.go @@ -4,9 +4,10 @@ import ( "context" "database/sql" "errors" - "teknologi-umum-bot/shared" "time" + "teknologi-umum-captcha/shared" + "github.com/jmoiron/sqlx" ) diff --git a/underattack/ratelimiter_test.go b/underattack/ratelimiter_test.go index 3f2b8b8..77d9a12 100644 --- a/underattack/ratelimiter_test.go +++ b/underattack/ratelimiter_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "teknologi-umum-bot/underattack" + "teknologi-umum-captcha/underattack" ) func TestRateLimitCall(t *testing.T) { diff --git a/underattack/repo.go b/underattack/repo.go index 38e10d6..73f506a 100644 --- a/underattack/repo.go +++ b/underattack/repo.go @@ -4,9 +4,10 @@ import ( "context" "database/sql" "errors" - "github.com/getsentry/sentry-go" - "teknologi-umum-bot/shared" "time" + + "github.com/getsentry/sentry-go" + "teknologi-umum-captcha/shared" ) // GetUnderAttackEntry will acquire under attack entry for specified groupID. @@ -132,7 +133,7 @@ func (d *Dependency) CreateNewEntry(ctx context.Context, groupID int64) error { func (d *Dependency) SetUnderAttackStatus(ctx context.Context, groupID int64, underAttack bool, expiresAt time.Time, notificationMessageID int64) error { span := sentry.StartSpan(ctx, "underattack.set_under_attack_status") defer span.Finish() - + c, err := d.DB.Connx(ctx) if err != nil { return err diff --git a/underattack/underattack_test.go b/underattack/underattack_test.go index 055930b..ca05cdc 100644 --- a/underattack/underattack_test.go +++ b/underattack/underattack_test.go @@ -6,10 +6,11 @@ import ( "github.com/getsentry/sentry-go" "log" "os" - "teknologi-umum-bot/underattack" "testing" "time" + "teknologi-umum-captcha/underattack" + "github.com/allegro/bigcache/v3" "github.com/jmoiron/sqlx" "github.com/lib/pq" diff --git a/utils/array_test.go b/utils/array_test.go index 421d6c0..7b9b5a1 100644 --- a/utils/array_test.go +++ b/utils/array_test.go @@ -1,8 +1,9 @@ package utils_test import ( - "teknologi-umum-bot/utils" "testing" + + "teknologi-umum-captcha/utils" ) func TestIsIn(t *testing.T) { diff --git a/utils/ascii_test.go b/utils/ascii_test.go index b5182b8..58c4e4b 100644 --- a/utils/ascii_test.go +++ b/utils/ascii_test.go @@ -2,8 +2,9 @@ package utils_test import ( "strings" - "teknologi-umum-bot/utils" "testing" + + "teknologi-umum-captcha/utils" ) func TestGenerateAscii(t *testing.T) { diff --git a/utils/random_test.go b/utils/random_test.go index 9f7e872..0d19eec 100644 --- a/utils/random_test.go +++ b/utils/random_test.go @@ -1,8 +1,9 @@ package utils_test import ( - "teknologi-umum-bot/utils" "testing" + + "teknologi-umum-captcha/utils" ) func TestGenerateRandomNumber(t *testing.T) { diff --git a/utils/tele_test.go b/utils/tele_test.go index 9aaca12..1ddf77c 100644 --- a/utils/tele_test.go +++ b/utils/tele_test.go @@ -1,9 +1,10 @@ package utils_test import ( - "teknologi-umum-bot/utils" "testing" + "teknologi-umum-captcha/utils" + tb "gopkg.in/telebot.v3" )