many fixes

This commit is contained in:
2026-02-03 16:41:53 +03:00
parent d6590680e2
commit 8126be0c8b
7 changed files with 121 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ package plugins
import (
"kurumibot/database/psql"
"log"
"git.nix13.pw/scuroneko/laniakea"
)
@@ -12,17 +13,36 @@ func RegisterAdmin(b *laniakea.Bot) {
b.AddPlugins(p.Build())
}
func uploadPhoto(msgContext *laniakea.MsgContext, db *laniakea.DatabaseContext) {
func uploadPhoto(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
rep := psql.NewUserRepository(db)
user, err := rep.GetOrCreate(msgContext.FromID, msgContext.Msg.From.FirstName)
user, err := rep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
if err != nil {
msgContext.Error(err)
ctx.Error(err)
return
}
if !user.Group.IsAdmin {
return
}
photoId := msgContext.Msg.Photo[0].FileID
msgContext.AnswerPhoto(photoId, photoId)
// https://core.telegram.org/bots/api#getfile
log.Println(ctx.Msg.Photo[0])
photoId := ctx.Msg.Photo[0].FileID
f, err := ctx.Bot.GetFile(&laniakea.GetFileP{FileId: photoId})
if err != nil {
ctx.Error(err)
return
}
u := laniakea.NewUploader(ctx.Bot)
content, err := ctx.Bot.GetFileByLink(f.FilePath)
if err != nil {
ctx.Error(err)
return
}
err = u.UploadPhoto(ctx.Msg.Chat.ID, content)
if err != nil {
ctx.Error(err)
return
}
log.Println(*f)
ctx.AnswerPhoto(photoId, laniakea.EscapeMarkdown(photoId))
}