lightningtipbot/internal/telegram/message.go
gohumble bf643f103d
🪄 update telebot v3 🤖 (#325)
* 🚧 minor changes to all handlers...

* 🚧 passing callback to tryEditStack

* 🚧 edit and delete callback messages

* 🚧 refactor again

* 🚧 uncomment this

* 🚧 using ctx.Message().Text

* 🚧 refactor

* 🚧 refactor

* 🚧 uncomment

* context not queruy

* 🚧 update forked lightningtipbot

* 🚧 reset ArticleResult

* fix inline receive

* readd shop

* remove chat from shopView

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2022-03-27 22:19:38 +02:00

47 lines
818 B
Go

package telegram
import (
"strconv"
"time"
tb "gopkg.in/lightningtipbot/telebot.v3"
)
type Message struct {
Message *tb.Message `json:"message"`
duration time.Duration
}
type MessageOption func(m *Message)
func WithDuration(duration time.Duration, tipBot *TipBot) MessageOption {
return func(m *Message) {
m.duration = duration
go m.dispose(tipBot)
}
}
func NewMessage(m *tb.Message, opts ...MessageOption) *Message {
msg := &Message{
Message: m,
}
for _, opt := range opts {
opt(msg)
}
return msg
}
func (msg Message) Key() string {
return strconv.Itoa(msg.Message.ID)
}
func (msg Message) dispose(tipBot *TipBot) {
// do not delete messages from private chat
if msg.Message.Private() {
return
}
go func() {
time.Sleep(msg.duration)
tipBot.tryDeleteMessage(msg.Message)
}()
}