@@ -49,6 +49,7 @@ function isPointInsidePolygon($point, $vertices) {
49
49
$ webhook_raids_received_total ->incBy (count ($ update ));
50
50
}
51
51
foreach ($ update as $ raid ) {
52
+ if ($ raid ['type ' ] != 'raid ' ) continue ;
52
53
// Skip posting if create only -mode is set or raid time is greater than value set in config
53
54
$ no_auto_posting = ($ config ->WEBHOOK_CREATE_ONLY or ($ raid ['message ' ]['end ' ]-$ raid ['message ' ]['start ' ]) > ($ config ->WEBHOOK_EXCLUDE_AUTOSHARE_DURATION * 60 ));
54
55
@@ -311,61 +312,107 @@ function isPointInsidePolygon($point, $vertices) {
311
312
'shadow ' => (in_array ($ level , RAID_LEVEL_SHADOW ) ? 1 : 0 ),
312
313
]);
313
314
314
- $ chats_geofence = $ chats_raidlevel = $ webhook_chats = $ chats_by_pokemon = [];
315
+ $ chats_geofence = $ chats_raidlevel = $ webhook_chats = $ chats_by_pokemon = $ chats = [];
315
316
if ($ send_updates == true ) {
317
+ // Update raid polls and send alerts of updates
316
318
require_once (LOGIC_PATH .'/update_raid_poll.php ' );
317
319
$ tg_json = update_raid_poll ($ raid_id , $ raid , false , $ tg_json , true );
318
320
if ($ wasBossUpdated ) $ tg_json = alarm ($ raid , false , 'new_boss ' , '' , $ tg_json );
319
- if (!empty ($ config ->WEBHOOK_CHATS_BY_POKEMON [0 ]) && !$ no_auto_posting ) {
320
- foreach ($ config ->WEBHOOK_CHATS_BY_POKEMON as $ rule ) {
321
- if (isset ($ rule ['pokemon_id ' ]) && $ rule ['pokemon_id ' ] == $ pokemon && (!isset ($ rule ['form_id ' ]) or (isset ($ rule ['form_id ' ]) && $ rule ['form_id ' ] == $ form ))) {
322
- foreach ($ rule ['chats ' ] as $ rule_chat ) {
323
- // If the raid isn't already posted to the chats specified in WEBHOOK_CHATS_BY_POKEMON, we add it to the array
324
- if (!isset ($ cleanup_data [$ raid_id ]) or !in_array ($ rule_chat , $ cleanup_data [$ raid_id ])) {
325
- $ chats_by_pokemon [] = $ rule_chat ;
321
+ // Post hatched Pokemon to their respective chats if configured
322
+ // Start share_chats backwards compatibility
323
+ if (!isset ($ config ->CHATS_SHARE )) {
324
+ if (!empty ($ config ->WEBHOOK_CHATS_BY_POKEMON [0 ]) && !$ no_auto_posting ) {
325
+ foreach ($ config ->WEBHOOK_CHATS_BY_POKEMON as $ rule ) {
326
+ if (isset ($ rule ['pokemon_id ' ]) && $ rule ['pokemon_id ' ] == $ pokemon && (!isset ($ rule ['form_id ' ]) or (isset ($ rule ['form_id ' ]) && $ rule ['form_id ' ] == $ form ))) {
327
+ foreach ($ rule ['chats ' ] as $ rule_chat ) {
328
+ // If the raid isn't already posted to the chats specified in WEBHOOK_CHATS_BY_POKEMON, we add it to the array
329
+ if (!isset ($ cleanup_data [$ raid_id ]) or !in_array ($ rule_chat , $ cleanup_data [$ raid_id ])) {
330
+ $ chats_by_pokemon [] = create_chat_object ([$ rule_chat ]);
331
+ }
332
+ }
333
+ }
334
+ }
335
+ }
336
+ // End chats_share backwards compatibility
337
+ }else {
338
+ if (!empty ($ config ->CHATS_SHARE ['webhook ' ]['by_pokemon ' ]) && !$ no_auto_posting ) {
339
+ foreach ($ config ->CHATS_SHARE ['webhook ' ]['by_pokemon ' ] as $ rule ) {
340
+ if (isset ($ rule ['pokemon_id ' ]) && $ rule ['pokemon_id ' ] == $ pokemon && (!isset ($ rule ['form_id ' ]) or (isset ($ rule ['form_id ' ]) && $ rule ['FORM_ID ' ] == $ form ))) {
341
+ foreach ($ rule ['chats ' ] as $ rule_chat ) {
342
+ if (!isset ($ cleanup_data [$ raid_id ]) or !in_array ($ rule_chat ['id ' ], $ cleanup_data [$ raid_id ])) {
343
+ $ chats_by_pokemon [] = $ rule_chat ;
344
+ }
326
345
}
327
346
}
328
347
}
329
348
}
330
349
}
350
+
331
351
if (empty ($ chats_by_pokemon )) continue ;
332
352
}else {
333
- // Get chats to share to by raid level and geofence id
334
- if ($ geofences != false ) {
335
- foreach ($ inside_geofences as $ geofence_id ) {
336
- $ const_geofence = 'WEBHOOK_CHATS_LEVEL_ ' . $ level . '_ ' . $ geofence_id ;
337
- $ const_geofence_chats = $ config ->{$ const_geofence } ?? [];
338
-
339
- if (!empty ($ const_geofence_chats )) {
340
- $ chats_geofence = explode (', ' , $ const_geofence_chats );
353
+ // Start share_chats backwards compatibility
354
+ if (!isset ($ config ->CHATS_SHARE )) {
355
+ // Get chats to share to by raid level and geofence id
356
+ if ($ geofences != false ) {
357
+ foreach ($ inside_geofences as $ geofence_id ) {
358
+ $ const_geofence = 'WEBHOOK_CHATS_LEVEL_ ' . $ level . '_ ' . $ geofence_id ;
359
+ $ const_geofence_chats = $ config ->{$ const_geofence } ?? [];
360
+
361
+ if (!empty ($ const_geofence_chats )) {
362
+ $ chats_geofence = explode (', ' , $ const_geofence_chats );
363
+ }
341
364
}
342
365
}
343
- }
344
366
345
- // Get chats to share to by raid level
346
- $ const = 'WEBHOOK_CHATS_LEVEL_ ' . $ level ;
347
- $ const_chats = $ config ->{$ const } ?? [];
367
+ // Get chats to share to by raid level
368
+ $ const = 'WEBHOOK_CHATS_LEVEL_ ' . $ level ;
369
+ $ const_chats = $ config ->{$ const } ?? [];
348
370
349
- if (!empty ($ const_chats )) {
350
- $ chats_raidlevel = explode (', ' , $ const_chats );
351
- }
371
+ if (!empty ($ const_chats )) {
372
+ $ chats_raidlevel = explode (', ' , $ const_chats );
373
+ }
352
374
353
- // Get chats
354
- if (!empty ($ config ->WEBHOOK_CHATS_ALL_LEVELS )) {
355
- $ webhook_chats = explode (', ' , $ config ->WEBHOOK_CHATS_ALL_LEVELS );
375
+ // Get chats
376
+ if (!empty ($ config ->WEBHOOK_CHATS_ALL_LEVELS )) {
377
+ $ webhook_chats = explode (', ' , $ config ->WEBHOOK_CHATS_ALL_LEVELS );
378
+ }
379
+ $ chats_combined = array_merge ($ chats_geofence , $ chats_raidlevel , $ webhook_chats );
380
+ foreach ($ chats_combined as $ chat ) {
381
+ $ chats [] = create_chat_object ([$ chat ]);
382
+ }
383
+ // End chats_share backwards compatibility
384
+ }else {
385
+ if ($ geofences != false ) {
386
+ foreach ($ inside_geofences as $ geofence_id ) {
387
+ $ geofence_chats_all = $ config ->CHATS_SHARE ['webhook ' ]['geofences ' ][$ geofence_id ]['all ' ] ?? [];
388
+ $ geofence_chats_by_level = $ config ->CHATS_SHARE ['webhook ' ]['geofences ' ][$ geofence_id ][$ level ] ?? [];
389
+
390
+ if (!empty ($ geofence_chats_all )) {
391
+ $ chats_geofence = array_merge ($ chats_geofence , $ geofence_chats_all );
392
+ }
393
+ if (!empty ($ geofence_chats_by_level )) {
394
+ $ chats_geofence = array_merge ($ chats_geofence , $ geofence_chats_by_level );
395
+ }
396
+ }
397
+ }
398
+ // Get chats to share to by raid level
399
+ $ chats_raidlevel = $ config ->CHATS_SHARE ['webhook ' ][$ level ] ?? [];
400
+
401
+ // Get chats
402
+ $ webhook_chats = $ config ->CHATS_SHARE ['webhook ' ]['all ' ] ?? [];
403
+ $ chats = array_merge ($ chats_geofence , $ chats_raidlevel , $ webhook_chats );
356
404
}
357
405
}
358
406
359
- $ chats = array_merge ($ chats_geofence , $ chats_raidlevel , $ webhook_chats , $ chats_by_pokemon );
360
-
361
407
require_once (LOGIC_PATH .'/send_raid_poll.php ' );
362
408
if ($ metrics ) {
363
409
$ webhook_raids_posted_total ->inc ();
364
410
}
365
411
if (count ($ chats ) > 0 ) {
366
412
$ tg_json = send_raid_poll ($ raid_id , $ chats , $ raid , $ tg_json );
413
+ }elseif (count ($ chats_by_pokemon ) > 0 ) {
414
+ $ tg_json = send_raid_poll ($ raid_id , $ chats_by_pokemon , $ raid , $ tg_json );
367
415
}
368
416
}
369
-
370
417
// Telegram multicurl request.
371
418
curl_json_multi_request ($ tg_json );
0 commit comments