Skip to content

Commit

Permalink
use weekdays num values to check for weekends
Browse files Browse the repository at this point in the history
Eslam-Nawara committed Nov 12, 2023
1 parent 92181c5 commit b281401
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions internal/bot.go
Original file line number Diff line number Diff line change
@@ -3,16 +3,14 @@ package internal

import (
"fmt"
"strings"
"slices"
"time"
_ "time/tzdata"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/rs/zerolog/log"
)

const weekends = "Friday Saturday"

// Bot contains the bot api and the communication channels with the bot
type Bot struct {
botAPI tgbotapi.BotAPI
@@ -89,6 +87,7 @@ func (bot Bot) Start() {

func (bot Bot) runBot() {
chatIDs := make(map[int64]bool)
weekends := []time.Weekday{time.Friday, time.Saturday}

ticker := time.NewTicker(bot.getDuration())

@@ -102,14 +101,13 @@ func (bot Bot) runBot() {

case <-ticker.C:
// skip weekends
if !strings.Contains(weekends, bot.time.Weekday().String()) {
if !slices.Contains(weekends, bot.time.Weekday()) {
for chatID := range chatIDs {
bot.sendReminder(chatID)
}

bot.time = bot.time.AddDate(0, 0, 1)
ticker.Reset(24 * time.Hour)
}
bot.time = bot.time.AddDate(0, 0, 1)
ticker.Reset(24 * time.Hour)
}
}
}

0 comments on commit b281401

Please sign in to comment.