File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { pokedex } from 'ps-client/data' ;
22
33import { PSCommands } from '@/cache' ;
4- import { bulkAddPoints } from '@/database/points' ;
54import { i18n } from '@/i18n' ;
65import { TimeZone } from '@/ps/handlers/cron/constants' ;
76import { sample } from '@/utils/random' ;
@@ -144,27 +143,25 @@ export function register(this: Client, Jobs: PSCronJobManager): void {
144143 await sleep ( '1 min' ) ;
145144 room . send ( 'Starting kunc!' ) ;
146145
146+ const gamePoints : Record < string , { user : User ; points : number } > = { } ;
147+
147148 for ( let i = 0 ; i < rounds ; i ++ ) {
148149 const winners = ( await kuncCommand . run ( partialContext as PSCommandContext ) ) as User [ ] | null ;
149150 if ( winners ) {
150- const pointsData = Object . fromEntries (
151- winners . map ( user => [
152- user . id ,
153- {
154- name : user . name ,
155- id : user . id ,
156- points : {
157- points : 1 ,
158- officialPoints : 1 ,
159- } ,
160- } ,
161- ] )
162- ) ;
163- bulkAddPoints ( pointsData , room . id ) ;
151+ winners . forEach ( user => {
152+ gamePoints [ user . id ] ??= { user, points : 0 } ;
153+ gamePoints [ user . id ] . points ++ ;
154+ } ) ;
164155 }
165156 if ( i !== rounds - 1 ) await sleep ( '5 sec' ) ;
166157 }
167158
159+ const top = Object . values ( gamePoints )
160+ . sortBy ( entry => entry . points , 'desc' )
161+ . slice ( 0 , 3 ) ;
162+
163+ room . send ( `Winners: ${ top . map ( ( { user } ) => user . name ) . list ( ) } ` ) ; // TODO add points based on... PL?
164+
168165 postGGSSEvent ( ) ;
169166 } ) ;
170167
You can’t perform that action at this time.
0 commit comments