Skip to content

Commit

Permalink
新增「单次下载数量的限制」
Browse files Browse the repository at this point in the history
  • Loading branch information
rroy233 committed Jan 21, 2024
1 parent 0de5055 commit 49163d5
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 32 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ general:
process_wait_queue_max_size: 50 # 等待队列最大长度
process_timeout: 60 # 处理超时时间(s)
support_tgs_file: false # 是否开启tgs表情支持
max_amount_per_req: 100 # 下载整套表情包时允许的最大数量
cache:
enabled: false # 是否启用文件缓存(需要使用Redis)
Expand Down Expand Up @@ -136,4 +137,4 @@ bash ./run.sh
```

### LICENSE
GPL-3.0 license
GPL-3.0 license
1 change: 1 addition & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ general:
process_wait_queue_max_size: 50 # Maximum length of the wait queue
process_timeout: 60 # Processing timeout (s)
support_tgs_file: false # Whether to enable tgs stickers support
max_amount_per_req: 100 # Maximum number of stickers allowed when downloading the whole set
cache:
enabled: false # Whether to enable file caching (requires Redis)
Expand Down
3 changes: 2 additions & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ general:
process_wait_queue_max_size: 50
process_timeout: 60
support_tgs_file: false
max_amount_per_req: 100

cache:
enabled: false
Expand All @@ -26,4 +27,4 @@ redis:
port: "6379"
tls: false
password: ""
db: 0
db: 0
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Config struct {
ProcessWaitQueueMaxSize int `yaml:"process_wait_queue_max_size"`
ProcessTimeout int `yaml:"process_timeout"`
SupportTGSFile bool `yaml:"support_tgs_file"`
MaxAmountPerReq int `yaml:"max_amount_per_req"`
} `yaml:"general"`
Cache struct {
Enabled bool `yaml:"enabled"`
Expand Down Expand Up @@ -57,6 +58,11 @@ func Init() {
if err != nil {
log.Fatalln("failed to parse config.yaml", err)
}

//validate config
if cf.General.MaxAmountPerReq == 0 {
log.Fatalln("General.MaxAmountPerReq should NOT be 0")
}
}

func Get() *Config {
Expand Down
8 changes: 8 additions & 0 deletions handler/DownloadStickerSetQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func DownloadStickerSetQuery(update tgbotapi.Update) {
return
}

//check amount of this sticker set
//compare with max_amount_per_req
if len(stickerSet.Stickers) > config.Get().General.MaxAmountPerReq {
logger.Info.Println(userInfo + "DownloadStickerSetQuery- amount > max_amount_per_req")
utils.CallBackWithAlert(update.CallbackQuery.ID, languages.Get(&update).BotMsg.ErrStickerSetAmountReachLimit)
return
}

//remove old msg to prevent frequent request
if time.Now().Unix()-int64(update.CallbackQuery.Message.Date) < 48*Hour {
utils.DeleteMsg(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID)
Expand Down
5 changes: 3 additions & 2 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"bot_msg": {
"processing": "Processing...",
"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.",
"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.",
"downloading_with_progress": "Downloading[%d/%d]...",
"uploaded_third_party": "Success!!\nSticker Name:%s\nSize:%s\nDownload:%s\n",
"uploaded_telegram": "Success!!\nSticker Name:%s\nSize:%dMB\n",
Expand All @@ -34,6 +34,7 @@
"err_upload_failed": "Failed to upload!!!",
"err_sticker_not_support": "Sticker not support!",
"err_convert_failed": "Failed to convert!!",
"err_send_file_failed": "Failed to send file!!!"
"err_send_file_failed": "Failed to send file!!!",
"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."
}
}
55 changes: 28 additions & 27 deletions languages/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,34 @@ type LanguageStruct struct {
RlottieNotExist string `json:"rlottie_not_exist"`
} `json:"system"`
BotMsg struct {
Processing string `json:"processing"`
StickersSetInfoFromUrl string `json:"stickers_set_info_from_url"`
DownloadingWithProgress string `json:"downloading_with_progress"`
UploadedThirdParty string `json:"uploaded_third_party"`
UploadedTelegram string `json:"uploaded_telegram"`
GetLimitCommand string `json:"get_limit_command"`
StartCommand string `json:"start_command"`
HelpCommand string `json:"help_command"`
ConvertCompleted string `json:"convert_completed"`
ConvertedWaitingUpload string `json:"converted_waiting_upload"`
DownloadStickerSet string `json:"download_sticker_set"`
ReloadConfigSuccess string `json:"reload_config_success"`
QueueAbortBtn string `json:"queue_abort_btn"`
QueueAborted string `json:"queue_aborted"`
QueueProcess string `json:"queue_process"`
ErrRateReachLimit string `json:"err_rate_reach_limit"`
ErrSysBusy string `json:"err_sys_busy"`
ErrNoPermission string `json:"err_no_permission"`
ErrReachLimit string `json:"err_reach_limit"`
ErrFailedToDownload string `json:"err_failed_to_download"`
ErrSysFailureOccurred string `json:"err_sys_failure_occurred"`
ErrFailed string `json:"err_failed"`
ErrTimeout string `json:"err_timeout"`
ErrUploadFailed string `json:"err_upload_failed"`
ErrStickerNotSupport string `json:"err_sticker_not_support"`
ErrConvertFailed string `json:"err_convert_failed"`
ErrSendFileFailed string `json:"err_send_file_failed"`
Processing string `json:"processing"`
StickersSetInfoFromUrl string `json:"stickers_set_info_from_url"`
DownloadingWithProgress string `json:"downloading_with_progress"`
UploadedThirdParty string `json:"uploaded_third_party"`
UploadedTelegram string `json:"uploaded_telegram"`
GetLimitCommand string `json:"get_limit_command"`
StartCommand string `json:"start_command"`
HelpCommand string `json:"help_command"`
ConvertCompleted string `json:"convert_completed"`
ConvertedWaitingUpload string `json:"converted_waiting_upload"`
DownloadStickerSet string `json:"download_sticker_set"`
ReloadConfigSuccess string `json:"reload_config_success"`
QueueAbortBtn string `json:"queue_abort_btn"`
QueueAborted string `json:"queue_aborted"`
QueueProcess string `json:"queue_process"`
ErrRateReachLimit string `json:"err_rate_reach_limit"`
ErrSysBusy string `json:"err_sys_busy"`
ErrNoPermission string `json:"err_no_permission"`
ErrReachLimit string `json:"err_reach_limit"`
ErrFailedToDownload string `json:"err_failed_to_download"`
ErrSysFailureOccurred string `json:"err_sys_failure_occurred"`
ErrFailed string `json:"err_failed"`
ErrTimeout string `json:"err_timeout"`
ErrUploadFailed string `json:"err_upload_failed"`
ErrStickerNotSupport string `json:"err_sticker_not_support"`
ErrConvertFailed string `json:"err_convert_failed"`
ErrSendFileFailed string `json:"err_send_file_failed"`
ErrStickerSetAmountReachLimit string `json:"err_sticker_set_amount_reach_limit"`
} `json:"bot_msg"`
}

Expand Down
3 changes: 2 additions & 1 deletion languages/zh-hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"err_upload_failed": "上传失败!!!",
"err_sticker_not_support": "该表情不支持下载",
"err_convert_failed": "转换文件失败",
"err_send_file_failed": "发送文件失败"
"err_send_file_failed": "发送文件失败",
"err_sticker_set_amount_reach_limit": "该表情包包含的表情数量过多,请单独发送表情或使用自行部署的版本"
}
}

0 comments on commit 49163d5

Please sign in to comment.