Skip to content

Commit bd13948

Browse files
authored
Merge pull request #24 from libost/dev
Release 1.9.4
2 parents 2e1c200 + 6199aa3 commit bd13948

9 files changed

Lines changed: 90 additions & 6 deletions

File tree

.github/workflows/go.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ permissions:
3636

3737
jobs:
3838
release:
39-
name: Release
39+
name: Pre-Release
4040
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
4141
runs-on: ubuntu-latest
4242
steps:
@@ -51,7 +51,7 @@ jobs:
5151
go-version: "1.25.0"
5252

5353
- name: Delete existing dev release
54-
uses: andreaswilli/delete-release-assets-action@main
54+
uses: 8Mi-Tech/delete-release-assets-action@main
5555
with:
5656
github_token: ${{ secrets.GITHUB_TOKEN }}
5757
tag: "v0.0.0-dev"
@@ -75,6 +75,13 @@ jobs:
7575
git push -f origin "${DEV_TAG}"
7676
echo "DEV_TAG=${DEV_TAG}" >> $GITHUB_ENV
7777
78+
- name: Extract trigger commit message
79+
id: extract_commit
80+
run: |
81+
echo "TRIGGER_COMMIT_MSG<<EOF" >> $GITHUB_OUTPUT
82+
echo "${{ github.event.head_commit.message }}" >> $GITHUB_OUTPUT
83+
echo "EOF" >> $GITHUB_OUTPUT
84+
7885
- name: Run GoReleaser
7986
uses: goreleaser/goreleaser-action@v7
8087
with:
@@ -83,6 +90,7 @@ jobs:
8390
args: release --clean
8491
env:
8592
RELEASE_CHANNEL: dev
93+
COMMIT_MESSAGE: ${{ steps.extract_commit.outputs.TRIGGER_COMMIT_MSG }}
8694
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8795
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
8896
FEEDBACK: https://t.me/bangdream_feedback_bot

.github/workflows/release.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Auto Release
1+
name: Stable Release
22

33
on:
44
push:
@@ -33,4 +33,30 @@ jobs:
3333
RELEASE_CHANNEL: stable
3434
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3535
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
36-
FEEDBACK: https://t.me/bangdream_feedback_bot
36+
FEEDBACK: https://t.me/bangdream_feedback_bot
37+
sync-branches:
38+
name: Sync Branches
39+
needs: release
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v6
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Sync branches
48+
run: |
49+
git config user.name "GitHub Actions"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
52+
git fetch origin main dev
53+
git checkout dev
54+
55+
# Prefer fast-forward; if not possible, create a merge commit
56+
if git merge --ff-only origin/main; then
57+
echo "Fast-forwarded dev to main"
58+
else
59+
git merge --no-ff origin/main -m "chore: sync main into dev after stable release"
60+
fi
61+
62+
git push origin dev

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ announce:
120120
121121
{{ if eq .Env.RELEASE_CHANNEL "dev" }}🚀 {{ .ProjectName | mdv2escape }} 新测试版发行: {{ .ShortCommit | mdv2escape }}{{ else }}🎉 {{ .ProjectName | mdv2escape }} 新版本发行: {{ .Tag | mdv2escape }}{{ end }}
122122
123+
{{ if eq .Env.RELEASE_CHANNEL "dev" }}`{{ .ShortCommit | mdv2escape }}`: {{ .Env.COMMIT_MESSAGE | mdv2escape }}{{ end }}
124+
123125
[有问题点我反馈]({{ .Env.FEEDBACK | mdv2escape }})
124126
125127
[更新日志]({{ .ReleaseURL }})

callback/callback.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,44 @@ func removeZipFiles(zipPaths []string) {
182182
}
183183

