Skip to content

Commit 3c190f2

Browse files
committed
chore: Handle missing artwork in getPictureFile function and update help text
1 parent df7dc0f commit 3c190f2

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

bot/handlers_common.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ func start(ctx context.Context, bot *telego.Bot, message telego.Message) {
4646

4747
func help(ctx context.Context, bot *telego.Bot, message telego.Message) {
4848
helpText := `使用方法:
49-
/start - 喵喵喵
5049
/file - 回复一条频道的消息获取原图文件 <index>
51-
/setu - 随机图片 <keyword1> <keyword2> ...
52-
/random - 也是随机图片 <keyword1> <keyword2> ...
50+
/setu - 随机图片(NSFW)
51+
/random - 随机全年龄图片
5352
/search - 搜索相似图片
53+
54+
关键词参数使用 '|' 分隔或关系, 使用空格分隔与关系, 示例:
55+
56+
/random 萝莉|白丝 猫耳|原创
57+
58+
表示搜索包含"萝莉"或"白丝", 且包含"猫耳"或"原创"的图片.
59+
Inline 查询支持同样的参数格式.
60+
5461
`
5562
isAdmin, _ := service.IsAdmin(ctx, message.From.ID)
5663
if isAdmin {
@@ -82,11 +89,16 @@ func getPictureFile(ctx context.Context, bot *telego.Bot, message telego.Message
8289
if err == nil && index > 0 {
8390
artwork, err := service.GetArtworkByMessageID(ctx, pictureMessageID)
8491
if err != nil {
85-
telegram.ReplyMessage(bot, message, "获取失败: "+err.Error())
92+
if errors.Is(err, mongo.ErrNoDocuments) {
93+
telegram.ReplyMessage(bot, message, "这张图片未在数据库中呢")
94+
return
95+
}
96+
Logger.Errorf("获取作品失败: %s", err)
97+
telegram.ReplyMessage(bot, message, "获取失败, 去找管理员反馈吧~")
8698
return
8799
}
88100
if index > len(artwork.Pictures) {
89-
telegram.ReplyMessage(bot, message, "这个作品没有这么多图片哦")
101+
telegram.ReplyMessage(bot, message, "这个作品没有这么多图片")
90102
return
91103
}
92104
picture := artwork.Pictures[index-1]
@@ -95,14 +107,14 @@ func getPictureFile(ctx context.Context, bot *telego.Bot, message telego.Message
95107
}
96108
_, err := telegram.SendPictureFileByMessageID(ctx, bot, message, pictureMessageID)
97109
if err != nil {
98-
telegram.ReplyMessage(bot, message, "获取失败: "+err.Error())
110+
telegram.ReplyMessage(bot, message, "图片发送失败: "+err.Error())
99111
return
100112
}
101113
}
102114

103115
func randomPicture(ctx context.Context, bot *telego.Bot, message telego.Message) {
104116
cmd, _, args := telegoutil.ParseCommand(message.Text)
105-
argText := strings.Join(args, " ")
117+
argText := strings.ReplaceAll(strings.Join(args, " "), "\\", "")
106118
textArray, err := common.ParseStringTo2DArray(argText, "|", " ")
107119
if err != nil {
108120
Logger.Warnf("解析参数失败: %s", err)

cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
Version string = "0.6.3"
10+
Version string = "0.6.4"
1111
)
1212

1313
var VersionCmd = &cobra.Command{

0 commit comments

Comments
 (0)