15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/ruboty/handlers/pux.rb', line 15
def judge(message)
ruboty_sorry = 'わかんない…'
p "POST #{request_url}"
response = agent.post(request_url, params(message))
face_recognition = JSON.parse(response.body)['results']['faceRecognition']
if face_recognition['errorInfo'].nil?
message.reply(ruboty_sorry)
else
face_info = face_recognition['detectionFaceInfo'][0]
gender_info = face_info['genderJudge']['genderResult']
age = face_info['ageJudge']['ageResult'] || ruboty_sorry
animal = face_info['enjoyJudge']['similarAnimal'] || ruboty_sorry
smile = face_info['smileJudge']['smileLevel'] || ruboty_sorry
doya = face_info['enjoyJudge']['doyaLevel'] || ruboty_sorry
trouble = face_info['enjoyJudge']['troubleLevel'] || ruboty_sorry
if gender_info.nil?
gender = ruboty_sorry
else
gender = gender_info == 0 ? "おとこのこ" : "おんなのこ"
end
result_message = ''
result_message << "ねんれい: #{age}さい"
result_message << "\nせいべつ: #{gender}"
result_message << "\nどうぶつ: #{animal}"
result_message << "\nえがお: #{smile}%"
result_message << "\nどやがお: #{doya}%"
result_message << "\nこまった: #{trouble}%"
end
message.reply(result_message)
rescue Exception => e
Ruboty.logger.error(%<Error: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}>)
message.reply(ruboty_sorry)
end
|