-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.js
37 lines (30 loc) · 1.19 KB
/
logging.js
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
const { google } = require("googleapis");
const { convertToObjects } = require("./utils/utils");
exports.logData = async (payload, auth) => {
const spreadsheetId = "10GrZcNEavKKv2QlVt-yd3HxEvL7iyF4v-jBdPVAfj5U";
const range = "Bot Logs!A2:F";
const valueInputOption = "USER_ENTERED";
// Payload expected layout (matches columns in sheet)
// Date, User, Command Type, Command, Options, Server, Result
// const resource = { values: [[new Date(), "User", "Slash", "Command", "Options", "Server", "Result"]] }
// Note that it is a nested array ( [[ <<content>> ]] )
const resource = { values: payload };
const sheets = google.sheets({ version: "v4", auth });
try {
// Do not record bot creator's command logs (due to excessive testing)
// This is hard-coded and not that great but it'll hopefully suffice for now
if (resource.values[0][1] === "Altivu") return;
await sheets.spreadsheets.values.append({
spreadsheetId,
range,
valueInputOption,
resource,
}),
(err, _res) => {
if (err) return console.error(err);
};
} catch (err) {
console.log(err);
}
return;
}