Added OptionsBuilder
This commit is contained in:
parent
1377e03b5e
commit
c6ce1913dc
6
bot.go
6
bot.go
|
@ -12,15 +12,15 @@ import (
|
||||||
type bot struct {
|
type bot struct {
|
||||||
echo.API
|
echo.API
|
||||||
chatID int64
|
chatID int64
|
||||||
me *echo.User
|
Me *echo.User
|
||||||
data StateData
|
data StateData
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
state Runnable
|
State Runnable
|
||||||
handler UpdateHandler
|
handler UpdateHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultHandler(u *Update) error {
|
func DefaultHandler(u *Update) error {
|
||||||
err := u.Bot.state.Call(u)
|
err := u.Bot.State.Call(u)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ func (n *Nechotron) newBot(chatID int64) echo.Bot {
|
||||||
// log.Println("New bot active: ", chatID, me.Result)
|
// log.Println("New bot active: ", chatID, me.Result)
|
||||||
b := &bot{
|
b := &bot{
|
||||||
chatID: chatID,
|
chatID: chatID,
|
||||||
me: me.Result,
|
Me: me.Result,
|
||||||
API: a,
|
API: a,
|
||||||
state: n.DefaultState,
|
State: n.DefaultState,
|
||||||
data: make(StateData),
|
data: make(StateData),
|
||||||
handler: n.Handler,
|
handler: n.Handler,
|
||||||
}
|
}
|
||||||
b.state = n.DefaultState
|
b.State = n.DefaultState
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package nechotron
|
||||||
|
|
||||||
|
import "github.com/NicoNex/echotron/v3"
|
||||||
|
|
||||||
|
type OptionsBuilder struct {
|
||||||
|
caption string
|
||||||
|
replyMarkup echotron.ReplyMarkup
|
||||||
|
parseMode echotron.ParseMode
|
||||||
|
entities []echotron.MessageEntity
|
||||||
|
messageThreadID int64
|
||||||
|
replyToMessageID int
|
||||||
|
disableWebPagePreview bool
|
||||||
|
disableNotification bool
|
||||||
|
protectContent bool
|
||||||
|
allowSendingWithoutReply bool
|
||||||
|
hasSpoiler bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) Caption(text string) *OptionsBuilder {
|
||||||
|
o.caption = text
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) ReplyMarkup(markup echotron.ReplyMarkup) *OptionsBuilder {
|
||||||
|
o.replyMarkup = markup
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) MarkdownV2() *OptionsBuilder {
|
||||||
|
o.parseMode = echotron.MarkdownV2
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) Spoiler() *OptionsBuilder {
|
||||||
|
o.hasSpoiler = true
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) Entities(entities []echotron.MessageEntity) *OptionsBuilder {
|
||||||
|
o.entities = entities
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) Thread(id int64) *OptionsBuilder {
|
||||||
|
o.messageThreadID = id
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) ReplyTo(id int) *OptionsBuilder {
|
||||||
|
o.replyToMessageID = id
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) DisableNotification() *OptionsBuilder {
|
||||||
|
o.disableNotification = true
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) ProtectContent() *OptionsBuilder {
|
||||||
|
o.protectContent = true
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) DisableWebPagePreview() *OptionsBuilder {
|
||||||
|
o.disableWebPagePreview = true
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) AllowSendingWithoutReply() *OptionsBuilder {
|
||||||
|
o.allowSendingWithoutReply = true
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *OptionsBuilder) MessageOptions() *echotron.MessageOptions {
|
||||||
|
return &echotron.MessageOptions{
|
||||||
|
ReplyMarkup: o.replyMarkup,
|
||||||
|
ParseMode: o.parseMode,
|
||||||
|
Entities: o.entities,
|
||||||
|
MessageThreadID: o.messageThreadID,
|
||||||
|
ReplyToMessageID: o.replyToMessageID,
|
||||||
|
DisableWebPagePreview: o.allowSendingWithoutReply,
|
||||||
|
DisableNotification: o.disableNotification,
|
||||||
|
ProtectContent: o.protectContent,
|
||||||
|
AllowSendingWithoutReply: o.allowSendingWithoutReply,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue