From 24fa86f4c99486d46394e372b978308e49fd859f Mon Sep 17 00:00:00 2001 From: nefrace Date: Fri, 20 Jan 2023 16:32:21 +0300 Subject: [PATCH] Testing state --- main.go | 3 ++- states.go | 36 +++++++++++++++++++++++++++++++++--- types.go | 14 ++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 types.go diff --git a/main.go b/main.go index f47ed0d..5b03d2c 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( ) func main() { - neko := nechotron.NewTron("1698825178:AAHy4Er7z768CmYy9M5drJOMQO2S-QnwdTI", nil) + neko := nechotron.NewTron("1698825178:AAHy4Er7z768CmYy9M5drJOMQO2S-QnwdTI", &MainState) + neko.ApiServer = "http://192.168.100.15:7373" log.Fatal(neko.DispatchPoll()) } diff --git a/states.go b/states.go index cdef268..b25fea5 100644 --- a/states.go +++ b/states.go @@ -1,7 +1,37 @@ package main -import neco "git.nefrace.ru/nefrace/nechotron" +import ( + "log" -func MainState(u *neco.Update) (neco.Runnable, error) { - return nil, nil + neco "git.nefrace.ru/nefrace/nechotron" + "github.com/NicoNex/echotron/v3" +) + +var MainState = neco.State{ + Fn: func(u *neco.Update) (neco.Runnable, error) { + log.Println(u.Message.ID) + if len(u.Message.Photo) > 0 { + f, err := u.Bot.GetFile(u.Message.Photo[len(u.Message.Photo)-1].FileID) + if err != nil { + log.Println(err) + return nil, err + } + log.Println(f.Result.FileID, f.Result.FilePath) + dl, err := u.Bot.DownloadFile(f.Result.FilePath) + if err != nil { + log.Println(err) + return nil, err + } + // log.Println(string(dl)) + _, err = u.Bot.SendPhoto(echotron.NewInputFileBytes("newfile.jpg", dl), u.ChatID(), &echotron.PhotoOptions{}) + res, err := u.Bot.SendPhoto(echotron.NewInputFilePath("TEST.png"), u.ChatID(), &echotron.PhotoOptions{}) + if err != nil { + log.Println(err) + return nil, err + } + log.Println(res.Result.Photo[len(res.Result.Photo)-1].FileID) + return nil, err + } + return nil, nil + }, } diff --git a/types.go b/types.go new file mode 100644 index 0000000..d713598 --- /dev/null +++ b/types.go @@ -0,0 +1,14 @@ +package main + +import "git.nefrace.ru/nefrace/tongo" + +var _ tongo.Collectable = &User{} + +type User struct { + tongo.Item + Username string + FirstName string + ID int64 +} + +func (User) Coll() string { return "users" }