@@ -43,7 +43,7 @@ def read_bots
43
43
bots [ bot_name ] = { }
44
44
45
45
chatbot_rules = hackerbot . at_xpath ( 'AIML_chatbot_rules' ) . text
46
- Print . debug "Loading chat_ai from #{ chatbot_rules } "
46
+ Print . debug "Loading chatbot ai from #{ chatbot_rules } "
47
47
bots [ bot_name ] [ 'chat_ai' ] = ProgramR ::Facade . new
48
48
bots [ bot_name ] [ 'chat_ai' ] . learn ( [ chatbot_rules ] )
49
49
@@ -87,6 +87,7 @@ def read_bots
87
87
# is this the last one?
88
88
if bots [ bot_name ] [ 'current_hack' ] < bots [ bot_name ] [ 'hacks' ] . length - 1
89
89
bots [ bot_name ] [ 'current_hack' ] += 1
90
+ bots [ bot_name ] [ 'current_quiz' ] = nil
90
91
current = bots [ bot_name ] [ 'current_hack' ]
91
92
92
93
# prompt for current hack
@@ -107,6 +108,7 @@ def read_bots
107
108
# is this a valid attack number?
108
109
if requested_index < bots [ bot_name ] [ 'hacks' ] . length
109
110
bots [ bot_name ] [ 'current_hack' ] = requested_index
111
+ bots [ bot_name ] [ 'current_quiz' ] = nil
110
112
current = bots [ bot_name ] [ 'current_hack' ]
111
113
112
114
# prompt for current hack
@@ -124,6 +126,52 @@ def read_bots
124
126
125
127
Print . debug "answer = #{ answer } "
126
128
129
+ current_quiz = bots [ bot_name ] [ 'current_quiz' ]
130
+ current = bots [ bot_name ] [ 'current_hack' ]
131
+
132
+ quiz = nil
133
+ # is there ONE quiz question?
134
+ if bots [ bot_name ] [ 'hacks' ] [ current ] . key? ( 'quiz' ) && bots [ bot_name ] [ 'hacks' ] [ current ] [ 'quiz' ] . key? ( 'answer' )
135
+ quiz = bots [ bot_name ] [ 'hacks' ] [ current ] [ 'quiz' ]
136
+ # multiple quiz questions?
137
+ # elsif bots[bot_name]['hacks'][current]['quiz'][current_quiz].key?('answer')
138
+ # quiz = bots[bot_name]['hacks'][current]['quiz'][current_quiz]
139
+ end
140
+
141
+ if quiz != nil
142
+ if answer . match ( quiz [ 'answer' ] )
143
+ m . reply 'CORRECT!!!!!!'
144
+ m . reply quiz [ 'correct_answer_response' ]
145
+
146
+ # Repeated logic
147
+ if quiz . key? ( 'trigger_next_attack' )
148
+ if bots [ bot_name ] [ 'current_hack' ] < bots [ bot_name ] [ 'hacks' ] . length - 1
149
+ bots [ bot_name ] [ 'current_hack' ] += 1
150
+ bots [ bot_name ] [ 'current_quiz' ] = nil
151
+ current = bots [ bot_name ] [ 'current_hack' ]
152
+
153
+ sleep ( 1 )
154
+ # prompt for current hack
155
+ m . reply bots [ bot_name ] [ 'hacks' ] [ current ] [ 'prompt' ]
156
+ else
157
+ m . reply bots [ bot_name ] [ 'messages' ] [ 'last_attack' ] . sample
158
+ end
159
+ end
160
+
161
+ else
162
+ m . reply 'INCORRECT!!!!!'
163
+ end
164
+ else
165
+ m . reply 'There is no question to answer'
166
+ end
167
+
168
+ Print . debug bots [ bot_name ] [ 'hacks' ] [ current ] . to_s
169
+ # Print.debug bots[bot_name]['hacks'][current]['condition']['quiz'][current_quiz]['answer']
170
+
171
+ # else
172
+ # m.reply 'Not currently waiting on an answer'
173
+ # end
174
+
127
175
128
176
end
129
177
@@ -133,6 +181,7 @@ def read_bots
133
181
# is this the last one?
134
182
if bots [ bot_name ] [ 'current_hack' ] > 0
135
183
bots [ bot_name ] [ 'current_hack' ] -= 1
184
+ bots [ bot_name ] [ 'current_quiz' ] = nil
136
185
current = bots [ bot_name ] [ 'current_hack' ]
137
186
138
187
# prompt for current hack
@@ -163,7 +212,7 @@ def read_bots
163
212
return if m . message =~ /help|next|previous|list|^(goto|attack) [0-9]|(the answer is|answer)/
164
213
165
214
begin
166
- reaction = bots [ bot_name ] [ 'chat_ai' ] . get_reaction ( m . message )
215
+ reaction = bots [ bot_name ] [ 'chat_ai' ] . get_reaction ( m . message . gsub /([^a-z0-9 \- ]+)/i , '' )
167
216
168
217
rescue Exception => e
169
218
puts e . message
@@ -225,10 +274,12 @@ def read_bots
225
274
end
226
275
227
276
if condition_met
228
- if condition . key? ( 'trigger_next' )
277
+ # Repeated logic for trigger_next_attack
278
+ if condition . key? ( 'trigger_next_attack' )
229
279
# is this the last one?
230
280
if bots [ bot_name ] [ 'current_hack' ] < bots [ bot_name ] [ 'hacks' ] . length - 1
231
281
bots [ bot_name ] [ 'current_hack' ] += 1
282
+ bots [ bot_name ] [ 'current_quiz' ] = nil
232
283
current = bots [ bot_name ] [ 'current_hack' ]
233
284
234
285
sleep ( 1 )
@@ -239,8 +290,9 @@ def read_bots
239
290
end
240
291
end
241
292
242
- if condition . key? ( 'quiz' )
243
- m . reply condition [ 'quiz' ] [ 'question' ]
293
+ if condition . key? ( 'trigger_quiz' )
294
+ m . reply bots [ bot_name ] [ 'hacks' ] [ current ] [ 'quiz' ] [ 'question' ]
295
+ m . reply bots [ bot_name ] [ 'messages' ] [ 'say_answer' ]
244
296
bots [ bot_name ] [ 'current_quiz' ] = 0
245
297
end
246
298
end
0 commit comments