From 3f11cad42f436845e8a21427c4d59d96acb083df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 6 Oct 2022 21:24:38 +0800 Subject: [PATCH] fix segv --- rule.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rule.go b/rule.go index 86eb747..4764f73 100644 --- a/rule.go +++ b/rule.go @@ -71,7 +71,17 @@ func init() { ), ), }, - File: tgba.FileID(ctx.Message.Chat.Photo.BigFileID), + File: func() tgba.RequestFileData { + if ctx.Message.Chat.Photo != nil { + return tgba.FileID(ctx.Message.Chat.Photo.BigFileID) + } + p, err := ctx.Caller.GetUserProfilePhotos(tgba.NewUserProfilePhotos(ctx.Message.From.ID)) + if err == nil && len(p.Photos) > 0 { + fp := p.Photos[0] + return tgba.FileID(fp[len(fp)-1].FileID) + } + return nil + }(), }, Caption: "主人, @" + ctx.Message.From.String() + " 请求响应~\n*ChatType*: " + ctx.Message.Chat.Type + "\n*ChatUserName*: " + ctx.Message.Chat.UserName + "\n*ChatID*: " + strconv.FormatInt(ctx.Message.Chat.ID, 10) + "\n*ChatTitle*: " + ctx.Message.Chat.Title + "\n*ChatDescription*: " + ctx.Message.Chat.Description, ParseMode: "Markdown",