-
Notifications
You must be signed in to change notification settings - Fork 0
/
tacsoc.gs
119 lines (102 loc) · 3.26 KB
/
tacsoc.gs
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
/*
* Google script to send Google Form responses to Discord via webhook
* Modified from https://github.com/Iku/Google-Forms-to-Discord for TACSoc
*/
/*************************** CONFIGURATION OPTIONS ***************************/
/* Webhook URL */
var POST_URL = "";
/* Specify the colour of the embed as 0xHEXCODE */
var COLOUR = 0x71FAD3;
/* Add the IDs of any roles you wish to mention */
var MENTION_ROLES = [
"",
];
/* Toggle if you also want to mention @here and/or @everyone */
var HERE = false;
var EVERYONE = false;
/* The following message will be sent along with the mentions */
var MESSAGE = "";
/* Discord question in form */
var discord = "What is your discord username? e.g. tacsoc#0001";
/*
* For any questions in the form you wish to display differently in the message,
* please add in the below format:
*
* "Question in form": "Question in message",
*/
var questions = {
"What is your full name?": "Name",
"What's your zID? (If not applicable, please write N/A)": "zID",
"What is the name of your educational institution or workplace?": "Institution",
"What degree are you studying?": "Degree",
"What is your e-mail?": "E-mail",
"What is your phone number? Don't worry, we won't spam you, we just need it for verification purposes.": "Phone",
};
/*****************************************************************************/
function onSubmit(e) {
var form = FormApp.getActiveForm();
var allResponses = form.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var response = latestResponse.getItemResponses();
var items = [];
var user = "";
for (var i = 0; i < response.length; i++) {
var question = response[i].getItem().getTitle().trim();
if (question === discord) {
user = response[i].getResponse();
continue;
}
if (questions[question]) {
question = questions[question]
};
var answer = response[i].getResponse();
try {
var parts = answer.match(/[\s\S]{1,1024}/g) || [];
} catch (e) {
var parts = answer;
}
if (answer === "") {
continue;
}
for (var j = 0; j < parts.length; j++) {
if (j === 0) {
items.push({
"name": question,
"value": parts[j],
"inline": false
});
} else {
items.push({
"name": question.concat(" (cont.)"),
"value": parts[j],
"inline": false
});
}
}
}
var mentions = "";
if (MENTION_ROLES.length) {
mentions += "<@&" + MENTION_ROLES.join("> <@&") + "> ";
}
if (HERE) {
mentions += "@here ";
};
if (EVERYONE) {
mentions += "@everyone ";
};
var options = {
"method": "post",
"headers": {
"Content-Type": "application/json",
},
"payload": JSON.stringify({
"content": mentions + MESSAGE,
"embeds": [{
"title": user,
"color": COLOUR,
"fields": items
}]
})
};
UrlFetchApp.fetch(POST_URL, options);
};