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

Added war_ended event #242

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions coc/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,21 @@ async def wrapped(cached_war: ClanWar, war: ClanWar, callback):
# no war on endpoint, so new war is for sure new
await callback(war)
return _ValidateEvent.shortcut_register(wrapped, tags, custom_class, retry_interval, WarEvents.event_type)

@classmethod
def war_ended(cls, tags=None, custom_class=None, retry_interval=None):
"""Alias for the war end time changes, indicating a war has just ended"""

async def wrapped(cached_war: ClanWar, war: ClanWar, callback):
if war.state == "warEnded":
# Check if the end time has changed or if it's newly set
end_time_changed = cached_war.end_time and war.end_time and cached_war.end_time.time != war.end_time.time
end_time_newly_set = war.end_time and not cached_war.end_time

if end_time_changed or end_time_newly_set:
await callback(war)

return _ValidateEvent.shortcut_register(wrapped, tags, custom_class, retry_interval, WarEvents.event_type)


@_ValidateEvent
Expand Down