From c23aa06dc65ab3a8d3873326253c9ccf0d1774eb Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 20 Jun 2018 07:01:16 +0200 Subject: [PATCH] Few fixes - update french translation - handle end of the game (and remove the match from the live entry) - cleanup etag array once in a while - re-add :zap: when the match begin - update preview in README --- README.md | 4 ++-- worldCupNotifier.php | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 58c226c..7b6cebc 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ It will post a message : ### Preview -Here is a preview of the Ghana vs USA match. +Here is a preview of the Colombia vs Japan match. -![worldcup-slack-bot sample](http://i.imgur.com/ucMTQrq.png) +![worldcup-slack-bot sample](https://i.imgur.com/H5kUavh.png) ### Requirements diff --git a/worldCupNotifier.php b/worldCupNotifier.php index 474be53..76d6d27 100644 --- a/worldCupNotifier.php +++ b/worldCupNotifier.php @@ -39,16 +39,16 @@ $language = array( 'fr-FR' => array( 'Le match', - 'est sur le point de commencer', + 'est sur le point de commencer ', 'Carton jaune', 'Carton rouge', - 'contre son camp', - 'Penalty', + 'But contre son camp', + 'Pénalty', 'BUUUUUT', - 'Penalty manqué', + 'Pénalty manqué', 'commence', 'Mi-temps', - 'à plein temps', + 'Fin de la 2e période', 'a repris', ), 'en-GB' => array( @@ -88,6 +88,7 @@ const EVENT_STRAIGHT_RED = 4; // Maybe? const EVENT_PERIOD_START = 7; const EVENT_PERIOD_END = 8; +const EVENT_END_OF_GAME = 26; const EVENT_OWN_GOAL = 34; const EVENT_FREE_KICK_GOAL = 39; const EVENT_PENALTY_GOAL = 41; @@ -107,6 +108,11 @@ $dbFile = './worldCupDB.json'; $db = json_decode(file_get_contents($dbFile), true); +// clean etag once in a while +if (isset($db['etag']) && count($db['etag']) > 5) { + $db['etag'] = []; +} + /* * Get data from URL */ @@ -222,7 +228,7 @@ function getEventPlayerAlias($eventPlayerId) // Find live matches and update score foreach ($matches as $match) { - if (($match['MatchStatus'] == MATCH_STATUS_LIVE) && !in_array($match["IdMatch"], $db['live_matches'])) + if ($match['MatchStatus'] == MATCH_STATUS_LIVE && !in_array($match["IdMatch"], $db['live_matches'])) { // yay new match ! $db['live_matches'][] = $match["IdMatch"]; @@ -240,7 +246,7 @@ function getEventPlayerAlias($eventPlayerId) ); // notify slack & save data - postToSlack($language[LOCALE][0].' '.$match["Home"]["TeamName"][0]["Description"].' / '.$match["Away"]["TeamName"][0]["Description"].' '.$language[LOCALE][1].'! '); + postToSlack(':zap: '.$language[LOCALE][0].' '.$match["Home"]["TeamName"][0]["Description"].' / '.$match["Away"]["TeamName"][0]["Description"].' '.$language[LOCALE][1].'! '); } if (in_array($match["IdMatch"], $db['live_matches'])) @@ -254,7 +260,7 @@ function getEventPlayerAlias($eventPlayerId) } // Post update on live matches (events since last updated time) -foreach ($db['live_matches'] as $matchId) +foreach ($db['live_matches'] as $key => $matchId) { $homeTeamName = $db[$matchId]['teamsByHomeAway']["Home"]; $awayTeamName = $db[$matchId]['teamsByHomeAway']["Away"]; @@ -289,6 +295,7 @@ function getEventPlayerAlias($eventPlayerId) $subject = ''; $details = ''; $interestingEvent = true; + switch ($eventType) { // Timekeeping case EVENT_PERIOD_START: @@ -351,6 +358,14 @@ function getEventPlayerAlias($eventPlayerId) $subject = ':no_good: '.$language[LOCALE][7].' '.$eventTeam.'!!!'; $details = $eventPlayerAlias.' ('.$matchTime.')'; break; + + // end of live match + case EVENT_END_OF_GAME: + unset($db['live_matches'][$key]); + unset($db[$matchId]); + $interestingEvent = false; + break; + default: $interestingEvent = false; continue;