184184
func GetPack(b *gotgbot.Bot, ctx *ext.Context, packName string, langCode string, msgId int64) error {
185+
currentUsage, err := database.Init("usage", ctx.EffectiveUser.Id, nil)
186+
if err != nil {
187+
return err
188+
}
189+
if !currentUsage["exists"].(bool) {
190+
database.Init("create", ctx.EffectiveUser.Id, nil)
191+
currentUsage["usage"] = float64(0)
192+
currentUsage["last_cycle_starts_at"] = float64(time.Now().Unix())
193+
}
194+
subErr := utils.SubscribeCheck(b, ctx, ctx.EffectiveUser.Id, langCode)
195+
if subErr != nil {
196+
return nil // 用户未订阅,已在 SubscribeCheck 中发送提示消息,直接返回不继续处理
197+
}
198+
limit := config.AppConfig.General.Limit
199+
userGroup, err := database.Init("user_group", ctx.EffectiveUser.Id, nil)
200+
if err != nil {
201+
return err
202+
}
203+
if userGroup["user_group"] == "sponsor" && config.AppConfig.Donation.BonusEnabled {
204+
limit = int(float64(config.AppConfig.General.Limit) * C.DonationBonusMultiplier) // 赞助用户的使用限制增加奖励倍数
205+
}
206+
if int(currentUsage["usage"].(float64)) >= limit && (int(currentUsage["last_cycle_starts_at"].(float64))+24*3600) >= int(time.Now().Unix()) {
207+
displayText := fmt.Sprintf(I.GetLocalisedString("general.out_of_quota", langCode), limit)
208+
if userGroup["user_group"] != "sponsor" && config.AppConfig.Donation.Enabled && config.AppConfig.Donation.BonusEnabled {
209+
displayText += I.GetLocalisedString("general.donate_reminder_outofquota", langCode)
210+
}
211+
if userGroup["user_group"] == "sponsor" && config.AppConfig.Donation.BonusEnabled {
212+
displayText += I.GetLocalisedString("general.donated", langCode)
213+
}
214+
_, _, _ = b.EditMessageText(displayText, &gotgbot.EditMessageTextOpts{
215+
ChatId: ctx.EffectiveChat.Id,
216+
MessageId: msgId,
217+
})
218+
err := C.ErrOutofQuota
219+
return err
220+
} else if (int(currentUsage["last_cycle_starts_at"].(float64)) + 24*3600) < int(time.Now().Unix()) {
221+
database.Init("reset_usage", ctx.EffectiveUser.Id, nil)
222+
}
185223
zipPaths, err := stickers.GetStickerPack(b, packName, ctx.EffectiveUser.Id, msgId, ctx)
186224
var limitErr *stickers.StickerPackLimitError
187225
if errors.As(err, &limitErr) {

commands/commands.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func start(b *gotgbot.Bot, ctx *ext.Context) error {
143143
}
144144
err = callback.GetPack(b, ctx, param, langCode, msg.GetMessageId())
145145
if err != nil {
146+
if errors.Is(err, S.ErrUserConversionInProgress) {
147+
return nil // 已在 callback.GetPack 中回复过转换中的消息,这里直接返回不再重复回复
148+
} else if errors.Is(err, C.ErrOutofQuota) {
149+
return nil // 已在 callback.GetPack 中回复过超出配额的消息,这里直接返回不再重复回复
150+
}
146151
log.Log(fmt.Sprintf("User %d failed to get sticker pack with parameter %s: %v", ctx.EffectiveUser.Id, param, err), C.LogLevelError)
147152
_, err = ctx.EffectiveMessage.Reply(b, I.GetLocalisedString("commands.get_desc_failed", langCode), nil)
148153
return err

config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ type Config struct {
6262
} `yaml:"donation,omitempty"`
6363
Misc struct {
6464
Timezone string `yaml:"timezone" default:"Asia/Shanghai"`
65-
//SelfUse bool `yaml:"self_use" default:"false"`
6665
} `yaml:"misc,omitempty"`
6766
}
6867

constants/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package constants
22

33
import (
4+
"errors"
45
"path/filepath"
56
"strings"
67
"time"
@@ -136,3 +137,7 @@ func CurrentTime(timezone string) (string, error) {
136137
}
137138
return time.Now().In(loc).Format("2006-01-02 15:04:05"), err
138139
}
140+
141+
var (
142+
ErrOutofQuota = errors.New("out of quota")
143+
)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func buildWebhookOptions(cfg *config.Config) (ext.WebhookOpts, *gotgbot.SetWebho
340340
DropPendingUpdates: true,
341341
}
342342

343-
if cfg.Webhook.NginxEnabled {
343+
if cfg.Webhook.NginxEnabled && os.Getenv("IN_DOCKER") != "true" {
344344
webhookOpts.ListenAddr = fmt.Sprintf("127.0.0.1:%d", cfg.Webhook.Port)
345345
return webhookOpts, setWebhookOpts
346346
}

stickers/stickers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func stickerHandler(b *gotgbot.Bot, ctx *ext.Context) error {
6363
if !currentUsage["exists"].(bool) {
6464
database.Init("create", ctx.EffectiveUser.Id, nil)
6565
currentUsage["usage"] = float64(0)
66+
currentUsage["last_cycle_starts_at"] = float64(time.Now().Unix())
6667
}
6768
langCode := I.LangCodePrefer(ctx.EffectiveUser.Id, ctx.EffectiveUser.LanguageCode)
6869
subErr := utils.SubscribeCheck(b, ctx, ctx.EffectiveUser.Id, langCode)

0 commit comments

Comments
 (0)