Skip to content

Commit

Permalink
Few fixes
Browse files Browse the repository at this point in the history
- 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 ⚡ when the match begin
- update preview in README
  • Loading branch information
j0k3r committed Jun 20, 2018
1 parent c216032 commit c23aa06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 23 additions & 8 deletions worldCupNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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"];
Expand All @@ -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']))
Expand All @@ -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"];
Expand Down Expand Up @@ -289,6 +295,7 @@ function getEventPlayerAlias($eventPlayerId)
$subject = '';
$details = '';
$interestingEvent = true;

switch ($eventType) {
// Timekeeping
case EVENT_PERIOD_START:
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c23aa06

Please sign in to comment.