-
Notifications
You must be signed in to change notification settings - Fork 0
/
userinfo.js
31 lines (31 loc) · 846 Bytes
/
userinfo.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
#!/usr/bin/env node
const fs = require("fs");
var inp = "";
try {
inp = fs.readFileSync(process.argv[2]+".ogg.users", "utf8");
} catch (ex) {}
var users = {};
try {
users = JSON.parse("{" + inp + "}");
} catch (ex) {
// Old-style, just an array
try {
users = JSON.parse("[" + inp + "]");
} catch (ex) {}
}
var n = parseInt(process.argv[3], 10);
var val = users[n] ? users[n] : "";
if (process.argv[4]) {
var param = process.argv[4];
val = val[param] ? val[param] : "";
} else if (typeof val === "object") {
val = val.tag;
val = val.replace(/[^a-zA-Z0-9]/g, "_");
}
if (process.argv[5] === "datauri" && val.startsWith("data:"))
val = Buffer.from(val.split(",")[1], "base64");
process.stdout.write(val);
process.stdout.end();
process.stdout.on("finish", () => {
process.exit((val==="")?1:0);
});