package plugins import ( "kurumibot/database/psql" "path/filepath" "git.nix13.pw/scuroneko/laniakea" "git.nix13.pw/scuroneko/laniakea/tgapi" "git.nix13.pw/scuroneko/laniakea/utils" ) func RegisterAdmin(b *laniakea.Bot) { p := laniakea.NewPlugin("Admin") p.Command(uploadPhoto, "uploadPhoto") p.Command(emojiId, "emojiId") p.Command(getProxy, "proxy") p.Command(test, "test") p.AddMiddleware(AdminMiddleware()) b.AddPlugins(p.Build()) } func AdminMiddleware() *laniakea.PluginMiddleware { m := laniakea.NewPluginMiddleware(func(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) bool { rep := psql.NewUserRepository(db) u, err := rep.GetById(ctx.FromID) if err != nil { return false } return u.Group.IsAdmin }) return m } func test(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) { ctx.Answer("Ok") } func getProxy(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) { ruProxy := "tg://proxy?port=3128&secret=7qaZyfQN-IQ7ZMwrR_zWnHBvem9uLnJ1&server=185.231.245.25" fiProxy := "tg://proxy?port=3128&secret=7vmNtw_233xvIRFvImm2PLtvem9uLnJ1&server=46.243.6.125" kb := laniakea.NewInlineKeyboard(1) kb.AddUrlButtonStyle("🇷🇺Russia", laniakea.ButtonStylePrimary, ruProxy) kb.AddUrlButtonStyle("🇫🇮Finland", laniakea.ButtonStylePrimary, fiProxy) ctx.Keyboard("Доступные прокси", kb) } func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) { var id string for _, e := range ctx.Msg.Entities { if e.Type != tgapi.MessageEntityCustomEmoji { continue } id = e.CustomEmojiID break } ctx.Answer(id) } func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) { ctx.SendAction(tgapi.ChatActionUploadPhoto) photoId := ctx.Msg.Photo.Last().FileID f, err := ctx.Api.GetFile(tgapi.GetFileP{FileId: photoId}) if err != nil { ctx.Error(err) return } u := tgapi.NewUploader(ctx.Api) defer u.Close() content, err := ctx.Bot.GetFileByLink(f.FilePath) if err != nil { ctx.Error(err) return } filename := filepath.Base(f.FilePath) msg, err := u.UploadPhoto(tgapi.UploadPhotoP{ ChatID: ctx.Msg.Chat.ID, Caption: ctx.Msg.Caption, }, tgapi.NewUploaderFile(filename, content)) if err != nil { ctx.Error(err) return } ctx.Answer(utils.EscapeMarkdown(msg.Photo.Last().FileID)) }