diff --git a/.forgejo/workflows/bake.yml b/.forgejo/workflows/bake.yml new file mode 100644 index 0000000..60611ba --- /dev/null +++ b/.forgejo/workflows/bake.yml @@ -0,0 +1,55 @@ +on: + push: + branches: + - 'ci-test' + tags: + - 'v*' + paths: + - '**.go' + - '**.html' + - 'Dockerfile' + - 'Dockerfile.*' + - 'docker-bake.hcl' + - '.forgejo/workflows/*.yml' + workflow_dispatch: + +jobs: + bake: + runs-on: docker + steps: + - name: Prepare Registry FQDN + id: registry + run: | + registry=${{ github.server_url }} + registry=${registry##http*://} + echo "registry=${registry}" >> "$GITHUB_OUTPUT" + + - name: Login to Container Registry + uses: https://code.forgejo.org/docker/login-action@v3 + with: + registry: ${{ steps.registry.outputs.registry }} + username: ${{ github.repository_owner }} + password: ${{ secrets.TOKEN }} + + - name: Checkout + uses: https://code.forgejo.org/actions/checkout@v4 + + - name: Set up Docker Buildx + uses: https://code.forgejo.org/docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: https://code.forgejo.org/docker/metadata-action@v5 + with: + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Build and push + uses: https://code.forgejo.org/docker/bake-action@v6 + with: + source: . + env: + TAG: ${{ steps.meta.outputs.tags }} diff --git a/cmd/tweeter/webhook.go b/cmd/tweeter/webhook.go index 0c69601..7995371 100644 --- a/cmd/tweeter/webhook.go +++ b/cmd/tweeter/webhook.go @@ -3,6 +3,7 @@ package tweeter import ( "bytes" "encoding/json" + "html" "log" "net/http" "strings" @@ -80,7 +81,7 @@ func (app App) SendToWebhook(tweets []*ts.Tweet) { tweetText = strings.ReplaceAll(tweetText, video.URL, "") } - mainEmbed.SetText(strings.TrimSpace(tweetText)) + mainEmbed.SetText(html.UnescapeString(strings.TrimSpace(tweetText))) for _, data := range webhooksToSend { err := sendRequest(app.config.Webhook, data) diff --git a/config.example.toml b/config.example.toml index 36f09a9..fdcd679 100644 --- a/config.example.toml +++ b/config.example.toml @@ -1,13 +1,19 @@ username = "" password = "asd123" #proxyaddr = "socks5://localhost:5555" -hostURL = "https://my.domain.tld" + +#usewebserver = false +indextarget = "https://discord.gg/Kw4MFGxYEj" # Optional +hostURL = "https://my.domain.tld" # Can be omitted if not using webserver + webhook = "https://domain.tld/api/webhooks/" + channels = [ "NinEverything", "NintendoEurope", "NintendoAmerica", ] + # Binary representation for efficient filtering # Bit from left to right (most to least significant bit): IsSelfThread, IsRetweet, IsReply, IsPin, IsQuoted filter = [ diff --git a/docker-bake.hcl b/docker-bake.hcl index e18ac8c..0af347b 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -8,8 +8,8 @@ variable "TAG" { function "generate_tags" { params = [images, versions] result = distinct(flatten( - [for i in split(",", images) : - [for v in split(",", versions) : + [for i in split(",", replace(images, "\n", ",")) : + [for v in split(",", replace(versions, "\n", ",")) : "${i}:${v}" ] ])) diff --git a/pkg/config/config.go b/pkg/config/config.go index dd540fb..499badb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -20,6 +20,7 @@ type Config struct { WebPort uint16 UserAgents []string NitterBase string + IndexTarget string } func ConfigFromFile(filePath string) (*Config, error) { diff --git a/pkg/web/web.go b/pkg/web/web.go index 11b99f1..a8b5a5a 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -72,12 +72,19 @@ func New(config *config.Config, scraper *ts.Scraper) (*WebServer, error) { WriteTimeout: 30 * time.Second, }, } + sm.HandleFunc("GET /", ws.handleIndex) sm.HandleFunc("GET /avatar/{username}", ws.handleAvatar) sm.HandleFunc("GET /tweet/{id}", ws.handleTweet) sm.HandleFunc("GET /video/{id}", ws.handleVideo) return ws, nil } +func (ws WebServer) handleIndex(w http.ResponseWriter, r *http.Request) { + if ws.config.IndexTarget != "" { + http.Redirect(w, r, ws.config.IndexTarget, http.StatusPermanentRedirect) + } +} + func (ws WebServer) handleAvatar(w http.ResponseWriter, r *http.Request) { username := r.PathValue("username")