first commit
This commit is contained in:
39
messageCleaner.go
Normal file
39
messageCleaner.go
Normal file
@ -0,0 +1,39 @@
|
||||
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,
|
||||
})
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user