Created
August 2, 2012 04:48
-
-
Save raa0121/3233678 to your computer and use it in GitHub Desktop.
lingr-bot(non move)
This file contains 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
if RUBY_VERSION < '1.9' | |
require 'rubygems' | |
end | |
require 'sinatra' | |
require 'json' | |
def sandbox(&code) | |
proc { | |
$SAFE = 2 | |
eval &code | |
}.call | |
end | |
get '/' do | |
"Here is raa0121's sinatra app" | |
end | |
post '/' do | |
content_type :text | |
json = JSON.parse(request.body.string) | |
json["events"].map do |e| | |
if e["message"] | |
m = e["message"]["text"] | |
if /^!?\s(.*)/ =~ m | |
x = Thread.start do | |
$SAFE = 2 | |
eval $1.to_s | |
end | |
x.value | |
#sandbox{$1} | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment