@@ -262,6 +262,9 @@ async def _handle_battle_message(self, split_messages: List[List[str]]):
262
262
:type split_message: str
263
263
"""
264
264
# Battle messages can be multiline
265
+ will_move = False
266
+ from_teampreview_request = False
267
+ maybe_default_order = False
265
268
if (
266
269
len (split_messages ) > 1
267
270
and len (split_messages [1 ]) > 1
@@ -284,7 +287,7 @@ async def _handle_battle_message(self, split_messages: List[List[str]]):
284
287
request = orjson .loads (split_message [2 ])
285
288
battle .parse_request (request )
286
289
if battle .move_on_next_request :
287
- await self . _handle_battle_request ( battle )
290
+ will_move = True
288
291
battle .move_on_next_request = False
289
292
elif split_message [1 ] == "win" or split_message [1 ] == "tie" :
290
293
if split_message [1 ] == "win" :
@@ -304,46 +307,53 @@ async def _handle_battle_message(self, split_messages: List[List[str]]):
304
307
"[Invalid choice] Sorry, too late to make a different move"
305
308
):
306
309
if battle .trapped :
307
- await self . _handle_battle_request ( battle )
310
+ will_move = True
308
311
elif split_message [2 ].startswith (
309
312
"[Unavailable choice] Can't switch: The active Pokémon is "
310
313
"trapped"
311
314
) or split_message [2 ].startswith (
312
315
"[Invalid choice] Can't switch: The active Pokémon is trapped"
313
316
):
314
317
battle .trapped = True
315
- await self . _handle_battle_request ( battle )
318
+ will_move = True
316
319
elif split_message [2 ].startswith (
317
320
"[Invalid choice] Can't switch: You can't switch to an active "
318
321
"Pokémon"
319
322
):
320
- await self ._handle_battle_request (battle , maybe_default_order = True )
323
+ will_move = True
324
+ maybe_default_order = True
321
325
elif split_message [2 ].startswith (
322
326
"[Invalid choice] Can't switch: You can't switch to a fainted "
323
327
"Pokémon"
324
328
):
325
- await self ._handle_battle_request (battle , maybe_default_order = True )
329
+ will_move = True
330
+ maybe_default_order = True
326
331
elif split_message [2 ].startswith (
327
332
"[Invalid choice] Can't move: Invalid target for"
328
333
):
329
- await self ._handle_battle_request (battle , maybe_default_order = True )
334
+ will_move = True
335
+ maybe_default_order = True
330
336
elif split_message [2 ].startswith (
331
337
"[Invalid choice] Can't move: You can't choose a target for"
332
338
):
333
- await self ._handle_battle_request (battle , maybe_default_order = True )
339
+ will_move = True
340
+ maybe_default_order = True
334
341
elif split_message [2 ].startswith (
335
342
"[Invalid choice] Can't move: "
336
343
) and split_message [2 ].endswith ("needs a target" ):
337
- await self ._handle_battle_request (battle , maybe_default_order = True )
344
+ will_move = True
345
+ maybe_default_order = True
338
346
elif (
339
347
split_message [2 ].startswith ("[Invalid choice] Can't move: Your" )
340
348
and " doesn't have a move matching " in split_message [2 ]
341
349
):
342
- await self ._handle_battle_request (battle , maybe_default_order = True )
350
+ will_move = True
351
+ maybe_default_order = True
343
352
elif split_message [2 ].startswith (
344
353
"[Invalid choice] Incomplete choice: "
345
354
):
346
- await self ._handle_battle_request (battle , maybe_default_order = True )
355
+ will_move = True
356
+ maybe_default_order = True
347
357
elif split_message [2 ].startswith (
348
358
"[Unavailable choice]"
349
359
) and split_message [2 ].endswith ("is disabled" ):
@@ -356,25 +366,34 @@ async def _handle_battle_message(self, split_messages: List[List[str]]):
356
366
"[Invalid choice] Can't move: You sent more choices than unfainted"
357
367
" Pokémon."
358
368
):
359
- await self ._handle_battle_request (battle , maybe_default_order = True )
369
+ will_move = True
370
+ maybe_default_order = True
360
371
elif split_message [2 ].startswith (
361
372
"[Invalid choice] Can't move: You can only Terastallize once per battle."
362
373
):
363
- await self ._handle_battle_request (battle , maybe_default_order = True )
374
+ will_move = True
375
+ maybe_default_order = True
364
376
else :
365
377
self .logger .critical ("Unexpected error message: %s" , split_message )
366
378
elif split_message [1 ] == "turn" :
367
379
battle .parse_message (split_message )
368
- await self . _handle_battle_request ( battle )
380
+ will_move = True
369
381
elif split_message [1 ] == "teampreview" :
370
382
battle .parse_message (split_message )
371
- await self ._handle_battle_request (battle , from_teampreview_request = True )
383
+ will_move = True
384
+ from_teampreview_request = True
372
385
elif split_message [1 ] == "bigerror" :
373
386
self .logger .warning ("Received 'bigerror' message: %s" , split_message )
374
387
elif split_message [1 ] == "uhtml" and split_message [2 ] == "otsrequest" :
375
388
await self ._handle_ots_request (battle .battle_tag )
376
389
else :
377
390
battle .parse_message (split_message )
391
+ if will_move :
392
+ await self ._handle_battle_request (
393
+ battle ,
394
+ from_teampreview_request = from_teampreview_request ,
395
+ maybe_default_order = maybe_default_order ,
396
+ )
378
397
379
398
async def _handle_battle_request (
380
399
self ,
0 commit comments