Class: Ruboty::Actions::OpeningSentence

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/actions/opening_sentence.rb

Constant Summary collapse

AOZORA_RANDOM_BOOK_URL =
'http://aozora-api.herokuapp.com/books/random.json'

Instance Method Summary collapse

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruboty/actions/opening_sentence.rb', line 9

def call
  json = open(AOZORA_RANDOM_BOOK_URL).read rescue return
  book = JSON.parse(json) rescue return
  message = [
    "@#{message.from_name}",
    "作品名: #{book['title']}",
    book['opening_sentence'],
    book['url']
  ].join($/)
  message.reply(message)
end