From 113cfd7681201e0214f304bfd3444eea00923595 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Wed, 23 Oct 2024 01:37:20 +0000 Subject: [PATCH] feat: add meta for pixiv --- pixiv/pixiv.go | 6 +++++- telegram/command.go | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pixiv/pixiv.go b/pixiv/pixiv.go index 7e8b444..f1d3df1 100644 --- a/pixiv/pixiv.go +++ b/pixiv/pixiv.go @@ -61,7 +61,7 @@ func NewBot(cfg *Config, redisClient *redis.Client, logger *logrus.Logger) (*Bot } } - b.papp = pixiv.NewApp().WithTmpdir(cfg.TmpDir) + b.papp = pixiv.NewApp().WithTmpdir(cfg.TmpDir).WithClient(client).WithDownloadClient(downloadClient) return b, nil } @@ -145,6 +145,10 @@ func (b *Bot) StartFollow(ttl int, output chan uint64) { } } +func (b *Bot) Get(id uint64) (*pixiv.Illust, error) { + return b.papp.IllustDetail(id) +} + func (b *Bot) Download(id uint64) ([]int64, error) { fn := func(illust *pixiv.Illust) string { subdir := illust.CreateDate.Format("2006-01") diff --git a/telegram/command.go b/telegram/command.go index d8738fd..6694c54 100644 --- a/telegram/command.go +++ b/telegram/command.go @@ -128,6 +128,11 @@ func onPixivNoArgs(b *Bot, message *tgbotapi.Message) { b.logger.Errorf("parse pid from file name failed: %s", err) return } + illust, err := b.pixivBot.Get(pid) + if err != nil { + b.logger.Errorf("get pixiv illust failed: %s", err) + return + } mw := imagick.NewMagickWand() defer mw.Destroy() @@ -156,9 +161,15 @@ func onPixivNoArgs(b *Bot, message *tgbotapi.Message) { Bytes: blob, }) msg.ParseMode = tgbotapi.ModeHTML + tags := "" + for _, tag := range illust.Tags { + tags += fmt.Sprintf("#%s ", tag.Name) + } msg.Caption = fmt.Sprintf( - "pixiv:%d(%dx%d)", - pixiv.URLWithID(pid), pid, width, height, + "%s: %s\n%s", + pixiv.URLWithID(pid), + illust.User.Name, illust.Title, + tags, ) msg.ReplyMarkup = buildLikeButton(b.redis, "pixiv", filePath) msg.ReplyToMessageID = message.MessageID