Giter Site home page Giter Site logo

j0k3r / worldcup-slack-bot Goto Github PK

View Code? Open in Web Editor NEW
39.0 10.0 29.0 36 KB

WorldCupBot will notify a Slack channel/group for every match during a FIFA World Cup

License: MIT License

PHP 100.00%
slack bot worldcup football worldcup-slack-bot php fifa-api

worldcup-slack-bot's Introduction

Worldcup Slack Bot

WorldCupBot will notify a Slack channel/group for every matches during a FIFA World Cup.

The API haven't changed since the Russia World Cup 2018. Which means you can use that bot for every FIFA World Cup, you just need to update ID_COMPETITION & ID_SEASON.

Find the competition you are looking for

World Cup ID_COMPETITION ID_SEASON
FIFA World Cup Russia 2018™ 17 254645
FIFA U-20 World Cup Poland 2019 104 281971
FIFA Women's World Cup France 2019™ 103 278513
FIFA World Cup Qatar 2022™ 17 255711

If the competition you are looking for isn't defined below, here is how you can find these numbers:

  • determine when the competition will start (for example 2022-11-19T00:00:00Z)
  • go to https://api.fifa.com/api/v3/calendar/matches?from=DATE_START&language=en&count=500 and replace DATE_START with the previous date (be careful to use the same format)
  • look for the competition (for example FIFA World Cup Qatar 2022)
  • get the correspondant values:
    • IdSeason
    • IdCompetition

What it does

That bot is using the "unofficial" FIFA json API (the one used for their mobile apps).

It will post a message :

  • when a match starts
  • for every red/yellow card
  • for the half time and end time
  • and of course, for every goal

Preview

Here is a preview of the United States vs Wales match (during the 2022 edition).

worldcup-slack-bot sample

Requirements

  • PHP >= 5.5 (I guess?)
  • You need to create a Slack Apps with an incoming webhooks:
    • Jump at https://api.slack.com/messaging/webhooks (you have to login)
    • Create a Slack app
    • Enable Incoming Webhooks
    • Create an Incoming Webhook (you'll then select the channel used for that bot)
    • Grab the link like https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX and put it in SLACK_URL

Installation

  • Clone this repo
  • Set up a cron to run every minute:
* * * * * cd /path/to/folder && php worldCupNotifier.php >> worldCupNotifier.log

Side notes

The code is ugly but it works.

Everything is posted in french, but feel free to fork and use your own language. FYI, FIFA API can provide text in en/fr/de/es/pt.

worldcup-slack-bot's People

Contributors

j0k3r avatar kyzn avatar oltodo avatar pborreli avatar travisamiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

worldcup-slack-bot's Issues

Extra time and Penalties

Thank you to Spain and Russia for giving us a test case.

From looking at the JSON from the FIFA API it looks like extra time could get mapped as such by the bot:

const PERIOD_1ST_ET = 7;
const PERIOD_2ND_ET = 9;

PHP Warning

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/jason/projects/worldcup-slack-bot/worldCupNotifier.php on line 405

2018 Update?

Is there any chance of an update to this bot for 2018?

Straight red card type number

According the previous Colombia/Japan match, it seems the type number for the straight red card is 3 but not 4 like the following defines.

const EVENT_STRAIGHT_RED = 4; // Maybe?

Refer to the match's events :

https://api.fifa.com/api/v1/timelines/17/254645/275073/300331550?language=fr-FR&count=1

{
  "EventId": "-1011232931",
  "IdTeam": "43926",
  "IdPlayer": "280487",
  "IdSubPlayer": null,
  "Timestamp": "2018-06-19T12:03:58.871Z",
  "MatchMinute": "3'",
  "Period": 3,
  "HomeGoals": 0,
  "AwayGoals": 0,
  "Type": 3,
  "TypeLocalized": [],
  "PositionX": null,
  "PositionY": null,
  "GoalGatePositionX": null,
  "GoalGatePositionY": null,
  "GoalGatePositionZ": null,
  "VarDetail": null,
  "HomePenaltyGoals": 0,
  "AwayPenaltyGoals": 0
}

double posting

Do you guys noticed the duplicate post on slack? is it the fifa api?

Women's World Cup?

Has anyone taken a look at the FIFA API to see if this bot will work with the Women's World Cup next month?

unable to start the app

$ php worldCupNotifier.php

Fatal error: Uncaught Error: Call to undefined function curl_init() in C:\Users\nokram\Documents\salesforce\workspace\worldcup-slack-bot\worldCupNotifier.php:124
Stack trace:
#0 C:\Users\nokram\Documents\salesforce\workspace\worldcup-slack-bot\worldCupNotifier.php(219): getUrl('https://api.fif...')
#1 {main}
  thrown in C:\Users\nokram\Documents\salesforce\workspace\worldcup-slack-bot\worldCupNotifier.php on line 124

#########################3
below is the php details

$ php --version
PHP 7.2.7 (cli) (built: Jun 19 2018 23:13:48) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Add VAR support

Event type 71 seems to be VAR activity. It may be for several things like: incident being investigated, incident referred for review, final referee decision etc. Quite hard to reverse engineer.

From some examples I've seen, potentially these are:

// VAR
const VAR_INCIDENT_GOAL = 1;
const VAR_INCIDENT_NO_GOAL = 2; // Maybe?
const VAR_INCIDENT_PENALTY = 3;
const VAR_INCIDENT_NO_PENALTY = 4;
const VAR_INCIDENT_RED_CARD = 5; // Maybe?
const VAR_INCIDENT_NO_RED_CARD = 6;

const VAR_REASON_OFFSIDE = 1; // Maybe?
const VAR_REASON_FOUL = 5; // Maybe?
const VAR_REASON_HANDBALL = 6; // Maybe?

const VAR_STATUS_WATCHING = 0;
const VAR_STATUS_REVIEW = 1;
const VAR_STATUS_ONFIELD_REVIEW = 2;
const VAR_STATUS_VAR_DECISION = 3;
const VAR_STATUS_ONFIELD_DECISION = 4;

const VAR_RESULT_GOAL_AWARDED = 1;
const VAR_RESULT_GOAL_DISALLOWED = 2; // Maybe?
const VAR_RESULT_PENALTY_AWARDED = 3;
const VAR_RESULT_PENALTY_REVERSED = 4;
const VAR_RESULT_YELLOW_CARD = 7; // Or at least, no red card
const VAR_RESULT_NO_CHANGE = 9;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.