@@ -48,8 +48,8 @@ type Question struct {
48
48
}
49
49
50
50
type DisplayableContent struct {
51
- Type ContentType
52
- Text string
51
+ Type ContentType `json:"type"`
52
+ Text string `json:"text"`
53
53
}
54
54
55
55
type ContentType uint8
@@ -60,12 +60,13 @@ const (
60
60
)
61
61
62
62
type Round struct {
63
- Question string `json:"question"`
64
- Answers []string `json:"answers"`
65
- Correct int `json:"correct,omitempty"`
66
- Current int `json:"current_round"`
67
- Max int `json:"max_round"`
68
- Category string `json:"category"`
63
+ Question DisplayableContent `json:"question"`
64
+ Answers []DisplayableContent `json:"answers"`
65
+ Correct int `json:"correct,omitempty"`
66
+ Current int `json:"current_round"`
67
+ Max int `json:"max_round"`
68
+ Group string `json:"group"`
69
+ Category string `json:"category"`
69
70
}
70
71
71
72
type RoundSummary struct {
@@ -204,26 +205,28 @@ func (c Category) GetRounds(n int) []*Round {
204
205
}
205
206
206
207
func (q Question ) ToRound () Round {
207
- var answers []string
208
+ var answers []DisplayableContent
208
209
209
210
// select one correct answer
210
211
if len (q .Correct ) > 1 {
211
212
rand .Shuffle (len (q .Correct ), func (i , j int ) {
212
213
q .Correct [i ], q .Correct [j ] = q .Correct [j ], q .Correct [i ]
213
214
})
214
- answers = append (answers , q .Correct [rand .Intn (len (q .Correct )- 1 )]. Text )
215
+ answers = append (answers , q .Correct [rand .Intn (len (q .Correct )- 1 )])
215
216
} else {
216
- answers = append (answers , q .Correct [0 ]. Text )
217
+ answers = append (answers , q .Correct [0 ])
217
218
}
218
219
219
220
// select up to 3 wrong answers
220
221
if len (q .Wrong ) > 3 {
221
222
rand .Shuffle (len (q .Wrong ), func (i , j int ) {
222
223
q .Wrong [i ], q .Wrong [j ] = q .Wrong [j ], q .Wrong [i ]
223
224
})
224
- }
225
- for _ , a := range q .Wrong [:3 ] {
226
- answers = append (answers , a .Text )
225
+ for _ , a := range q .Wrong [:3 ] {
226
+ answers = append (answers , a )
227
+ }
228
+ } else {
229
+ answers = append (answers , q .Wrong ... )
227
230
}
228
231
229
232
var correct int
@@ -235,7 +238,7 @@ func (q Question) ToRound() Round {
235
238
})
236
239
237
240
return Round {
238
- Question : q .Question . Text ,
241
+ Question : q .Question ,
239
242
Answers : answers ,
240
243
Correct : correct + 1 ,
241
244
}
0 commit comments