-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.gs
More file actions
139 lines (119 loc) · 3.53 KB
/
main.gs
File metadata and controls
139 lines (119 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*spreadsheet取得*/
function getData(){
const sheet = SpreadsheetApp.getActiveSheet();
let data = sheet.getDataRange().getValues();
let keys = data.splice(0, 1)[0];
/*1行目をkeyとして取得、オブジェクト生成*/
return data.map(function(row) {
var obj = {}
row.map(function(item, index) {
obj[keys[index]] = item;
});
return obj;
});
}
/*spreadsheet更新日時取得*/
function getLastDate(){
let data = getData();
/*date取り出し*/
const date = data.map(function(object){
return object.タイムスタンプ;
});
return date[date.length - 1].getTime();
}
/*タイムテーブルの時間帯に更新があったか*/
function judgeSheet(){
/*ex)現在22:33の時22:00を取得(gettimeはミリ秒)*/
let justTime = new Date();
justTime.setMinutes(0);
justTime.setSeconds(0);
console.log(justTime.getTime() - getLastDate());
if(justTime.getTime() - getLastDate() <= 3600000 && justTime.getHours() >= 9 && justTime.getTime() - getLastDate() > 0){
return "day";
}
else if(justTime.getTime() - getLastDate() <= 28800000 && justTime.getHours() == 8 && justTime.getTime() - getLastDate() > 0){
return "night";
}
else{
return false;
}
}
function payLoadTemplate(){
let data = getData();
let counts = [
{ count: 0, name: 'アカウントについて'},
{ count: 0, name: 'バグ報告' },
{ count: 0, name: '新機能提案'},
{ count: 0, name: 'その他'}
];
console.log(data);
/**
* =====================================================
*
* init variable start
*/
/*ex)現在11:33の時11:00を取得*/
let justTime = new Date();
justTime.setMinutes(0);
justTime.setSeconds(0);
/*ex)現在11:33の時10:00を取得*/
let beforeTime = new Date();
beforeTime.setMinutes(0);
beforeTime.setSeconds(0);
beforeTime.setHours(beforeTime.getHours() - 1);
/* init variable finish */
/*新規オブジェクト取り出し(1時間以内)*/
data = data.filter(function(obj){
const timestamp = obj.タイムスタンプ.getTime()
const diff = justTime.getTime() - timestamp
return 0 < diff && diff <= 3600000;
});
/*バグ報告のオブジェクトを取りだし*/
const bugObj = data.filter(function(obj) {
return obj[CATEGORY] === NOTIFICATION;
});
/*件数取得*/
for(let d of data){
for (let c of counts) {
if (d[CATEGORY] === c.name) {
c.count++;
break;
}
}
}
/*slackに流す文章*/
let strBody = formatDate(new Date(), 'MM/dd HH:mm') + "\n";
strBody += formatDate(beforeTime, 'HH:mm') + "~" + formatDate(justTime, 'HH:mm') + "\n";
for (let c of counts) {
if (c.count > 0) {
strBody += c.name +": "+ c.count + "件\n";
}
}
strBody += "\n";
for(let i = 1; i <= bugObj.length; i++){
strBody += NOTIFICATION + "の内容 " + i + "\n";
strBody += bugObj[i-1].お問い合わせ内容_件名 + "\n";
}
return strBody;
}
function sendSlack(){
const url = "";
const payload = { "text" : payLoadTemplate()};
const payloadNight = { "text" : payLoadTemplateNight()};
const options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload)
};
const optionsNight = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payloadNight)
};
if(judgeSheet() === "day"){
var response = UrlFetchApp.fetch(url, options);
}
else if(judgeSheet() === "night"){
var response = UrlFetchApp.fetch(url, optionsNight);
}
}