File tree 1 file changed +20
-23
lines changed
1 file changed +20
-23
lines changed Original file line number Diff line number Diff line change @@ -137,32 +137,29 @@ impl Command for PickCommand {
137
137
138
138
let fid = match m. contains_id ( "name" ) {
139
139
//check for name specified
140
- true => {
141
- match m. get_one :: < String > ( "name" ) . map ( |name| name) {
142
- Some ( quesname) => match cache. get_problem_from_name ( quesname) {
143
- Ok ( p) => p. fid ,
144
- Err ( _) => 1 ,
145
- } ,
146
- None => {
147
- // Pick random without specify id
148
- let problem = & problems[ rand:: thread_rng ( ) . gen_range ( 0 ..problems. len ( ) ) ] ;
149
- problem. fid
150
- }
151
- }
152
- }
153
- false => {
154
- m. get_one :: < i32 > ( "id" )
155
- . map ( |id| * id)
156
- . or ( daily_id)
157
- . unwrap_or_else ( || {
158
- // Pick random without specify id
159
- let problem = & problems[ rand:: thread_rng ( ) . gen_range ( 0 ..problems. len ( ) ) ] ;
160
- problem. fid
161
- } )
140
+ true => match m. get_one :: < String > ( "name" ) . map ( |name| name) {
141
+ Some ( quesname) => match cache. get_problem_id_from_name ( quesname) {
142
+ Ok ( p) => Ok ( p) ,
143
+ Err ( e) => Err ( e) ,
144
+ } ,
145
+ None => Err ( Error :: NoneError ) ,
146
+ } ,
147
+ false => match m. get_one :: < i32 > ( "id" ) . map ( |id| * id) . or ( daily_id) {
148
+ Some ( p) => Ok ( p) ,
149
+ None => Err ( Error :: NoneError ) ,
150
+ } ,
151
+ } ;
152
+
153
+ let id = match fid {
154
+ Ok ( id) => id,
155
+ Err ( _) => {
156
+ // Pick random without specify id
157
+ let problem = & problems[ rand:: thread_rng ( ) . gen_range ( 0 ..problems. len ( ) ) ] ;
158
+ problem. fid
162
159
}
163
160
} ;
164
161
165
- let r = cache. get_question ( fid ) . await ;
162
+ let r = cache. get_question ( id ) . await ;
166
163
167
164
match r {
168
165
Ok ( q) => println ! ( "{}" , q. desc( ) ) ,
You can’t perform that action at this time.
0 commit comments