From bf61bf19a008c9f064aa127ce09625c82cfd7379 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:07:36 -0800 Subject: [PATCH] Sync old season before beginning new season (#55) * add `sync_test.ts` tests * call `await this.listPlayers()` once --- deno.lock | 216 +++++++++--------- deps.ts | 11 +- lib/api/dailies.ts | 21 +- lib/lc/client.ts | 4 +- lib/lc/client_interface.ts | 2 +- .../denokv/denokv_leaderboard_client.ts | 19 +- .../denokv/denokv_leaderboard_client_test.ts | 27 ++- lib/leaderboard/sync.ts | 18 +- lib/leaderboard/sync_test.ts | 165 +++++++++++++ 9 files changed, 347 insertions(+), 136 deletions(-) create mode 100644 lib/leaderboard/sync_test.ts diff --git a/deno.lock b/deno.lock index 18cf283..f8a9ad9 100644 --- a/deno.lock +++ b/deno.lock @@ -3,114 +3,114 @@ "remote": { "https://cdn.skypack.dev/-/tweetnacl@v1.0.3-G4yM3nQ8lnXXlGGQADqJ/dist=es2019,mode=imports/optimized/tweetnacl.js": "d26554516df57e5cb58954e90c633c8871b4e66016b9fe4e07a36db5430bc8c7", "https://cdn.skypack.dev/tweetnacl@1.0.3": "6610aad2ac175c2d575995fc7de8ed552c2e5e05aef80ed8588cf3c6e2db61d7", - "https://deno.land/std@0.206.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", - "https://deno.land/std@0.206.0/assert/_diff.ts": "58e1461cc61d8eb1eacbf2a010932bf6a05b79344b02ca38095f9b805795dc48", - "https://deno.land/std@0.206.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.206.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", - "https://deno.land/std@0.206.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", - "https://deno.land/std@0.206.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", - "https://deno.land/std@0.206.0/assert/assert_equals.ts": "d8ec8a22447fbaf2fc9d7c3ed2e66790fdb74beae3e482855d75782218d68227", - "https://deno.land/std@0.206.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", - "https://deno.land/std@0.206.0/assert/assert_false.ts": "0ccbcaae910f52c857192ff16ea08bda40fdc79de80846c206bfc061e8c851c6", - "https://deno.land/std@0.206.0/assert/assert_greater.ts": "ae2158a2d19313bf675bf7251d31c6dc52973edb12ac64ac8fc7064152af3e63", - "https://deno.land/std@0.206.0/assert/assert_greater_or_equal.ts": "1439da5ebbe20855446cac50097ac78b9742abe8e9a43e7de1ce1426d556e89c", - "https://deno.land/std@0.206.0/assert/assert_instance_of.ts": "3aedb3d8186e120812d2b3a5dea66a6e42bf8c57a8bd927645770bd21eea554c", - "https://deno.land/std@0.206.0/assert/assert_is_error.ts": "c21113094a51a296ffaf036767d616a78a2ae5f9f7bbd464cd0197476498b94b", - "https://deno.land/std@0.206.0/assert/assert_less.ts": "aec695db57db42ec3e2b62e97e1e93db0063f5a6ec133326cc290ff4b71b47e4", - "https://deno.land/std@0.206.0/assert/assert_less_or_equal.ts": "5fa8b6a3ffa20fd0a05032fe7257bf985d207b85685fdbcd23651b70f928c848", - "https://deno.land/std@0.206.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", - "https://deno.land/std@0.206.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", - "https://deno.land/std@0.206.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", - "https://deno.land/std@0.206.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", - "https://deno.land/std@0.206.0/assert/assert_not_strict_equals.ts": "ca6c6d645e95fbc873d25320efeb8c4c6089a9a5e09f92d7c1c4b6e935c2a6ad", - "https://deno.land/std@0.206.0/assert/assert_object_match.ts": "d8fc2867cfd92eeacf9cea621e10336b666de1874a6767b5ec48988838370b54", - "https://deno.land/std@0.206.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", - "https://deno.land/std@0.206.0/assert/assert_strict_equals.ts": "b1f538a7ea5f8348aeca261d4f9ca603127c665e0f2bbfeb91fa272787c87265", - "https://deno.land/std@0.206.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", - "https://deno.land/std@0.206.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", - "https://deno.land/std@0.206.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", - "https://deno.land/std@0.206.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", - "https://deno.land/std@0.206.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", - "https://deno.land/std@0.206.0/assert/mod.ts": "37c49a26aae2b254bbe25723434dc28cd7532e444cf0b481a97c045d110ec085", - "https://deno.land/std@0.206.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", - "https://deno.land/std@0.206.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", - "https://deno.land/std@0.206.0/datetime/constants.ts": "b63a6b702e06fa028fb2ffa25e0cf775e3b21cf7f38e53a6f219e9641894dfbb", - "https://deno.land/std@0.206.0/dotenv/mod.ts": "039468f5c87d39b69d7ca6c3d68ebca82f206ec0ff5e011d48205eea292ea5a6", - "https://deno.land/std@0.206.0/fmt/colors.ts": "c51c4642678eb690dcf5ffee5918b675bf01a33fba82acf303701ae1a4f8c8d9", - "https://deno.land/x/discord_api_types@0.37.63/gateway/common.ts": "fb67003adda424df76c2726e0624d709c5a16e3694d6b75facd587d121fe121f", - "https://deno.land/x/discord_api_types@0.37.63/gateway/v10.ts": "249f6de453d606b291fc548a27204b4a71bc462d3204c7a71622e016773ea9ab", - "https://deno.land/x/discord_api_types@0.37.63/globals.ts": "7d8879654c4741ac071668ad52f2659bcdb66694cfe7da306c8437ec752807a7", - "https://deno.land/x/discord_api_types@0.37.63/payloads/common.ts": "7c42a7965f38d82d9a425cf732ff0d4d2b5370568168d5fa41f138fd8ab4c693", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/attachment.ts": "c66dccd54c1b84d073f2e1caa466e551b8045a84a2e8a88a1bfbc7e2c64a703d", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/base.ts": "f6a2556e14d489e1f0e5ddeb3a0303e2603e25330530dd9263e176013c5f51eb", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/boolean.ts": "65e29561b61785ca4ede4b1b4a88c5fc0696cfdf1fa74d5197588c196ee7ae98", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/channel.ts": "73c7fc49de242e1ce3be958375fd810750aed83553ef3860e3cddf858f9eb464", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/integer.ts": "a25d24a3e54d647c7039b99e3208fc0fc2228d174f6dcc421e93919b8154a011", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/mentionable.ts": "742e42857465866e0c08b587d7fb5ccd81d4705c61ce4cd6b97ad5692e88e969", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/number.ts": "be974ea68f5fdf55d7a7f5d3faf48a3193777d432b1aa9087afc204bcb916284", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/role.ts": "a57114d0f7eeee4ab7cf217a865dd9dbd9096d007c556aec6185d64257100f41", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/shared.ts": "9e2d3b3530280f6de5f9b6de1bb81e8a905998e058f784a9b041e48a96cd93d2", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/string.ts": "33ab12dab64544a70729b9b66b5a9790964ea779f05d4ab1a1e190e7c1b59e98", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommand.ts": "0013737da6d2b54e2f413fbf31cf9c84ea51bd9204b615cb4fd19b420f856cb2", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommandGroup.ts": "db5cc701bcb3d68c094de409da39c9a2b8834dc0d5038e5f963c96e5eaf412ac", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/_chatInput/user.ts": "ed2871693744298225ba53ddfb18d3e7afff20a34f413822d5b1193918aea27f", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/chatInput.ts": "46362da4e56c99cc69331481330d6e95c31d5e46f4cc36ec23f03cafbb687d52", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/contextMenu.ts": "89aed5f05f75d482e40259f55d0172143a90c1980d060d16545bdc14b68b29c4", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/internals.ts": "5eb5ea13a1247c73c0611886dea09ab8d632a9c5555ff0f33d44cd379fd75a08", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/_applicationCommands/permissions.ts": "ddca14b62e6afd418c1417117ffcc7cfb2ea5e5cc5353b4a0598435bdea45fb5", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/applicationCommands.ts": "b0646f2930d38113389bd1ecf8c605ac5af8fc40f93fafd17f968150419fac14", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/autocomplete.ts": "821ae50ff9845cac4b03169dbd4c4b187d8399765eb1f0d658d477c68e4c6136", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/base.ts": "ca2df849ee55f2fbd5fa9626c48811de7cc9b69979838c6c54982a5e3a44219a", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/messageComponents.ts": "08faa77d1c1d9a33359a962b78b695304e27cb6435af319b41e9a9d3b395adb2", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/modalSubmit.ts": "3a02d2d7df5bcdb1ffcd089f15e0d82ab65dcc0cefa904c6e0621f46edac041e", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/ping.ts": "096ce582e9af373649fd5355cccd7424adceaffb73367b5301f1594ef5a3c264", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/_interactions/responses.ts": "c1b0fc1ecca7858de08720e0222660e23935ebdd563e1964878a525eb29f062b", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/application.ts": "7ec267bf4b809534c8c5e919a7b1da7b33190f9d545445146e007ddb9d0554f5", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/auditLog.ts": "ced9d28a20b2bb201761c37ef266ace325a808a405b7472d70ad6df3b56c4d87", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/autoModeration.ts": "9ccb4408f1c6392d9619fac159997e08e660080b3f9567a1619163a40329e3a2", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/channel.ts": "2d5168c85de11cb82503390aa6e49e20ea4bb806d010762cc3a4b1ece09b696a", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/emoji.ts": "b9a30b16e1ec4dc15d6149e59aa48b02ad57a51335b7be5a7f5368db0491b3dd", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/gateway.ts": "4ce715fa94eadf5e2ba6adfc4a3bf99bac5d19c4787794ee1774b645a324db72", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/guild.ts": "4c03e054fc07d8db0ee7fa2b6f645f57f7642de0d28a704aa15047a51544f710", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/guildScheduledEvent.ts": "bf506b7807501b71077751ec793e719c5515e1bb405dec5cc4371a61b03cf8b9", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/interactions.ts": "17dabe94016dad3d0d7fdc0aa812bf5b0b366465dd72cd0b01168880778cc60d", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/invite.ts": "92c09f549482a4e2ad5a3c1062debfb262c6fe4b6740581175a0b8108873ab01", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/mod.ts": "83d68247652307f1587d71ac6983fd795ad7b9d5c92540a65207ea9293b09812", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/monetization.ts": "9a91c8dbb4f4c505e561630f0205f821e6877a5ea74faf4eaad9c154f5cc0d02", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/oauth2.ts": "dfb9f09fb44bf5faaa73ad4488ebe408905907d5fd46404895317f4e7c378489", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/permissions.ts": "5e7990e6dad3e35f8c130dc52de4bbf63afe5d6ad98e1c56b09da3ead94ad5a4", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/stageInstance.ts": "f0b9ee8c24c67298086fa32cb0595f6c29710d81b6fe85b958d48e6c549c4cb8", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/sticker.ts": "8511b5cdbe8289ce13fd51c2e96d24548345111b8d9f9c907dd3336f10e795bf", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/teams.ts": "101044d8c48a3cbabb60048eff9f69588bdd1ea84d1825de0372b4e23ad7ccbe", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/template.ts": "c6bee171ed0ce61fc8b59de42541a023bdcde62718deb42325397e5c82efdc27", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/user.ts": "361b93e3683fcf611c021c4f39c7501ca1482e999887d97a4b0a09398b4618c5", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/voice.ts": "62d03a540f2e78e5f3989f71a0ee1ec682ef7306a4fa096f89118cbd82351d47", - "https://deno.land/x/discord_api_types@0.37.63/payloads/v10/webhook.ts": "7fc370f40a84f12a6e57ddda7cf2814f15039d6320b46979db0b49d5b91e303b", - "https://deno.land/x/discord_api_types@0.37.63/rest/common.ts": "36f7f83f8c1b95d68d9a55bc00b1d54eb4672186960962684826581f13ef9643", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/application.ts": "9f1c388bb5ccba192a57923c0aabe525f47de2d5ef8710a5d9a0cd0a3fa55317", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/auditLog.ts": "39a0914b6c51445023d82c3e3e66c9866cbb3cb6774d3e7eac63414ea9bcbfec", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/autoModeration.ts": "3d388fd9a91c34f04b5e3e1b6ffe12029fb48b511f37ff88042325ec6cbc6605", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/channel.ts": "421ab1178e83765fe403c75b8e481823bd10a9288c1487163c4f1b5049d2ca7c", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/emoji.ts": "9f694a1bd63886c62a87b4320f3bfa5d4f534b2d87c317d77d572d10522df3aa", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/gateway.ts": "747cb95c9a8bca4e52423c780d5fc492fb0dab2b6015cd7e51e890e8d51acf29", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/guild.ts": "6822854ad9026c2be656acc81e8161d45d650d44170e664762ec7e67b1f15e4e", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/guildScheduledEvent.ts": "29d361f395d8cd1ecb47550615d19e10793d513cc5ad8d32895da2cc9cd0fd89", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/interactions.ts": "2b6decdfff921b6aa8f0e6e5c61d38469a0178c5ecf1a18dd17ad6738143e662", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/invite.ts": "28f8e740bdaa782c9d9d504049323762b5c1180348019dc5f9e0a900ec11213e", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/mod.ts": "de48b0db06354fc8d37034a6cc5052a56fa38f4105db4df2157cfca8c164fbba", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/monetization.ts": "93f066371177fc847576df6875cd5019b116bc7ad0b2559395452d75920085a4", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/oauth2.ts": "b659a35654c17767480d142c46c36f5fe2544346875745e3f654c5e7c3d9f3f9", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/stageInstance.ts": "a090ff8b54f77188323af5d06cdef9c42738edf9a9b0eba8aad3c89d5ac5569f", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/sticker.ts": "1f7f2729308a0ec1fe373b5df7ac71bafc200132f1a06df7e75bf5ce1d1069c1", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/template.ts": "0ad41c3c85571d3c5b0bec3914c678a21f376ec162ef0d3f1f7731a8d1d1009c", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/user.ts": "60cfa227426c791021e9e8f769287e997477e722db5a3c577a9ec54078aaffca", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/voice.ts": "cdbe9d6c39c8f44635d8632bf62a95b8c15877b92c56ddf69df2072bb1a74edc", - "https://deno.land/x/discord_api_types@0.37.63/rest/v10/webhook.ts": "f4d47265bc69f9fa32efd0fd620db8b1d1996d2184cf5ac624abd104862d6ae0", - "https://deno.land/x/discord_api_types@0.37.63/rpc/common.ts": "a693352ffd86ae9e995fb3fbfbfd2be30896257ecb83c5611050f060b08de4ef", - "https://deno.land/x/discord_api_types@0.37.63/rpc/v10.ts": "fbaad9f3d73fce88e76b0e52ad5345093f18077e4293937c9ec0ee24415b9a93", - "https://deno.land/x/discord_api_types@0.37.63/utils/internals.ts": "cb70895ba89f7947c38f7fa447b0190cb14b5585be323414cda53d2ccb19b16c", - "https://deno.land/x/discord_api_types@0.37.63/utils/v10.ts": "056bd036f8c65365ff28eb63ec6897811d51921cca6d068392dd1ca5b397ae62", - "https://deno.land/x/discord_api_types@0.37.63/v10.ts": "f3f23492c59e77859aba5b34431edf3668c37f722d7f70c2e1ef7ba4bcda3010", + "https://deno.land/std@0.208.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", + "https://deno.land/std@0.208.0/assert/_diff.ts": "58e1461cc61d8eb1eacbf2a010932bf6a05b79344b02ca38095f9b805795dc48", + "https://deno.land/std@0.208.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", + "https://deno.land/std@0.208.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", + "https://deno.land/std@0.208.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", + "https://deno.land/std@0.208.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", + "https://deno.land/std@0.208.0/assert/assert_equals.ts": "d8ec8a22447fbaf2fc9d7c3ed2e66790fdb74beae3e482855d75782218d68227", + "https://deno.land/std@0.208.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", + "https://deno.land/std@0.208.0/assert/assert_false.ts": "0ccbcaae910f52c857192ff16ea08bda40fdc79de80846c206bfc061e8c851c6", + "https://deno.land/std@0.208.0/assert/assert_greater.ts": "ae2158a2d19313bf675bf7251d31c6dc52973edb12ac64ac8fc7064152af3e63", + "https://deno.land/std@0.208.0/assert/assert_greater_or_equal.ts": "1439da5ebbe20855446cac50097ac78b9742abe8e9a43e7de1ce1426d556e89c", + "https://deno.land/std@0.208.0/assert/assert_instance_of.ts": "3aedb3d8186e120812d2b3a5dea66a6e42bf8c57a8bd927645770bd21eea554c", + "https://deno.land/std@0.208.0/assert/assert_is_error.ts": "c21113094a51a296ffaf036767d616a78a2ae5f9f7bbd464cd0197476498b94b", + "https://deno.land/std@0.208.0/assert/assert_less.ts": "aec695db57db42ec3e2b62e97e1e93db0063f5a6ec133326cc290ff4b71b47e4", + "https://deno.land/std@0.208.0/assert/assert_less_or_equal.ts": "5fa8b6a3ffa20fd0a05032fe7257bf985d207b85685fdbcd23651b70f928c848", + "https://deno.land/std@0.208.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", + "https://deno.land/std@0.208.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", + "https://deno.land/std@0.208.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", + "https://deno.land/std@0.208.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", + "https://deno.land/std@0.208.0/assert/assert_not_strict_equals.ts": "4cdef83df17488df555c8aac1f7f5ec2b84ad161b6d0645ccdbcc17654e80c99", + "https://deno.land/std@0.208.0/assert/assert_object_match.ts": "d8fc2867cfd92eeacf9cea621e10336b666de1874a6767b5ec48988838370b54", + "https://deno.land/std@0.208.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", + "https://deno.land/std@0.208.0/assert/assert_strict_equals.ts": "b1f538a7ea5f8348aeca261d4f9ca603127c665e0f2bbfeb91fa272787c87265", + "https://deno.land/std@0.208.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", + "https://deno.land/std@0.208.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", + "https://deno.land/std@0.208.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", + "https://deno.land/std@0.208.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", + "https://deno.land/std@0.208.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", + "https://deno.land/std@0.208.0/assert/mod.ts": "37c49a26aae2b254bbe25723434dc28cd7532e444cf0b481a97c045d110ec085", + "https://deno.land/std@0.208.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", + "https://deno.land/std@0.208.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", + "https://deno.land/std@0.208.0/datetime/constants.ts": "b63a6b702e06fa028fb2ffa25e0cf775e3b21cf7f38e53a6f219e9641894dfbb", + "https://deno.land/std@0.208.0/dotenv/mod.ts": "039468f5c87d39b69d7ca6c3d68ebca82f206ec0ff5e011d48205eea292ea5a6", + "https://deno.land/std@0.208.0/fmt/colors.ts": "34b3f77432925eb72cf0bfb351616949746768620b8e5ead66da532f93d10ba2", + "https://deno.land/x/discord_api_types@0.37.65/gateway/common.ts": "fb67003adda424df76c2726e0624d709c5a16e3694d6b75facd587d121fe121f", + "https://deno.land/x/discord_api_types@0.37.65/gateway/v10.ts": "249f6de453d606b291fc548a27204b4a71bc462d3204c7a71622e016773ea9ab", + "https://deno.land/x/discord_api_types@0.37.65/globals.ts": "7d8879654c4741ac071668ad52f2659bcdb66694cfe7da306c8437ec752807a7", + "https://deno.land/x/discord_api_types@0.37.65/payloads/common.ts": "4449a87e8c1cf6d091f667370be3a42609c1a4f44cbe5f9881f7fc0e6f6920cc", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/attachment.ts": "c66dccd54c1b84d073f2e1caa466e551b8045a84a2e8a88a1bfbc7e2c64a703d", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/base.ts": "f6a2556e14d489e1f0e5ddeb3a0303e2603e25330530dd9263e176013c5f51eb", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/boolean.ts": "65e29561b61785ca4ede4b1b4a88c5fc0696cfdf1fa74d5197588c196ee7ae98", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/channel.ts": "73c7fc49de242e1ce3be958375fd810750aed83553ef3860e3cddf858f9eb464", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/integer.ts": "a25d24a3e54d647c7039b99e3208fc0fc2228d174f6dcc421e93919b8154a011", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/mentionable.ts": "742e42857465866e0c08b587d7fb5ccd81d4705c61ce4cd6b97ad5692e88e969", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/number.ts": "be974ea68f5fdf55d7a7f5d3faf48a3193777d432b1aa9087afc204bcb916284", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/role.ts": "a57114d0f7eeee4ab7cf217a865dd9dbd9096d007c556aec6185d64257100f41", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/shared.ts": "9e2d3b3530280f6de5f9b6de1bb81e8a905998e058f784a9b041e48a96cd93d2", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/string.ts": "33ab12dab64544a70729b9b66b5a9790964ea779f05d4ab1a1e190e7c1b59e98", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommand.ts": "0013737da6d2b54e2f413fbf31cf9c84ea51bd9204b615cb4fd19b420f856cb2", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/subcommandGroup.ts": "db5cc701bcb3d68c094de409da39c9a2b8834dc0d5038e5f963c96e5eaf412ac", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/_chatInput/user.ts": "ed2871693744298225ba53ddfb18d3e7afff20a34f413822d5b1193918aea27f", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/chatInput.ts": "46362da4e56c99cc69331481330d6e95c31d5e46f4cc36ec23f03cafbb687d52", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/contextMenu.ts": "89aed5f05f75d482e40259f55d0172143a90c1980d060d16545bdc14b68b29c4", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/internals.ts": "5eb5ea13a1247c73c0611886dea09ab8d632a9c5555ff0f33d44cd379fd75a08", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/_applicationCommands/permissions.ts": "ddca14b62e6afd418c1417117ffcc7cfb2ea5e5cc5353b4a0598435bdea45fb5", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/applicationCommands.ts": "b0646f2930d38113389bd1ecf8c605ac5af8fc40f93fafd17f968150419fac14", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/autocomplete.ts": "821ae50ff9845cac4b03169dbd4c4b187d8399765eb1f0d658d477c68e4c6136", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/base.ts": "ca2df849ee55f2fbd5fa9626c48811de7cc9b69979838c6c54982a5e3a44219a", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/messageComponents.ts": "08faa77d1c1d9a33359a962b78b695304e27cb6435af319b41e9a9d3b395adb2", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/modalSubmit.ts": "3a02d2d7df5bcdb1ffcd089f15e0d82ab65dcc0cefa904c6e0621f46edac041e", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/ping.ts": "096ce582e9af373649fd5355cccd7424adceaffb73367b5301f1594ef5a3c264", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/_interactions/responses.ts": "c1b0fc1ecca7858de08720e0222660e23935ebdd563e1964878a525eb29f062b", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/application.ts": "7ec267bf4b809534c8c5e919a7b1da7b33190f9d545445146e007ddb9d0554f5", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/auditLog.ts": "ced9d28a20b2bb201761c37ef266ace325a808a405b7472d70ad6df3b56c4d87", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/autoModeration.ts": "9ccb4408f1c6392d9619fac159997e08e660080b3f9567a1619163a40329e3a2", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/channel.ts": "47af2e40deb2ce6dd00438cd41d67d00f311ac330db6c27aed74da104776baf8", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/emoji.ts": "b9a30b16e1ec4dc15d6149e59aa48b02ad57a51335b7be5a7f5368db0491b3dd", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/gateway.ts": "4ce715fa94eadf5e2ba6adfc4a3bf99bac5d19c4787794ee1774b645a324db72", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/guild.ts": "4c03e054fc07d8db0ee7fa2b6f645f57f7642de0d28a704aa15047a51544f710", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/guildScheduledEvent.ts": "bf506b7807501b71077751ec793e719c5515e1bb405dec5cc4371a61b03cf8b9", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/interactions.ts": "17dabe94016dad3d0d7fdc0aa812bf5b0b366465dd72cd0b01168880778cc60d", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/invite.ts": "92c09f549482a4e2ad5a3c1062debfb262c6fe4b6740581175a0b8108873ab01", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/mod.ts": "83d68247652307f1587d71ac6983fd795ad7b9d5c92540a65207ea9293b09812", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/monetization.ts": "9a91c8dbb4f4c505e561630f0205f821e6877a5ea74faf4eaad9c154f5cc0d02", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/oauth2.ts": "dfb9f09fb44bf5faaa73ad4488ebe408905907d5fd46404895317f4e7c378489", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/permissions.ts": "5e7990e6dad3e35f8c130dc52de4bbf63afe5d6ad98e1c56b09da3ead94ad5a4", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/stageInstance.ts": "f0b9ee8c24c67298086fa32cb0595f6c29710d81b6fe85b958d48e6c549c4cb8", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/sticker.ts": "8511b5cdbe8289ce13fd51c2e96d24548345111b8d9f9c907dd3336f10e795bf", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/teams.ts": "101044d8c48a3cbabb60048eff9f69588bdd1ea84d1825de0372b4e23ad7ccbe", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/template.ts": "c6bee171ed0ce61fc8b59de42541a023bdcde62718deb42325397e5c82efdc27", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/user.ts": "361b93e3683fcf611c021c4f39c7501ca1482e999887d97a4b0a09398b4618c5", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/voice.ts": "62d03a540f2e78e5f3989f71a0ee1ec682ef7306a4fa096f89118cbd82351d47", + "https://deno.land/x/discord_api_types@0.37.65/payloads/v10/webhook.ts": "7fc370f40a84f12a6e57ddda7cf2814f15039d6320b46979db0b49d5b91e303b", + "https://deno.land/x/discord_api_types@0.37.65/rest/common.ts": "36f7f83f8c1b95d68d9a55bc00b1d54eb4672186960962684826581f13ef9643", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/application.ts": "9f1c388bb5ccba192a57923c0aabe525f47de2d5ef8710a5d9a0cd0a3fa55317", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/auditLog.ts": "39a0914b6c51445023d82c3e3e66c9866cbb3cb6774d3e7eac63414ea9bcbfec", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/autoModeration.ts": "3d388fd9a91c34f04b5e3e1b6ffe12029fb48b511f37ff88042325ec6cbc6605", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/channel.ts": "421ab1178e83765fe403c75b8e481823bd10a9288c1487163c4f1b5049d2ca7c", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/emoji.ts": "9f694a1bd63886c62a87b4320f3bfa5d4f534b2d87c317d77d572d10522df3aa", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/gateway.ts": "747cb95c9a8bca4e52423c780d5fc492fb0dab2b6015cd7e51e890e8d51acf29", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/guild.ts": "6822854ad9026c2be656acc81e8161d45d650d44170e664762ec7e67b1f15e4e", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/guildScheduledEvent.ts": "29d361f395d8cd1ecb47550615d19e10793d513cc5ad8d32895da2cc9cd0fd89", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/interactions.ts": "2b6decdfff921b6aa8f0e6e5c61d38469a0178c5ecf1a18dd17ad6738143e662", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/invite.ts": "28f8e740bdaa782c9d9d504049323762b5c1180348019dc5f9e0a900ec11213e", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/mod.ts": "de48b0db06354fc8d37034a6cc5052a56fa38f4105db4df2157cfca8c164fbba", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/monetization.ts": "93f066371177fc847576df6875cd5019b116bc7ad0b2559395452d75920085a4", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/oauth2.ts": "b659a35654c17767480d142c46c36f5fe2544346875745e3f654c5e7c3d9f3f9", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/stageInstance.ts": "a090ff8b54f77188323af5d06cdef9c42738edf9a9b0eba8aad3c89d5ac5569f", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/sticker.ts": "1f7f2729308a0ec1fe373b5df7ac71bafc200132f1a06df7e75bf5ce1d1069c1", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/template.ts": "0ad41c3c85571d3c5b0bec3914c678a21f376ec162ef0d3f1f7731a8d1d1009c", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/user.ts": "60cfa227426c791021e9e8f769287e997477e722db5a3c577a9ec54078aaffca", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/voice.ts": "cdbe9d6c39c8f44635d8632bf62a95b8c15877b92c56ddf69df2072bb1a74edc", + "https://deno.land/x/discord_api_types@0.37.65/rest/v10/webhook.ts": "f4d47265bc69f9fa32efd0fd620db8b1d1996d2184cf5ac624abd104862d6ae0", + "https://deno.land/x/discord_api_types@0.37.65/rpc/common.ts": "a693352ffd86ae9e995fb3fbfbfd2be30896257ecb83c5611050f060b08de4ef", + "https://deno.land/x/discord_api_types@0.37.65/rpc/v10.ts": "fbaad9f3d73fce88e76b0e52ad5345093f18077e4293937c9ec0ee24415b9a93", + "https://deno.land/x/discord_api_types@0.37.65/utils/internals.ts": "cb70895ba89f7947c38f7fa447b0190cb14b5585be323414cda53d2ccb19b16c", + "https://deno.land/x/discord_api_types@0.37.65/utils/v10.ts": "056bd036f8c65365ff28eb63ec6897811d51921cca6d068392dd1ca5b397ae62", + "https://deno.land/x/discord_api_types@0.37.65/v10.ts": "f3f23492c59e77859aba5b34431edf3668c37f722d7f70c2e1ef7ba4bcda3010", "https://deno.land/x/ulid@v0.3.0/mod.ts": "f7ff065b66abd485051fc68af23becef6ccc7e81f7774d7fcfd894a4b2da1984" } } diff --git a/deps.ts b/deps.ts index 5a86b06..9fc17d9 100644 --- a/deps.ts +++ b/deps.ts @@ -1,10 +1,9 @@ export { assertEquals, assertRejects, -} from "https://deno.land/std@0.206.0/assert/mod.ts"; - -export { load } from "https://deno.land/std@0.206.0/dotenv/mod.ts"; -export * from "https://deno.land/std@0.206.0/datetime/constants.ts"; +} from "https://deno.land/std@0.208.0/assert/mod.ts"; +export { load } from "https://deno.land/std@0.208.0/dotenv/mod.ts"; +export * from "https://deno.land/std@0.208.0/datetime/constants.ts"; export { ulid } from "https://deno.land/x/ulid@v0.3.0/mod.ts"; export type { APIApplicationCommandInteractionDataOption, @@ -17,12 +16,12 @@ export type { APIUser, RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIWebhookWithTokenJSONBody, -} from "https://deno.land/x/discord_api_types@0.37.63/v10.ts"; +} from "https://deno.land/x/discord_api_types@0.37.65/v10.ts"; export { ApplicationCommandOptionType, InteractionResponseType, InteractionType, MessageFlags, Utils, -} from "https://deno.land/x/discord_api_types@0.37.63/v10.ts"; +} from "https://deno.land/x/discord_api_types@0.37.65/v10.ts"; export { default as nacl } from "https://cdn.skypack.dev/tweetnacl@1.0.3"; diff --git a/lib/api/dailies.ts b/lib/api/dailies.ts index 2361f0a..277354b 100644 --- a/lib/api/dailies.ts +++ b/lib/api/dailies.ts @@ -1,4 +1,4 @@ -import { type APIEmbed } from "lc-dailies/deps.ts"; +import { type APIEmbed, WEEK } from "lc-dailies/deps.ts"; import * as api from "./mod.ts"; import * as discord from "lc-dailies/lib/discord/mod.ts"; import * as router from "lc-dailies/lib/router/mod.ts"; @@ -90,11 +90,20 @@ async function executeDailyWebhook( // If the season is ongoing, then sync it. const referenceDate = new Date(); - const isLatestSeason = storedSeason && leaderboard.checkDateInWeek( - new Date(storedSeason.start_date).getTime(), - referenceDate.getTime(), - ); - const syncedSeason = isLatestSeason + + let isLatestSeason = false; + if (storedSeason) { + const seasonStartDate = new Date(storedSeason.start_date).getTime(); + const seasonEndDate = seasonStartDate + WEEK; + isLatestSeason = leaderboard.checkDateBetween( + seasonStartDate, + seasonEndDate, + referenceDate.getTime(), + ); + } + + // Sync the season if it is ongoing and not synced. + const syncedSeason = isLatestSeason && storedSeason ? await leaderboardClient .sync(storedSeason.id) .then((response) => response.season) diff --git a/lib/lc/client.ts b/lib/lc/client.ts index c7435b3..b84b351 100644 --- a/lib/lc/client.ts +++ b/lib/lc/client.ts @@ -28,9 +28,9 @@ export class LCClient implements LCClientInterface { public async getDailyQuestion(): Promise { const date = new Date(); const [question] = await this.listDailyQuestions( - 1, date.getFullYear(), date.getMonth() + 1, + 1, ); if (!question) { throw new Error("No daily question found"); @@ -43,9 +43,9 @@ export class LCClient implements LCClientInterface { * listDailyQuestions gets the last `amount` of daily questions from Leetcode since `asOfYear` and `asOfMonth`. */ public async listDailyQuestions( - limit: number, asOfYear: number, asOfMonth: number, + limit = 10, ): Promise { const dailies: LCQuestion[] = []; let currentYear = asOfYear; diff --git a/lib/lc/client_interface.ts b/lib/lc/client_interface.ts index 7a67d74..1ea0e97 100644 --- a/lib/lc/client_interface.ts +++ b/lib/lc/client_interface.ts @@ -48,9 +48,9 @@ export interface LCClientInterface { * listDailyQuestions gets the last `amount` of daily questions from Leetcode since `asOfYear` and `asOfMonth`. */ listDailyQuestions( - limit: number, asOfYear: number, asOfMonth: number, + limit?: number, ): Promise; /** diff --git a/lib/leaderboard/denokv/denokv_leaderboard_client.ts b/lib/leaderboard/denokv/denokv_leaderboard_client.ts index 275fd23..86610fa 100644 --- a/lib/leaderboard/denokv/denokv_leaderboard_client.ts +++ b/lib/leaderboard/denokv/denokv_leaderboard_client.ts @@ -139,6 +139,7 @@ export class DenoKvLeaderboardClient implements LeaderboardClient { let seasonStartDate: Date; let isLatestSeason: boolean; let seasonResult: Deno.KvEntryMaybe | null; + const players = await this.listPlayers(); if (seasonID) { seasonResult = await this.kv.get([ LeaderboardKvPrefix.SEASONS, @@ -156,6 +157,23 @@ export class DenoKvLeaderboardClient implements LeaderboardClient { const isPresentAndLatest = seasonResult?.value && new Date(seasonResult.value.start_date).getTime() === startOfWeekDate.getTime(); + + if (!isPresentAndLatest && seasonResult?.value) { + // Sync old season. + const oldSeason = await sync({ + lcClient: this.lc, + players, + season: seasonResult.value, + }); + oldSeason.synced_at = referenceDate.toUTCString(); + + // Store the synced old season. + await this.kv.set( + [LeaderboardKvPrefix.SEASONS, oldSeason.id], + oldSeason, + ); + } + season = isPresentAndLatest ? seasonResult?.value! : makeEmptySeason(startOfWeekDate); @@ -164,7 +182,6 @@ export class DenoKvLeaderboardClient implements LeaderboardClient { } // Sync the season. - const players = await this.listPlayers(); season = await sync({ lcClient: this.lc, players, season }); season.synced_at = referenceDate.toUTCString(); diff --git a/lib/leaderboard/denokv/denokv_leaderboard_client_test.ts b/lib/leaderboard/denokv/denokv_leaderboard_client_test.ts index 7e46680..dabedcc 100644 --- a/lib/leaderboard/denokv/denokv_leaderboard_client_test.ts +++ b/lib/leaderboard/denokv/denokv_leaderboard_client_test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertRejects, DAY } from "lc-dailies/deps.ts"; +import { assertEquals, assertRejects, DAY, WEEK } from "lc-dailies/deps.ts"; import * as fake_lc from "lc-dailies/lib/lc/fake_client.ts"; import type { Season } from "lc-dailies/lib/api/mod.ts"; import { DenoKvLeaderboardClient } from "./denokv_leaderboard_client.ts"; @@ -60,32 +60,47 @@ Deno.test("DenoKvLeaderboardClient", async (t) => { ); const syncResponse = await client .sync(undefined, twoDaysAfterFakeSeasonStartDate); - assertSeasonsEqual(syncResponse.season, FAKE_SEASON); + assertSeasonsEquals(syncResponse.season, FAKE_SEASON); }); let seasonID: string | undefined; await t.step("getLatestSeason", async () => { const season = await client.getLatestSeason(); seasonID = season?.id; - assertSeasonsEqual(season, FAKE_SEASON); + assertSeasonsEquals(season, FAKE_SEASON); + }); + + await t.step("sync again", async () => { + const weekAfterFakeSeasonStartDate = new Date( + FAKE_SEASON_START_DATE.getTime() + WEEK, + ); + const syncResponse = await client + .sync(undefined, weekAfterFakeSeasonStartDate); + assertEquals( + syncResponse.season.start_date, + "Sun, 06 Aug 2023 00:00:00 GMT", + ); + assertEquals(syncResponse.season.submissions, {}); }); await t.step("listSeasons", async () => { const seasons = await client.listSeasons(); + assertEquals(seasons.length, 2); + const season = seasons[0]; - assertSeasonsEqual(season, FAKE_SEASON); + assertSeasonsEquals(season, FAKE_SEASON); }); await t.step("getSeason", async () => { const season = await client.getSeason(seasonID!); - assertSeasonsEqual(season, FAKE_SEASON); + assertSeasonsEquals(season, FAKE_SEASON); }); // Dispose of the resource. kv.close(); }); -function assertSeasonsEqual( +function assertSeasonsEquals( actualSeason: Season | null, expectedSeason: Season, ): void { diff --git a/lib/leaderboard/sync.ts b/lib/leaderboard/sync.ts index 6b7e179..9f01ba3 100644 --- a/lib/leaderboard/sync.ts +++ b/lib/leaderboard/sync.ts @@ -42,9 +42,9 @@ export async function sync(options: SyncOptions): Promise { const seasonStartDate = new Date(options.season.start_date); const seasonEndDate = new Date(seasonStartDate.getTime() + WEEK); const recentDailyQuestions = await options.lcClient.listDailyQuestions( - options.questionsFetchAmount ?? 10, seasonEndDate.getUTCFullYear(), seasonEndDate.getUTCMonth() + 1, + options.questionsFetchAmount, ); // Fetch the submissions of the players. @@ -69,8 +69,9 @@ export async function sync(options: SyncOptions): Promise { } // Skip if the submission is not in the season. - const isSubmissionInSeason = checkDateInWeek( + const isSubmissionInSeason = checkDateBetween( seasonStartDate.getTime(), + seasonEndDate.getTime(), submissionDate.getTime(), ); if (!isSubmissionInSeason) { @@ -90,8 +91,9 @@ export async function sync(options: SyncOptions): Promise { // Skip if the question is not in the season. const questionDate = new Date(recentDailyQuestion.date); - const isQuestionInSeason = checkDateInWeek( + const isQuestionInSeason = checkDateBetween( seasonStartDate.getTime(), + seasonEndDate.getTime(), questionDate.getTime(), ); if (!isQuestionInSeason) { @@ -135,8 +137,12 @@ export function fromLCTimestamp(timestamp: string): Date { } /** - * checkDateInWeek checks if a date is in a week. + * checkDateBetween checks if a date is in a given duration. */ -export function checkDateInWeek(startOfWeek: number, date: number): boolean { - return date >= startOfWeek && date < startOfWeek + WEEK; +export function checkDateBetween( + start: number, + end: number, + date: number, +): boolean { + return date >= start && date < end; } diff --git a/lib/leaderboard/sync_test.ts b/lib/leaderboard/sync_test.ts new file mode 100644 index 0000000..a8d1bd2 --- /dev/null +++ b/lib/leaderboard/sync_test.ts @@ -0,0 +1,165 @@ +import { assertEquals } from "lc-dailies/deps.ts"; +import type { LCSubmission } from "lc-dailies/lib/lc/mod.ts"; +// import type { SyncOptions } from "./sync.ts"; +import { sync } from "./sync.ts"; + +const FAKE_UNSYNCED_SEASON = { + "id": "01H8T4MM00BQHHK7VTTEJE1WAS", + "start_date": "Sun, 27 Aug 2023 00:00:00 GMT", + "players": { + "redacted_discord_id_00": { + "discord_user_id": "redacted_discord_id_00", + "lc_username": "EthanThatOneKid", + }, + "redacted_discord_id_01": { + "discord_user_id": "redacted_discord_id_01", + "lc_username": "PillowGit", + }, + }, + "questions": { + "implement-stack-using-queues": { + "name": "implement-stack-using-queues", + "date": "2023-08-28", + "title": "Implement Stack using Queues", + "difficulty": "Easy", + "url": "https://leetcode.com/problems/implement-stack-using-queues/", + }, + "counting-bits": { + "name": "counting-bits", + "date": "2023-09-01", + "title": "Counting Bits", + "difficulty": "Easy", + "url": "https://leetcode.com/problems/counting-bits/", + }, + }, + "submissions": { + "redacted_discord_id_00": { + "implement-stack-using-queues": { + "id": "1035629181", + "date": "Wed, 30 Aug 2023 04:10:39 GMT", + }, + "counting-bits": { + "id": "1037337123", + "date": "Fri, 01 Sep 2023 04:18:58 GMT", + }, + }, + "redacted_discord_id_01": { + "counting-bits": { + "id": "1037327504", + "date": "Fri, 01 Sep 2023 04:01:36 GMT", + }, + "implement-stack-using-queues": { + "id": "1034291152", + "date": "Mon, 28 Aug 2023 17:06:37 GMT", + }, + }, + }, + "scores": {}, +}; + +const FAKE_QUESTION = { + name: "reverse-integer", + date: "2023-09-02", + title: "Reverse Integer", + difficulty: "Easy", + url: "https://leetcode.com/problems/reverse-integer/", +}; + +const FAKE_SUBMISSION = { + id: "8008569420", + name: "reverse-integer", + title: "Reverse Integer", + timestamp: "1693627483", +}; + +const FAKE_SYNCED_SEASON = { + "id": "01H8T4MM00BQHHK7VTTEJE1WAS", + "start_date": "Sun, 27 Aug 2023 00:00:00 GMT", + "players": { + "redacted_discord_id_00": { + "discord_user_id": "redacted_discord_id_00", + "lc_username": "EthanThatOneKid", + }, + "redacted_discord_id_01": { + "discord_user_id": "redacted_discord_id_01", + "lc_username": "PillowGit", + }, + }, + "questions": { + "implement-stack-using-queues": { + "name": "implement-stack-using-queues", + "date": "2023-08-28", + "title": "Implement Stack using Queues", + "difficulty": "Easy", + "url": "https://leetcode.com/problems/implement-stack-using-queues/", + }, + "counting-bits": { + "name": "counting-bits", + "date": "2023-09-01", + "title": "Counting Bits", + "difficulty": "Easy", + "url": "https://leetcode.com/problems/counting-bits/", + }, + "reverse-integer": FAKE_QUESTION, + }, + "submissions": { + "redacted_discord_id_00": { + "implement-stack-using-queues": { + "id": "1035629181", + "date": "Wed, 30 Aug 2023 04:10:39 GMT", + }, + "counting-bits": { + "id": "1037337123", + "date": "Fri, 01 Sep 2023 04:18:58 GMT", + }, + }, + "redacted_discord_id_01": { + "counting-bits": { + "id": "1037327504", + "date": "Fri, 01 Sep 2023 04:01:36 GMT", + }, + "implement-stack-using-queues": { + "id": "1034291152", + "date": "Mon, 28 Aug 2023 17:06:37 GMT", + }, + "reverse-integer": { + "id": FAKE_SUBMISSION.id, + "date": "Sat, 02 Sep 2023 04:04:43 GMT", + }, + }, + }, + "scores": { + "redacted_discord_id_00": 159, + "redacted_discord_id_01": 204, + }, +}; + +Deno.test("sync syncs a season with Leetcode", async () => { + const actual = await sync({ + season: FAKE_UNSYNCED_SEASON, + players: FAKE_UNSYNCED_SEASON.players, + lcClient: { + verifyUser(_: string) { + throw new Error("Not implemented"); + }, + getDailyQuestion() { + throw new Error("Not implemented"); + }, + listDailyQuestions(_: number, __: number, ___: number) { + return Promise.resolve([FAKE_QUESTION]); + }, + getRecentAcceptedSubmissions(username: string, _?: number) { + const result: LCSubmission[] = []; + const fakeUsername = + FAKE_UNSYNCED_SEASON.players.redacted_discord_id_01.lc_username; + if (username === fakeUsername) { + result.push(FAKE_SUBMISSION); + } + + return Promise.resolve(result); + }, + }, + }); + + assertEquals(actual, FAKE_SYNCED_SEASON); +});