                 channel = stream.channel
                 msg.send "#{channel.display_name} (\"#{channel.status}\") - #{channel.url} [Viewers: #{stream.viewers}]"
 
-            if object._total > 5
-                msg.reply "There are #{object._total - 5} other \"#{category}\" live streams."
+            if object._total > maxResults
+                msg.reply "There are #{object._total - maxResults} other \"#{category}\" live streams."
 
-    robot.respond /ttv featured/i, (msg) ->
-        twitch_request msg, '/streams/featured', { limit: 5 }, (object) ->
-            for feature in object.featured
-                channel = feature.stream.channel
-                msg.send "#{feature.stream.game}: #{channel.display_name} (#{channel.status}) - #{channel.url} [Viewers: #{feature.stream.viewers}]"
+    robot.respond /ttv search (.*)/i, (msg) ->
+        query = msg.match[1]
+        twitch_request msg, "/search/streams", { q: query, limit: maxResults }, (object) ->
+            if object._total is 0
+                msg.reply "No live streams were found using search query: \"#{query}\". Try a different query or try again later."
+                return
+
+            for stream in object.streams
+                channel = stream.channel
+                msg.send "#{channel.display_name} (\"#{channel.status}\") - #{channel.url} [Viewers: #{stream.viewers}]"
+
+            if object._total > maxResults
+                msg.reply "There are #{object._total - maxResults} other live streams matching your search query: \"#{query}\"."
 
     robot.respond /ttv stream (.*)/i, (msg) ->
         twitch_request msg, "/streams/#{msg.match[1]}", null, (object) ->

#

module.exports = (robot) ->
    robot.respond /ttv game (.*)/i, (msg) ->
        category = msg.match[1]
        twitch_request msg, '/streams', { game: category, limit: 5 }, (object) ->
            if object._total is 0
                msg.reply "No live streams were found in \"#{category}\". Try a different category or try again later."
                return

#   None
#
# Commands:
#   hubot ttv featured - Returns the first 5 featured live streams
#   hubot ttv game <category> - Returns the first 5 live streams in a game <category> (case-sensitive)
#   hubot ttv search <query> - Returns the first 5 live streams matching the search <query>
#   hubot ttv stream <name> - Returns information about stream <name>
#   hubot ttv top - Returns the top 5 games sorted by the number of current viewers on Twitch, most popular first
#
# Author:
#   MrSaints
