Skip to content

Commit

Permalink
Worrrrrrrks
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Apr 13, 2016
1 parent 9f21adf commit 2aac331
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/lita/handlers/onewheel_automatic_pancake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,35 @@
module Lita
module Handlers
class OnewheelAutomaticPancake < Handler
config :pancake_server

route /^play (.*)$/i,
:play,
command: true,
help: {'play' => 'Play something with this text.'}

def play(response)
search_term = response.matches[0][0]
Lita.logger.debug "Search term found #{search_term}"
list_of_matches = get_matches(search_term)
chosen_one = list_of_matches.sample
Lita.logger.debug "#{list_of_matches.count} matches, chose #{chosen_one.to_s}"
play_file(chosen_one)
end

def get_matches(search_term)
Lita.logger.debug "searching #{config.pancake_server}/search for {query: #{search_term}}"
response = RestClient.post "#{config.pancake_server}/search", {query: search_term}
# Lita.logger.debug "Response: #{response}"
JSON.parse response
end

def play_file(chosen_one)
uri = "#{config.pancake_server}/play/#{chosen_one['id']}"
Lita.logger.debug "POST to #{config.pancake_server}/play/#{chosen_one['id']}"
RestClient.post uri, {}
end

Lita.register_handler(self)
end
end
Expand Down
1 change: 1 addition & 0 deletions lita_config.rb.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Lita.configure do |config|
config.robot.log_level = :debug
config.handlers.onewheel_automatic_pancake.pancake_server = 'http://10.44.1.222:3456'
end

0 comments on commit 2aac331

Please sign in to comment.