Skip to content

Commit

Permalink
feat: add PollTime to options
Browse files Browse the repository at this point in the history
  • Loading branch information
Александр Солопов committed Oct 14, 2024
1 parent b6b80a4 commit e94d4b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func NewBot(token string, opts ...BotOption) (*Bot, error) {
debug := defaultDebug
client := *http.DefaultClient
lastEventID := 0
pollTime := 0
for _, option := range opts {
switch option.Type() {
case "api_url":
Expand All @@ -273,6 +274,8 @@ func NewBot(token string, opts ...BotOption) (*Bot, error) {
client = option.Value().(http.Client)
case "last_event_id":
lastEventID = option.Value().(int)
case "poll_time":
pollTime = option.Value().(int)
}
}

Expand All @@ -281,7 +284,7 @@ func NewBot(token string, opts ...BotOption) (*Bot, error) {
}

tgClient := NewCustomClient(&client, apiURL, token, logger)
updater := NewUpdater(tgClient, 0, logger)
updater := NewUpdater(tgClient, pollTime, logger)
updater.lastEventID = lastEventID

info, err := tgClient.GetInfo()
Expand Down
10 changes: 10 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ func (o BotLastEventID) Type() string {
func (o BotLastEventID) Value() interface{} {
return int(o)
}

type BotPollTime int

func (o BotPollTime) Type() string {
return "poll_time"
}

func (o BotPollTime) Value() interface{} {
return int(o)
}

0 comments on commit e94d4b6

Please sign in to comment.