Created
November 28, 2017 01:14
-
-
Save serinuntius/5b5085602f0f1a317c1f4500f57dbc70 to your computer and use it in GitHub Desktop.
おい岡田Botのメイン部分(Outgoing webhocksで叩かれる)
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
require 'sinatra' | |
require 'sinatra/reloader' | |
require 'json' | |
require 'net/http' | |
require 'uri' | |
require 'redis' | |
uri = URI.parse(ENV['REDISTOGO_URL']) | |
redis = Redis.new(host: uri.host, port: uri.port, password: uri.password) | |
post '/' do | |
if %w(okada <@U1ZSV3QSU>).include?(params[:trigger_word]) | |
# タスク追加モード | |
channel_name = params[:channel_name] | |
user_name = params[:user_name] | |
channel_id = params[:channel_id] | |
puts 'timestamp' | |
timestamp = params[:timestamp].split('.').first.to_i | |
puts timestamp | |
req = { | |
channel_name: channel_name, | |
channel_id: channel_id, | |
user_name: user_name, | |
timestamp: timestamp | |
}.to_json | |
redis.multi do | |
redis.set(channel_name,req) | |
redis.expire(channel_name, 3 * 60 * 60) # 3時間で消す | |
end | |
else | |
# タスク完了モード | |
channel_name = params[:channel_name] | |
redis.del(channel_name) | |
end | |
{}.to_json | |
end | |
get '/debug' do | |
res = [] | |
keys = redis.keys('*') | |
keys.each do |key| | |
value = JSON.parse(redis.get(key)) | |
sabun_sec = Time.now - Time.at(value['timestamp']) | |
text = <<-"EOS" | |
<@U1ZSV3QSU> #{value['user_name']}さんへの返信が#{(sabun_sec/60).to_i}分経ってるのにまだです。 | |
<##{value['channel_id']}|#{value['channel_name']}> に入って返信しましょう。 | |
EOS | |
res << text | |
end | |
res.to_json | |
end | |
get '/delete' do | |
res = [] | |
keys = redis.keys('*') | |
keys.each do |key| | |
redis.del(key) | |
end | |
res.to_json | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment