-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddUser.gs
40 lines (39 loc) · 1.12 KB
/
AddUser.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
//user yang pernah akses bot (klik command /start)
function saveUser(from) {
var rownum = getUserRow(from.id);
if (rownum == 0) {
var datauser = [
[
from.id, from.username, from.first_name, 0
]
];
var rangeName = 'USER!A2:D';
var valueRange = Sheets.newValueRange();
valueRange.values = datauser;
var result = Sheets.Spreadsheets.Values.append(valueRange, SheetID, rangeName, { valueInputOption: 'USER_ENTERED' });
} else {
var datauser = [
[
from.id, from.username, from.first_name
]
];
var rangeName = 'USER!A' + rownum + ':C' + rownum;
var valueRange = Sheets.newValueRange();
valueRange.values = datauser;
var result = Sheets.Spreadsheets.Values.update(valueRange, SheetID, rangeName, { valueInputOption: 'USER_ENTERED' });
}
}
function getUserRow(userid) {
var rangeName = 'USER!A2:D';
var users = Sheets.Spreadsheets.Values.get(SheetID, rangeName).values;
if (!users) {
return 0;
} else {
for (var row = 0; row < users.length; row++) {
if (users[row][0] == userid) {
return row + 2;
}
}
return 0;
}
}