Last active
July 4, 2016 01:42
-
-
Save ya-ma-cho/8a34e3ece3842386ac44d4fc92195a4e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function irucaAutoLogout() { | |
var iruca_room_code = "XXX"; | |
var slack_url = "https://hooks.slack.com/services/XXX/XXX/XXX"; | |
var data = JSON.parse(UrlFetchApp.fetch("https://iruca.co/api/rooms/" + iruca_room_code + "/members", {'method':'get', 'muteHttpExceptions':true})); | |
var update_flg = false; | |
var urlFetchOption = {}; | |
var update_members = ""; | |
for each (var user in data) { | |
if(user.status=="在席"||user.status=="取込中"||user.status=="外出"){ | |
update_flg = true; | |
urlFetchOption = { | |
method:'put', | |
payload:{name:user.name, status:"離席", message:"強制離席 m9(^Д^)"}, | |
muteHttpExceptions:true | |
}; | |
UrlFetchApp.fetch("https://iruca.co/api/rooms/" + iruca_room_code + "/members/" + user.id, urlFetchOption); | |
update_members += "@"+user.name+" "; | |
} | |
} | |
var body = ""; | |
if(update_flg){ | |
body = update_members + "夜も更けておりますので、強制的に「離席」にしました。まだ残られている方は明日以降の作業をご検討ください。"; | |
}else{ | |
body = "・・・おや?誰もいないようだ。"; | |
} | |
var options = { | |
"method":"POST", | |
"contentType":"application/json", | |
"headers" : {"Accept":"application/json", "Content-Type":"application/json", "Authorization":"Basic _authcode_"}, | |
"payload" : JSON.stringify({"username":"離席太郎", "text":body, "icon_emoji":":full_moon_with_face:", "link_names":1}) | |
}; | |
UrlFetchApp.fetch(slack_url, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment