File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ var config = require('../config');
1212var core = require ( '../core' ) ;
1313
1414var cmd = {
15- command : 'show < keyword> ' ,
15+ command : 'show [ keyword] ' ,
1616 desc : 'show problem by name or index' ,
1717 builder : {
1818 gen : {
Original file line number Diff line number Diff line change @@ -79,11 +79,25 @@ core.getProblem = function(keyword, cb) {
7979
8080 keyword = Number ( keyword ) || keyword ;
8181
82- var problem = _ . find ( problems , function ( x ) {
83- return x . id === keyword ||
84- x . name === keyword ||
85- x . slug === keyword ;
86- } ) ;
82+ var problem ;
83+ if ( keyword === undefined ) {
84+ log . debug ( 'random select problem' ) ;
85+ var user = core . getUser ( ) ;
86+ // random select one that not AC-ed yet
87+ problems = _ . filter ( problems , function ( x ) {
88+ if ( x . state === 'ac' ) return false ;
89+ if ( ! user . paid && x . locked ) return false ;
90+ return true ;
91+ } ) ;
92+ problem = problems [ _ . random ( problems . length - 1 ) ] ;
93+ } else {
94+ problem = _ . find ( problems , function ( x ) {
95+ return x . id === keyword ||
96+ x . name === keyword ||
97+ x . slug === keyword ;
98+ } ) ;
99+ }
100+
87101 if ( ! problem )
88102 return cb ( 'Problem not found!' ) ;
89103
You can’t perform that action at this time.
0 commit comments