49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package plugins
|
|
|
|
import (
|
|
"kurumibot/database/psql"
|
|
"log"
|
|
|
|
"git.nix13.pw/scuroneko/laniakea"
|
|
)
|
|
|
|
func RegisterAdmin(b *laniakea.Bot) {
|
|
p := laniakea.NewPlugin("Admin")
|
|
p = p.Command(uploadPhoto, "uploadPhoto")
|
|
b.AddPlugins(p.Build())
|
|
}
|
|
|
|
func uploadPhoto(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|
rep := psql.NewUserRepository(db)
|
|
user, err := rep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
|
|
if err != nil {
|
|
ctx.Error(err)
|
|
return
|
|
}
|
|
if !user.Group.IsAdmin {
|
|
return
|
|
}
|
|
|
|
// 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))
|
|
}
|