Skip to content

Instantly share code, notes, and snippets.

@thvinmei
Last active October 22, 2022 17:10
Show Gist options
  • Save thvinmei/399df916ce10e7906ed546a689f0abb6 to your computer and use it in GitHub Desktop.
Save thvinmei/399df916ce10e7906ed546a689f0abb6 to your computer and use it in GitHub Desktop.
Slackに筋肉体操からランダムな1つを選択して投稿するスクリプト
var properties = PropertiesService.getScriptProperties();
function Kinniku2Slack() {
// Google App Script で実行
// 実行時にNHKの「筋肉体操」からランダムに1つ選んで
// Slackの指定チャンネルに書き込む。
var yesterday = loadCount()
//番組数までの乱数生成
var today = Math.floor( Math.random() * 4 );
//前回と同じものが選ばれた場合は再選択
while (yesterday == today){
today = Math.floor( Math.random() * 4 );
}
var Body;
var Url;
var Name;
switch ( today ) {
case 0:
Body = "腕立て伏せ ~厚い胸板を作る~"
Url = "https://www.youtube.com/watch?v=WndOChZSjTk"
break;
case 1:
Body = "腹筋 ~凹凸ある腹筋を目指す~"
Url = "https://www.youtube.com/watch?v=1GanGLmDt2I"
break;
case 2:
Body = "スクワット ~強靭な足腰を作る~"
Url = "https://www.youtube.com/watch?v=PyJOEt2nsGQ"
break;
case 3:
Body = "背筋 ~語れる男の背中を作る~"
Url = "https://www.youtube.com/watch?v=IHYOhDe4FB8"
break;
default:
Body = "今日はお休み"
Url = ""
}
Name = "今日の「筋肉体操」"
var data={
"text":Body +"\n\n" + Url,
"username": Name,
"icon_emoji" : ":man_climbing::skin-tone-3:"
}
var options =
{
"method" : "POST",
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
// SlackのIncoming WebhookのURLを取得して入力
UrlFetchApp.fetch("https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXX", options);
saveCount(today)
}
function loadCount() {
var count = properties.getProperty("Count");
if (!count) return 0;
return parseInt(count, 10);
}
function saveCount(count) {
properties.setProperty("Count", count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment