Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vildan-valeev committed Dec 29, 2023
1 parent 358d260 commit 9cb1dee
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Library with states, goroutines

## Example
```go

const (
groupID = 1234568
token = "token"
)

type stateFn func(event *gvk.Update) stateFn

type Bot struct {
Expand All @@ -14,11 +20,6 @@ type Bot struct {
gvk.API
}

const (
groupID = 1234567
token = "token here"
)

func newBot(chatID int64) gvk.Bot {
b := &Bot{
chatID: chatID,
Expand All @@ -34,20 +35,21 @@ func (b *Bot) Update(update *gvk.Update) {
}

func (b *Bot) EntryHandler(update *gvk.Update) stateFn {
if strings.HasPrefix(update.MessageNew.Message.Text, "ping") {
b.MessagesSend("pong", &gvk.MessagesSendOptions{UserID: b.chatID})
if strings.HasPrefix(update.Object.MessageNew.Message.Text, "ping") {
b.MessagesSend(&gvk.MessagesSendOptions{Message: "pong", UserID: b.chatID})
return b.handleNext
}

b.MessagesSend("not understand...", &gvk.MessagesSendOptions{UserID: b.chatID,})
b.MessagesSend(&gvk.MessagesSendOptions{Message: "not understand...", UserID: b.chatID})

return b.EntryHandler
}

func (b *Bot) handleNext(update *gvk.Update) stateFn {
b.name = update.MessageNew.Message.Text
b.MessagesSend("pong again )))", &gvk.MessagesSendOptions{
UserID: b.chatID,})
b.MessagesSend(&gvk.MessagesSendOptions{
Message: "pong again )))",
UserID: b.chatID,
})

return b.EntryHandler
}
Expand Down
2 changes: 1 addition & 1 deletion dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d *Dispatcher) PollOptions(dropPendingUpdates bool) error {
for {
//TODO: сброс апдейтов

time.Sleep(100 * time.Millisecond)
time.Sleep(50 * time.Millisecond)

result, err := d.api.GetUpdates(&d.opts)
if err != nil {
Expand Down
Empty file added go.sum
Empty file.
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type MessagesSendOptions struct {
Message string `query:"message"`
UserID int64 `query:"user_id"`
Keyboard Keyboard `query:"keyboard"`
DontParseLinks int64 `json:"dont_parse_links"`
DisableMentions int64 `json:"disable_mentions"`
DontParseLinks int64 `json:"dont_parse_links"` // 1 - true, 0 - false
DisableMentions int64 `json:"disable_mentions"` // 1 - true, 0 - false
}

type MessagesEditOptions struct {
Expand Down
6 changes: 3 additions & 3 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ func (u *Update) ChatID() int64 {
}

func (a RawUpdates) UnmarshalCustom() (Updates, error) {
if len(a) > 0 {
fmt.Println("COUNT UPDATES", len(a))
}
//if len(a) > 0 {
// fmt.Println("COUNT UPDATES", len(a))
//}

var updates Updates
for _, row := range a {
Expand Down

0 comments on commit 9cb1dee

Please sign in to comment.