feat(race): add supports_countdown to ContestListResult

Problem: `:CP race` on platforms without future contests (CSES, USACO)
wastes time fetching the full contest list only to discover there is
no `start_time`. The error message is also uninformative.

Solution: Add `supports_countdown` bool to `ContestListResult` (default
`True`). CSES and USACO set it to `False`. Cache the flag per-platform
so subsequent calls skip the fetch entirely. `race.lua` checks the
cached value first, then the scraper result, and shows
`"<Platform> does not support :CP race"` instead of a generic error.
This commit is contained in:
Barrett Ruth 2026-03-06 18:01:08 -05:00
parent 592f977296
commit 4e709c8470
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
7 changed files with 62 additions and 16 deletions

View file

@ -392,7 +392,8 @@ end
---@param platform string
---@param contests ContestSummary[]
function M.set_contest_summaries(platform, contests)
---@param opts? { supports_countdown?: boolean }
function M.set_contest_summaries(platform, contests, opts)
cache_data[platform] = cache_data[platform] or {}
for _, contest in ipairs(contests) do
cache_data[platform][contest.id] = cache_data[platform][contest.id] or {}
@ -405,9 +406,22 @@ function M.set_contest_summaries(platform, contests)
end
end
if opts and opts.supports_countdown ~= nil then
cache_data[platform].supports_countdown = opts.supports_countdown
end
M.save()
end
---@param platform string
---@return boolean?
function M.get_supports_countdown(platform)
if not cache_data[platform] then
return nil
end
return cache_data[platform].supports_countdown
end
---@param platform string
---@param contest_id string
---@return integer?