many fixes
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user