craft-bot/messageCleaner.go
Timofey.Kovalev 7fdb46d208 first commit
2021-06-10 21:12:47 +03:00

40 lines
665 B
Go

package main
import (
"context"
"sync"
"time"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
type messageCleaner struct {
botApi *tgbotapi.BotAPI
wg *sync.WaitGroup
}
func newMessageCleaner(bot *tgbotapi.BotAPI, wg *sync.WaitGroup) *messageCleaner {
return &messageCleaner{
botApi: bot,
wg: wg,
}
}
func (m *messageCleaner) add(ctx context.Context, messID int, chatID int64, d time.Duration) {
m.wg.Add(1)
go func() {
defer m.wg.Done()
select {
case <-time.NewTimer(d).C:
case <-ctx.Done():
}
_, _ = m.botApi.DeleteMessage(tgbotapi.DeleteMessageConfig{
MessageID: messID,
ChatID: chatID,
})
}()
}