Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"When?" bot #83

Merged

Conversation

kazhuravlev
Copy link
Contributor

@kazhuravlev kazhuravlev commented Nov 26, 2022

  • removed when cmd (from sys bot)
  • implemented "when bot"
  • write a tests

closes #82

remove when cmd
implementation for "when bot"
enable the "when bot"
@coveralls
Copy link

coveralls commented Nov 27, 2022

Pull Request Test Coverage Report for Build 3567923629

  • 48 of 56 (85.71%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 82.898%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/bot/when.go 44 52 84.62%
Totals Coverage Status
Change from base Build 3473882661: 0.07%
Covered Lines: 1808
Relevant Lines: 2181

💛 - Coveralls

Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx. A few minor things/suggestions

app/bot/when.go Outdated Show resolved Hide resolved
app/bot/when.go Outdated Show resolved Hide resolved
app/bot/when.go Outdated Show resolved Hide resolved
app/bot/when.go Outdated
}

// closestPrevNextWeekdays returns closest next `weekday` at `hour`:`minute` after `t`.
func closestPrevNextWeekdays(t time.Time, weekday time.Weekday, hour, minute int) (time.Time, time.Time) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this supposed to be called closestPrevNextWeekend? Or maybe closestPrevNextSat?
Actually, I'm not fully certain what this func supposed to do and how it does it. From the caller side it looks like an attempt to discover times of the prev and next start of the podcast stream, but I don't really understand this implementation. Alternatively I can think on a simple loop adding 6 days to the current day and for back till it gets a pair of Sat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is pretty easy (but reading this is not so easy). I try to change a function for our concrete purpose with hardcode. I dont like it, but it will be easy to rewrite this function by someone.

I try to explain current behaviour:

  • Get an absolute diff in days between current weekday and stream weekday. daysDiff
  • Add this diff to current timestamp. now.Date() + daysDiff. This is date of stream
  • Create a new time.Time obj with date of stream, and constant hours of stream
  • Also, get the prev (or next) stream date depends on current calculation

Check out commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I missed the point, this is way too much for what it does. Isn't replacing this thing with a trivial "gimme time duration from now till the next show" enough? It will get rid of prev/next thing completely and will give you back directly what you are looking for - duration till the next show.

func(w *When) tillNextShow(t time.Time) (time.Duration) {
	next := t.AddDate(0, 0, int(time.Saturday-t.Weekday()))
	next = time.Date(next.Year(), next.Month(), next.Day(), 20, 0, 0, 0, time.UTC)
	return t.Sub(next)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

app/bot/when.go Outdated Show resolved Hide resolved
app/bot/when_test.go Outdated Show resolved Hide resolved
@umputun umputun merged commit a6e0fac into radio-t:master Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Добавление бота для команды countdown!
3 participants