Test middleware
This commit is contained in:
parent
8d4523efd7
commit
036e4dcbad
20
commands.go
20
commands.go
|
@ -3,26 +3,28 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.nefrace.ru/nefrace/nechotron"
|
||||
neco "git.nefrace.ru/nefrace/nechotron"
|
||||
)
|
||||
|
||||
var commandMe = nechotron.NewCommand("me", false)
|
||||
var commandMe = neco.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)))
|
||||
func handleMe(u *neco.UpdateCommand) error {
|
||||
_, err := u.AnswerMarkdown(fmt.Sprintf("_*%s* %s_", neco.EscapeMd2(u.From().FirstName), neco.EscapeMd2(u.Param)))
|
||||
return err
|
||||
}
|
||||
|
||||
var commandHelp = nechotron.NewCommand("help", false)
|
||||
var commandHelp = neco.NewCommand("help", "Показываю данный текст", false)
|
||||
|
||||
func handleHelp(u *nechotron.UpdateCommand) error {
|
||||
func handleHelp(u *neco.UpdateCommand) error {
|
||||
_, err := u.AnswerPlain("Тут текст помощи")
|
||||
return err
|
||||
}
|
||||
|
||||
var commandSay = nechotron.NewCommand("say", true)
|
||||
var commandSay = neco.NewCommand("say", "Пишу ваш текст от своего имени.", true)
|
||||
|
||||
func handleSay(u *nechotron.UpdateCommand) error {
|
||||
_, err := u.AnswerMarkdown(fmt.Sprintf("*_%s_*", nechotron.EscapeMd2(u.Param)))
|
||||
func handleSay(u *neco.UpdateCommand) error {
|
||||
_, err := u.AnswerMarkdown(fmt.Sprintf("*_%s_*", neco.EscapeMd2(u.Param)))
|
||||
return err
|
||||
}
|
||||
|
||||
var commandWarn = neco.NewCommand("warn", "Делаю предупреждение пользователю", true)
|
||||
|
|
7
main.go
7
main.go
|
@ -6,8 +6,11 @@ import (
|
|||
"git.nefrace.ru/nefrace/nechotron"
|
||||
)
|
||||
|
||||
var BuildTime string
|
||||
|
||||
func main() {
|
||||
neko := nechotron.NewTron("1698825178:AAHy4Er7z768CmYy9M5drJOMQO2S-QnwdTI", &MainState)
|
||||
neco := nechotron.NewTron("1698825178:AAHy4Er7z768CmYy9M5drJOMQO2S-QnwdTI", &MainState)
|
||||
neco.Use(UserLogger)
|
||||
// neko.ApiServer = "http://192.168.100.15:7373"
|
||||
log.Fatal(neko.DispatchPoll())
|
||||
log.Fatal(neco.DispatchPoll())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.nefrace.ru/nefrace/nechotron"
|
||||
)
|
||||
|
||||
func UserLogger(next nechotron.UpdateHandler) nechotron.UpdateHandler {
|
||||
return func(u *nechotron.Update) error {
|
||||
log.Println(u.From().FirstName)
|
||||
next(u)
|
||||
return nil
|
||||
}
|
||||
}
|
25
types.go
25
types.go
|
@ -1,14 +1,31 @@
|
|||
package main
|
||||
|
||||
import "git.nefrace.ru/nefrace/tongo"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.nefrace.ru/nefrace/tongo"
|
||||
)
|
||||
|
||||
var _ tongo.Collectable = &User{}
|
||||
|
||||
type User struct {
|
||||
tongo.Item
|
||||
Username string
|
||||
FirstName string
|
||||
ID int64
|
||||
Username string
|
||||
FirstName string
|
||||
ID int64
|
||||
KarmaOffser int
|
||||
}
|
||||
|
||||
func (User) Coll() string { return "users" }
|
||||
|
||||
var _ tongo.Collectable = &KarmaShot{}
|
||||
|
||||
type KarmaShot struct {
|
||||
tongo.Item
|
||||
From tongo.OID
|
||||
To tongo.OID
|
||||
Count int
|
||||
When time.Time
|
||||
}
|
||||
|
||||
func (KarmaShot) Coll() string { return "karma" }
|
||||
|
|
Loading…
Reference in New Issue