Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added support for nfl/nba/nhl teams

  • Loading branch information...
commit 4441c96ecf326e82d24205076544ca8ccad4470d 1 parent a2541ab
Mike Wilcox authored

Showing 1 changed file with 45 additions and 3 deletions. Show diff stats Hide diff stats

  1. +45 3 src/scripts/espn.coffee
48 src/scripts/espn.coffee
... ... @@ -1,5 +1,5 @@
1 1 # Description:
2   -# Grab a headline from ESPN through querying hubot
  2 +# Grab headlines and MLB/NFL/NBA/NHL team home pages from ESPN
3 3 #
4 4 # Dependencies:
5 5 # None
@@ -9,7 +9,10 @@
9 9 #
10 10 # Commands:
11 11 # hubot espn headline - Displays a random headline from ESPN.com
12   -# hubot espn mlb <name of team> - Displays ESPN.com team homepage
  12 +# hubot espn mlb <name of team> - Displays ESPN.com MLB team homepage
  13 +# hubot espn nfl <name of team> - Displays ESPN.com NFL team homepage
  14 +# hubot espn nba <name of team> - Displays ESPN.com NBA team homepage
  15 +# hubot espn nhl <name of team> - Displays ESPN.com NHL team homepage
13 16 #
14 17 # Author:
15 18 # mjw56
@@ -36,7 +39,7 @@ module.exports = (robot) ->
36 39 rnd = Math.floor(Math.random()*urls.length)
37 40 msg.send urls[rnd]
38 41
39   - robot.respond /(espn)( mlb)? (.*)/i, (msg) ->
  42 + robot.respond /(espn)( mlb) (.*)/i, (msg) ->
40 43 msg.http('http://api.espn.com/v1/sports/baseball/mlb/teams?apikey=' + espnApiKey)
41 44 .get() (err, res, body) ->
42 45 result = JSON.parse(body)
@@ -48,3 +51,42 @@ module.exports = (robot) ->
48 51
49 52 if team is input || city is input
50 53 msg.send 'Team news for the '+ child.location + ' ' + child.name + '- ' + child.links.web.teams.href
  54 +
  55 + robot.respond /(espn)( nfl) (.*)/i, (msg) ->
  56 + msg.http('http://api.espn.com/v1/sports/football/nfl/teams?apikey=' + espnApiKey)
  57 + .get() (err, res, body) ->
  58 + result = JSON.parse(body)
  59 +
  60 + for child in result.sports[0].leagues[0].teams
  61 + team = child.name.toLowerCase()
  62 + city = child.location.toLowerCase()
  63 + input = msg.match[3].toLowerCase()
  64 +
  65 + if team is input || city is input
  66 + msg.send 'Team news for the '+ child.location + ' ' + child.name + '- ' + child.links.web.teams.href
  67 +
  68 + robot.respond /(espn)( nba) (.*)/i, (msg) ->
  69 + msg.http('http://api.espn.com/v1/sports/basketball/nba/teams?apikey=' + espnApiKey)
  70 + .get() (err, res, body) ->
  71 + result = JSON.parse(body)
  72 +
  73 + for child in result.sports[0].leagues[0].teams
  74 + team = child.name.toLowerCase()
  75 + city = child.location.toLowerCase()
  76 + input = msg.match[3].toLowerCase()
  77 +
  78 + if team is input || city is input
  79 + msg.send 'Team news for the '+ child.location + ' ' + child.name + '- ' + child.links.web.teams.href
  80 +
  81 + robot.respond /(espn)( nhl) (.*)/i, (msg) ->
  82 + msg.http('http://api.espn.com/v1/sports/hockey/nhl/teams?apikey=' + espnApiKey)
  83 + .get() (err, res, body) ->
  84 + result = JSON.parse(body)
  85 +
  86 + for child in result.sports[0].leagues[0].teams
  87 + team = child.name.toLowerCase()
  88 + city = child.location.toLowerCase()
  89 + input = msg.match[3].toLowerCase()
  90 +
  91 + if team is input || city is input
  92 + msg.send 'Team news for the '+ child.location + ' ' + child.name + '- ' + child.links.web.teams.href

0 comments on commit 4441c96

Please sign in to comment.
Something went wrong with that request. Please try again.