Created
August 19, 2016 20:16
-
-
Save Xibanya/0552eb25e5a20cceb83843d9892ab364 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'open-uri' | |
| require 'nokogiri' | |
| get '/' do | |
| 'Congrats, you did a GET' | |
| status 200 | |
| headers \ | |
| 'Content-Type' => 'application/json' | |
| body '{"response_type": "in_channel","text": "It works!"}' | |
| end | |
| get '/emote' do | |
| page = Nokogiri::HTML(open('http://forums.somethingawful.com/misc.php?action=showsmilies')) | |
| search = ':' + params['text'] + ':' | |
| items = page.css('div.text') | |
| items.each do |item| | |
| if item.text =~ /#{search}/ | |
| headers \ | |
| 'Content-Type' => 'application/json' | |
| body '{"response_type": "in_channel","text": "' + item.next_element['src'].to_s + '"}' | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment