Skip to content

Commit 49163d5

Browse files
committed
新增「单次下载数量的限制」
1 parent 0de5055 commit 49163d5

File tree

8 files changed

+52
-32
lines changed

8 files changed

+52
-32
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ general:
8787
process_wait_queue_max_size: 50 # 等待队列最大长度
8888
process_timeout: 60 # 处理超时时间(s)
8989
support_tgs_file: false # 是否开启tgs表情支持
90+
max_amount_per_req: 100 # 下载整套表情包时允许的最大数量
9091
9192
cache:
9293
enabled: false # 是否启用文件缓存(需要使用Redis)
@@ -136,4 +137,4 @@ bash ./run.sh
136137
```
137138

138139
### LICENSE
139-
GPL-3.0 license
140+
GPL-3.0 license

README_en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ general:
8787
process_wait_queue_max_size: 50 # Maximum length of the wait queue
8888
process_timeout: 60 # Processing timeout (s)
8989
support_tgs_file: false # Whether to enable tgs stickers support
90+
max_amount_per_req: 100 # Maximum number of stickers allowed when downloading the whole set
9091
9192
cache:
9293
enabled: false # Whether to enable file caching (requires Redis)

config.example.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ general:
88
process_wait_queue_max_size: 50
99
process_timeout: 60
1010
support_tgs_file: false
11+
max_amount_per_req: 100
1112

1213
cache:
1314
enabled: false
@@ -26,4 +27,4 @@ redis:
2627
port: "6379"
2728
tls: false
2829
password: ""
29-
db: 0
30+
db: 0

config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Config struct {
1919
ProcessWaitQueueMaxSize int `yaml:"process_wait_queue_max_size"`
2020
ProcessTimeout int `yaml:"process_timeout"`
2121
SupportTGSFile bool `yaml:"support_tgs_file"`
22+
MaxAmountPerReq int `yaml:"max_amount_per_req"`
2223
} `yaml:"general"`
2324
Cache struct {
2425
Enabled bool `yaml:"enabled"`
@@ -57,6 +58,11 @@ func Init() {
5758
if err != nil {
5859
log.Fatalln("failed to parse config.yaml", err)
5960
}
61+
62+
//validate config
63+
if cf.General.MaxAmountPerReq == 0 {
64+
log.Fatalln("General.MaxAmountPerReq should NOT be 0")
65+
}
6066
}
6167

6268
func Get() *Config {

handler/DownloadStickerSetQuery.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ func DownloadStickerSetQuery(update tgbotapi.Update) {
4343
return
4444
}
4545

46+
//check amount of this sticker set
47+
//compare with max_amount_per_req
48+
if len(stickerSet.Stickers) > config.Get().General.MaxAmountPerReq {
49+
logger.Info.Println(userInfo + "DownloadStickerSetQuery- amount > max_amount_per_req")
50+
utils.CallBackWithAlert(update.CallbackQuery.ID, languages.Get(&update).BotMsg.ErrStickerSetAmountReachLimit)
51+
return
52+
}
53+
4654
//remove old msg to prevent frequent request
4755
if time.Now().Unix()-int64(update.CallbackQuery.Message.Date) < 48*Hour {
4856
utils.DeleteMsg(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID)

languages/en.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"bot_msg": {
1111
"processing": "Processing...",
12-
"stickers_set_info_from_url": "Sticker Name:%s\nCount:%d\n\nTo ddownload the full set of stickers, click the button below。\nIf you want to download some of them, please send them directly.",
12+
"stickers_set_info_from_url": "Sticker Name:%s\nCount:%d\n\nTo download the full set of stickers, click the button below。\nIf you want to download some of them, please send them directly.",
1313
"downloading_with_progress": "Downloading[%d/%d]...",
1414
"uploaded_third_party": "Success!!\nSticker Name:%s\nSize:%s\nDownload:%s\n",
1515
"uploaded_telegram": "Success!!\nSticker Name:%s\nSize:%dMB\n",
@@ -34,6 +34,7 @@
3434
"err_upload_failed": "Failed to upload!!!",
3535
"err_sticker_not_support": "Sticker not support!",
3636
"err_convert_failed": "Failed to convert!!",
37-
"err_send_file_failed": "Failed to send file!!!"
37+
"err_send_file_failed": "Failed to send file!!!",
38+
"err_sticker_set_amount_reach_limit": "This sticker set contains more stickers than allowed limit. Please send it separately or use a self-deployed version."
3839
}
3940
}

languages/language.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,34 @@ type LanguageStruct struct {
2020
RlottieNotExist string `json:"rlottie_not_exist"`
2121
} `json:"system"`
2222
BotMsg struct {
23-
Processing string `json:"processing"`
24-
StickersSetInfoFromUrl string `json:"stickers_set_info_from_url"`
25-
DownloadingWithProgress string `json:"downloading_with_progress"`
26-
UploadedThirdParty string `json:"uploaded_third_party"`
27-
UploadedTelegram string `json:"uploaded_telegram"`
28-
GetLimitCommand string `json:"get_limit_command"`
29-
StartCommand string `json:"start_command"`
30-
HelpCommand string `json:"help_command"`
31-
ConvertCompleted string `json:"convert_completed"`
32-
ConvertedWaitingUpload string `json:"converted_waiting_upload"`
33-
DownloadStickerSet string `json:"download_sticker_set"`
34-
ReloadConfigSuccess string `json:"reload_config_success"`
35-
QueueAbortBtn string `json:"queue_abort_btn"`
36-
QueueAborted string `json:"queue_aborted"`
37-
QueueProcess string `json:"queue_process"`
38-
ErrRateReachLimit string `json:"err_rate_reach_limit"`
39-
ErrSysBusy string `json:"err_sys_busy"`
40-
ErrNoPermission string `json:"err_no_permission"`
41-
ErrReachLimit string `json:"err_reach_limit"`
42-
ErrFailedToDownload string `json:"err_failed_to_download"`
43-
ErrSysFailureOccurred string `json:"err_sys_failure_occurred"`
44-
ErrFailed string `json:"err_failed"`
45-
ErrTimeout string `json:"err_timeout"`
46-
ErrUploadFailed string `json:"err_upload_failed"`
47-
ErrStickerNotSupport string `json:"err_sticker_not_support"`
48-
ErrConvertFailed string `json:"err_convert_failed"`
49-
ErrSendFileFailed string `json:"err_send_file_failed"`
23+
Processing string `json:"processing"`
24+
StickersSetInfoFromUrl string `json:"stickers_set_info_from_url"`
25+
DownloadingWithProgress string `json:"downloading_with_progress"`
26+
UploadedThirdParty string `json:"uploaded_third_party"`
27+
UploadedTelegram string `json:"uploaded_telegram"`
28+
GetLimitCommand string `json:"get_limit_command"`
29+
StartCommand string `json:"start_command"`
30+
HelpCommand string `json:"help_command"`
31+
ConvertCompleted string `json:"convert_completed"`
32+
ConvertedWaitingUpload string `json:"converted_waiting_upload"`
33+
DownloadStickerSet string `json:"download_sticker_set"`
34+
ReloadConfigSuccess string `json:"reload_config_success"`
35+
QueueAbortBtn string `json:"queue_abort_btn"`
36+
QueueAborted string `json:"queue_aborted"`
37+
QueueProcess string `json:"queue_process"`
38+
ErrRateReachLimit string `json:"err_rate_reach_limit"`
39+
ErrSysBusy string `json:"err_sys_busy"`
40+
ErrNoPermission string `json:"err_no_permission"`
41+
ErrReachLimit string `json:"err_reach_limit"`
42+
ErrFailedToDownload string `json:"err_failed_to_download"`
43+
ErrSysFailureOccurred string `json:"err_sys_failure_occurred"`
44+
ErrFailed string `json:"err_failed"`
45+
ErrTimeout string `json:"err_timeout"`
46+
ErrUploadFailed string `json:"err_upload_failed"`
47+
ErrStickerNotSupport string `json:"err_sticker_not_support"`
48+
ErrConvertFailed string `json:"err_convert_failed"`
49+
ErrSendFileFailed string `json:"err_send_file_failed"`
50+
ErrStickerSetAmountReachLimit string `json:"err_sticker_set_amount_reach_limit"`
5051
} `json:"bot_msg"`
5152
}
5253

languages/zh-hans.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"err_upload_failed": "上传失败!!!",
3535
"err_sticker_not_support": "该表情不支持下载",
3636
"err_convert_failed": "转换文件失败",
37-
"err_send_file_failed": "发送文件失败"
37+
"err_send_file_failed": "发送文件失败",
38+
"err_sticker_set_amount_reach_limit": "该表情包包含的表情数量过多,请单独发送表情或使用自行部署的版本"
3839
}
3940
}

0 commit comments

Comments
 (0)