Skip to content

Instantly share code, notes, and snippets.

@yasuoza
Created February 4, 2014 05:29
Show Gist options
  • Save yasuoza/8798579 to your computer and use it in GitHub Desktop.
Save yasuoza/8798579 to your computer and use it in GitHub Desktop.
require 'date-utils'
module.exports = (robot) ->
robot.respond /([^\s]*)\s?の\s?([^\s]*)\s?の運勢/i, (msg) ->
dateArgs = msg.match[1]
signArgs = msg.match[2]
date = switch dateArgs
when '昨日'
Date.yesterday()
when '今日'
Date.today()
when '明日'
Date.tomorrow()
else
new Date(Date.parse(args))
sign = switch signArgs
when /おひつじ/
'牡羊座'
when /おうし/
'牡牛座'
when /ふたご/
'双子座'
when /かに/
'蟹座'
when /しし/
'獅子座'
when /おとめ/
'乙女座'
when /てんびん/
'天秤座'
when /さそり/
'蠍座'
when /いて/
'射手座'
when /やぎ/
'山羊座'
when /みずがめ/
'水瓶座'
when /うお/
'魚座'
else
signArgs
dateStr = date.toFormat('YYYY/MM/DD')
msg.http("http://api.jugemkey.jp/api/horoscope/free/#{dateStr}").get() (err, res, body) ->
datas = JSON.parse(body).horoscope[dateStr]
data = (data for data in datas when data.sign == sign)[0]
message = """
#{dateStr}の#{sign}の運勢。 #{data.rank}位。
総合運: #{data.total}/5, 金銭運: #{data.money}/5, 仕事運: #{data.job}/5, 愛情運: #{data.love}/5, ラッキーカラー: #{data.color}
#{data.content}
"""
msg.reply message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment