diff --git a/commands.go b/commands.go new file mode 100644 index 0000000..f54bc95 --- /dev/null +++ b/commands.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "git.nefrace.ru/nefrace/nechotron" +) + +var commandMe = nechotron.NewCommand("me", false) + +func handleMe(u *nechotron.UpdateCommand) error { + _, err := u.AnswerMarkdown(fmt.Sprintf("_*%s* %s_", nechotron.EscapeMd2(u.From().FirstName), nechotron.EscapeMd2(u.Param))) + return err +} + +var commandHelp = nechotron.NewCommand("help", false) + +func handleHelp(u *nechotron.UpdateCommand) error { + _, err := u.AnswerPlain("Тут текст помощи") + return err +} + +var commandSay = nechotron.NewCommand("say", true) + +func handleSay(u *nechotron.UpdateCommand) error { + _, err := u.AnswerMarkdown(fmt.Sprintf("*_%s_*", nechotron.EscapeMd2(u.Param))) + return err +} diff --git a/main.go b/main.go index 5b03d2c..353af66 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,6 @@ import ( func main() { neko := nechotron.NewTron("1698825178:AAHy4Er7z768CmYy9M5drJOMQO2S-QnwdTI", &MainState) - neko.ApiServer = "http://192.168.100.15:7373" + // neko.ApiServer = "http://192.168.100.15:7373" log.Fatal(neko.DispatchPoll()) } diff --git a/states.go b/states.go index b25fea5..ebb19a9 100644 --- a/states.go +++ b/states.go @@ -1,37 +1,16 @@ package main import ( - "log" - 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 + Fn: func(u *neco.Update) error { + disp := neco.NewDispatcher(). + HandleCommand(commandMe, handleMe). + HandleCommand(commandHelp, handleHelp). + HandleCommand(commandSay, handleSay) + + return disp.Run(u) }, }