From 6f7fff5aabfc368bdc90c3c995343cb4a3df783c Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Thu, 1 Oct 2026 18:45:08 +0700 Subject: [PATCH] feat(random): send /gachabeta clips as 360x640 portrait animations Each gacha style now carries the frame size it renders, so Telegram receives the beta wish's portrait size while /gacha stays 640x360. --- docs/deploy-coolify-selfhosted.md | 4 ++-- internal/modules/random/gacha_api_client.go | 14 +++++++++----- internal/modules/random/gacha_command_test.go | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/deploy-coolify-selfhosted.md b/docs/deploy-coolify-selfhosted.md index 77901d8..b810387 100644 --- a/docs/deploy-coolify-selfhosted.md +++ b/docs/deploy-coolify-selfhosted.md @@ -94,8 +94,8 @@ animation and reply show. Options are 5★ by default; prefix `4*` or `3*` to lower one, e.g. `/gacha Pizza, 4* Pho, 3* Rice`. The unlisted `/gachabeta` takes the same input and renders the beta version -of the wish from `.../api/gachabeta` on the same service, with the same text -fallback. +of the wish from `.../api/gachabeta` on the same service as a `360x640` +portrait MP4, with the same text fallback. ## 1. MongoDB Atlas (M0) diff --git a/internal/modules/random/gacha_api_client.go b/internal/modules/random/gacha_api_client.go index f4eb21f..4437abc 100644 --- a/internal/modules/random/gacha_api_client.go +++ b/internal/modules/random/gacha_api_client.go @@ -16,15 +16,19 @@ const ( ) // gachaStyle is one wish animation the renderer serves: its path next to -// /api/gif and the clip length in seconds. +// /api/gif, the clip length in seconds, and the frame size it renders for a +// gachaRemoteWidth request. type gachaStyle struct { Path string Duration int + Width int + Height int } var ( - gachaStyleWish = gachaStyle{Path: "gacha", Duration: 7} - gachaStyleBeta = gachaStyle{Path: "gachabeta", Duration: 6} + gachaStyleWish = gachaStyle{Path: "gacha", Duration: 7, Width: gachaRemoteWidth, Height: gachaRemoteHeight} + // The beta wish is portrait: the requested width is its long edge. + gachaStyleBeta = gachaStyle{Path: "gachabeta", Duration: 6, Width: gachaRemoteHeight, Height: gachaRemoteWidth} ) type gachaAPIRequest struct { @@ -87,7 +91,7 @@ func renderGachaAnimation(ctx context.Context, style gachaStyle, label string, r return wheelAnimation{ Data: data, Duration: style.Duration, - Width: gachaRemoteWidth, - Height: gachaRemoteHeight, + Width: style.Width, + Height: style.Height, }, nil } diff --git a/internal/modules/random/gacha_command_test.go b/internal/modules/random/gacha_command_test.go index 2f9c306..3b64e67 100644 --- a/internal/modules/random/gacha_command_test.go +++ b/internal/modules/random/gacha_command_test.go @@ -208,8 +208,10 @@ func TestGachaBeta_UsesBetaRendererAndAnyoneCanRunIt(t *testing.T) { if animation == nil { t.Fatalf("calls = %+v, want a sendAnimation", rb.Sent()) } - if got := animation.Form["duration"]; got != "6" { - t.Fatalf("duration = %q, want 6", got) + for field, want := range map[string]string{"duration": "6", "width": "360", "height": "640"} { + if got := animation.Form[field]; got != want { + t.Fatalf("%s = %q, want %s", field, got, want) + } } }