Make bonus rules visible: highlighted BONUS line on the alerts overlay, streamgoals_bonus action
Test and Release / test (push) Successful in 1m14s
Test and Release / release (push) Successful in 4s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 12:07:06 -08:00
1 parent 1e2ca96eed
commit c7f2dcffeb
9 files changed
+187 -3

No files matched your search

+30
View File
@@ -107,6 +107,7 @@ final class Payloads {
'amount_display' => self::money( (int) $r['base_minor'], $cur ),
'currency' => $cur,
'message' => (string) ( $r['message'] ?? '' ),
'bonuses' => self::bonuses( $r['bonuses'] ?? array() ),
);
}
$alerts = array_slice( $alerts, 0, max( 1, $limit ) );
@@ -116,6 +117,35 @@ final class Payloads {
return array( 'alerts' => $alerts, 'last_id' => $lastId );
}
/**
* Display-safe bonus labels. Stored events should be [A-Za-z0-9_-] only; anything else is stripped
* anyway, then humanized ("big_donation" -> "Big donation"). Empty/duplicate results are dropped.
*
* @param mixed $events
* @return string[]
*/
public static function bonuses( mixed $events ): array {
$out = array();
foreach ( is_array( $events ) ? $events : array() as $e ) {
if ( ! is_string( $e ) ) {
continue;
}
$clean = substr( (string) preg_replace( '/[^A-Za-z0-9_-]/', '', $e ), 0, 40 );
$label = trim( (string) preg_replace( '/[_-]+/', ' ', $clean ) );
if ( '' === $label ) {
continue;
}
$label = ucfirst( strtolower( $label ) );
if ( ! in_array( $label, $out, true ) ) {
$out[] = $label;
}
if ( count( $out ) >= 5 ) {
break;
}
}
return $out;
}
/** Strong ETag over the payload, ignoring the volatile server_now so unchanged data yields 304s. */
public static function etag( array $payload ): string {
unset( $payload['server_now'] );