Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Last active April 9, 2016 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherenkov/774670edfb86f2344e10a54af4f8d5a6 to your computer and use it in GitHub Desktop.
Save cherenkov/774670edfb86f2344e10a54af4f8d5a6 to your computer and use it in GitHub Desktop.
エビ中とLINEしてる気分になれるChatBotをPictRubyで作ってみた ref: http://qiita.com/cherenkov/items/c6a744639a39a693810b
#line_like_chatbot v0.1
class Chat
def initialize
feed = "http://lineblog.me/ebichu/index.rdf"
count = 10
url = "https://query.yahooapis.com/v1/public/yql?q=SELECT%20title%2Clink%2Cencoded%20FROM%20rss%20WHERE%20url%3D%22" + URI.encode_www_form_component(feed) + "%22%20%7C%20truncate(count%3D" + count.to_s + ")&format=json"
data = Browser.json url
@menu = []
@text = []
data['query']['results']['item'].each_with_index {|item,i|
@menu.push "#{i+1}:#{item['title']}"
@text.push item['encoded']
}
@menu = @menu.join("\n")
@select_index = nil
@stdout = nil
@i = -1
end
def welcome
@menu
end
def call(input)
if @select_index == nil
@select_index = input.to_i
src = @text[@select_index-1]
url = "http://api.dan.co.jp/lleval.cgi?l=rb&s=" + URI.encode_www_form_component("p '#{src}'")+".gsub(%2F%5Cn%5Cs%2B%7C(%3Cbr%5Cs%5C%2F%3E)%2B%2F%2C%22%5Cn%22).gsub(%2F%3C(%22%5B%5E%22%5D*%22%7C'%5B%5E'%5D*'%7C%5B%5E'%22%3E%5D)*%3E%2F%2C'').gsub(%2F(%5CA%5Cn%2B%7C%5Cn%2B%5Cz)%2F%2C%22%22).split(%2F%5Cs*%5Cn%2B%5Cs*%2F)"
json = Browser.json url
@stdout = eval(json['stdout'])
@i += 1
@stdout[@i].strip
else
@i += 1
@i < @stdout.size ? @stdout[@i].strip : "おわり🍤"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment