Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Discord Event Announcements Finished #129
Discord Event Announcements Finished #129
Changes from 6 commits
d37cdb6
f4691b6
a17e20d
77117a7
6d34857
5afa421
480a860
2c15d57
ab0875f
86c479e
b25d208
f220330
b725aa8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't always be in daylight savings time, so PT would be more correct in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used DateTimeField and made it TZ aware. Everything is stored as UTC and the getters will convert it to Pacific Time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you consider renaming this function to something like
get_events_in_date_or_time_delta
? The fact that this has 3 branches plus a dict lookup makes it hard to understand. Maybe you could have a helper function,get_events_in_time_range
, that took a time range (start and end time) and returned events, and then have another function that translates "week", "day" etc to the correct time ranges to pass toget_events_in_time_range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have split the function into 3, namely
get_events_in_date_or_time_delta(requested_tdelta)
, and 2 helpers:get_events_in_time_range(range)
,timeify(requested_tdelta)
. I added docstrings in for added clarity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I regret saying to call it
get_events_in_date_or_time_delta
. Maybe you should think of a better name yourself, likeget_events_in_period
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring doesn't match what the function does
Redundant comments are neutral at best, but inconsistent comments are bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned earlier, if we remove date and only use time, then we could simplify this to just one filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this fix in
announcements.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could consider using https://docs.djangoproject.com/en/2.2/ref/models/options/#django.db.models.Options.ordering
To avoid re-writing the
order_by
each time we queryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added into the Events model so that everything is already ordered in the DB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The circular dependency makes me a bit uneasy. Haven't completely thought it through, but could
announcements_thread
andevent_announcement
be moved into this class?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally put this here because we need to wait for
on_ready
to trigger before theannouncement_thread
starts, or else the thread would start too early with no client ready. Do you have something else in mind?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so I'm wondering why
event_announcement
is a method inCSUABot
rather than inCSUAClient
, or even a stand-alone function, considering there's an instance ofCSUAClient
inCSUABot
. I suppose there isn't really an impact on functionality and it's more about design. My understanding is thatCSUAClient
holds the core parts running the bot, whileCSUABot
is sort of an internal API. Could we get a third opinion?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? Take a look at 201c5bf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MB I think I messed up when resolving the merge conflict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the constants you just defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the fact that we're using magic strings here. If "week" or "tomorrow" or "today" get accidentally misspelled, we might end up with a bug that we won't notice until the time comes around. My suggestion would be to define some constants like TODAY = "today" and just use those instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add pytz here or remove pytz from the code