From c6ce1913dc53c2eda88827c1bbb3f12dabc02b4c Mon Sep 17 00:00:00 2001 From: nefrace Date: Fri, 10 Feb 2023 16:59:42 +0300 Subject: [PATCH] Added OptionsBuilder --- bot.go | 6 ++-- nechotron.go | 6 ++-- options.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 options.go diff --git a/bot.go b/bot.go index 74b3670..f1e11c1 100644 --- a/bot.go +++ b/bot.go @@ -12,15 +12,15 @@ import ( type bot struct { echo.API chatID int64 - me *echo.User + Me *echo.User data StateData lock sync.Mutex - state Runnable + State Runnable handler UpdateHandler } func DefaultHandler(u *Update) error { - err := u.Bot.state.Call(u) + err := u.Bot.State.Call(u) return err } diff --git a/nechotron.go b/nechotron.go index 1162496..03ec771 100644 --- a/nechotron.go +++ b/nechotron.go @@ -32,13 +32,13 @@ func (n *Nechotron) newBot(chatID int64) echo.Bot { // log.Println("New bot active: ", chatID, me.Result) b := &bot{ chatID: chatID, - me: me.Result, + Me: me.Result, API: a, - state: n.DefaultState, + State: n.DefaultState, data: make(StateData), handler: n.Handler, } - b.state = n.DefaultState + b.State = n.DefaultState return b } diff --git a/options.go b/options.go new file mode 100644 index 0000000..0c0bd7f --- /dev/null +++ b/options.go @@ -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, + } +}