diff options
author | Luca Matei Pintilie <luca@lucamatei.com> | 2023-07-29 21:55:25 +0000 |
---|---|---|
committer | Luca Matei Pintilie <luca@lucamatei.com> | 2023-07-29 21:55:25 +0000 |
commit | 02e6bd900641552bf53907c3ae14f86d925d4c58 (patch) | |
tree | 6bb21ea119383eacc8b9c45c4f9b60e62f628796 | |
parent | 47fe13ca267ac662f77e2bc9f2dc167fc42a3f1e (diff) | |
download | speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.tar speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.tar.gz speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.tar.bz2 speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.tar.lz speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.tar.xz speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.tar.zst speedrunbot-slash-02e6bd900641552bf53907c3ae14f86d925d4c58.zip |
Fix counting for users with no posts
-rwxr-xr-x | src/srcom/posts.ts | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/srcom/posts.ts b/src/srcom/posts.ts index 37f5a0f..eeb21ae 100755 --- a/src/srcom/posts.ts +++ b/src/srcom/posts.ts @@ -48,14 +48,7 @@ export async function posts( userAllPostsText.match(/(\d+)(\s+)?<\/div>(\s+)?<\/a>(\s+)?<\/nav>/)?.[0], ); const fetchPageTasks: (Promise<string> | string)[] = []; - - if ( - !userAllPostsText.includes( - "hasn't posted any comments yet.", - ) - ) { - return "This user has not posted anything on the forum yet."; - } else if (isNaN(numberOfPages)) { + if (isNaN(numberOfPages)) { fetchPageTasks.push(userAllPostsText); } else { for (let i = 1; i < numberOfPages + 1; i++) { @@ -93,20 +86,7 @@ export async function posts( // @ts-ignore I don't think this is possible to fail const totalMatches = userAllPostsText.match( /Showing \d+ to \d+ of (\d+)?(,)?(\d+)?(,)?(\d+)?/, - ).filter((f) => !!f); - let total = 0; - switch (totalMatches?.length) { - case 2: - total = parseInt(totalMatches[1]); - break; - case 4: - total = parseInt(totalMatches[1]) * 1_000 + parseInt(totalMatches[3]); - break; - case 6: - total = parseInt(totalMatches[1]) * 1_000_000 + - parseInt(totalMatches[3]) * 1_000 + parseInt(totalMatches[5]); - break; - } + )?.filter((f) => !!f); let game = 0; let site = 0; @@ -114,6 +94,25 @@ export async function posts( game += result.game; site += result.site; } + let total = game + site; + + if (totalMatches) { + switch (totalMatches.length) { + case 2: + total = parseInt(totalMatches[1]); + break; + case 4: + total = parseInt(totalMatches[1]) * 1_000 + parseInt(totalMatches[3]); + break; + case 6: + total = parseInt(totalMatches[1]) * 1_000_000 + + parseInt(totalMatches[3]) * 1_000 + parseInt(totalMatches[5]); + break; + default: + total = 0; + break; + } + } const secret = (site + game) - total; |