Skip to content

Commit

Permalink
feat: add meta for pixiv
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Oct 23, 2024
1 parent 15da1cc commit 113cfd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pixiv/pixiv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
Expand Down
15 changes: 13 additions & 2 deletions telegram/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
"<a href=\"%s\">pixiv:%d</a>(%dx%d)",
pixiv.URLWithID(pid), pid, width, height,
"<a href=\"%s\">%s: %s</a>\n%s",
pixiv.URLWithID(pid),
illust.User.Name, illust.Title,
tags,
)
msg.ReplyMarkup = buildLikeButton(b.redis, "pixiv", filePath)
msg.ReplyToMessageID = message.MessageID
Expand Down

0 comments on commit 113cfd7

Please sign in to comment.