mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-14 12:43:14 +02:00
* 🚧 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>
47 lines
818 B
Go
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)
|
|
}()
|
|
}
|