first commit

This commit is contained in:
Timofey.Kovalev
2021-06-10 21:12:47 +03:00
commit 7fdb46d208
10 changed files with 1076 additions and 0 deletions

39
messageCleaner.go Normal file
View 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,
})
}()
}