package plugins

import (
	"kurumibot/database/psql"

	"kurumibot/laniakea"
)

func RegisterAdmin(b *laniakea.Bot) {
	p := laniakea.NewPlugin("Admin")
	p = p.Command(uploadPhoto, "uploadPhoto")

	b.AddPlugins(p.Build())
}

func uploadPhoto(msgContext *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
	user, err := psql.GetOrCreateUser(msgContext.FromID, msgContext.Msg.From.FirstName)
	if err != nil {
		msgContext.Error(err)
		return
	}
	if !user.Group.IsAdmin {
		return
	}

	photoId := msgContext.Msg.Photo[0].FileID
	msgContext.AnswerPhoto(photoId, photoId)
}
