Skip to content

Instantly share code, notes, and snippets.

@Xibanya
Created August 19, 2016 20:16
Show Gist options
  • Save Xibanya/0552eb25e5a20cceb83843d9892ab364 to your computer and use it in GitHub Desktop.
Save Xibanya/0552eb25e5a20cceb83843d9892ab364 to your computer and use it in GitHub Desktop.
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