-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
109 lines (94 loc) · 2.62 KB
/
app.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
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
const request = require("request");
const fs = require("fs");
const {
webhooks,
groupId,
ROBLOSECURITY,
checkInterval,
overridePfp,
disableMentions,
colors,
overrideName
} = require("./config");
async function main() {
request(
`https://groups.roblox.com/v1/groups/${groupId}`,
ROBLOSECURITY !== ""
? {
headers: {
Cookie: `.ROBLOSECURITY=${ROBLOSECURITY}`
}
}
: {},
async (err, {}, body) => {
if (err) throw err;
body = JSON.parse(body);
if (!body.shout) {
console.error(
"I cannot view the shout. Please add a .ROBLOSECURITY token to the config file for a user that is in the group."
);
process.exit(1);
}
let groupName = body.name;
let shouter = body.shout.poster.username;
let shouterId = body.shout.poster.userId;
let shout = body.shout.body;
let createdAt = body.shout.updated;
if (!fs.existsSync(".lastPostDate"))
await fs.writeFileSync(".lastPostDate", Date.parse(createdAt));
let lastPost = await fs.readFileSync(".lastPostDate", "utf8");
if (Date.parse(createdAt) === Number(lastPost)) return;
await fs.writeFileSync(".lastPostDate", Date.parse(createdAt));
let thumbnail = await getThumbnail(groupId).catch(console.error);
webhooks.forEach(webhook => {
request.post(webhook, {
json: true,
body: {
username: (overrideName ? `${groupName} Bot` : null),
avatar_url: ( overridePfp ? thumbnail : null ),
content: disableMentions ? null : "@here",
embeds: [
{
title: `${groupName} Notification`,
color: getRandomColor(colors),
timestamp: createdAt,
thumbnail: {
url: `https://www.roblox.com/headshot-thumbnail/image?userId=${shouterId}&width=420&height=420&format=png`
},
fields: [
{
name: "Shouted by",
value: shouter
},
{
name: "Message",
value: shout
}
]
}
]
}
}, (err) => {
if(err) console.error(err);
});
});
}
);
}
function getRandomColor(colors) {
return colors[Math.floor(Math.random() * colors.length)];
}
function getThumbnail(groupId) {
return new Promise((resolve, reject) => {
request(
`https://thumbnails.roblox.com/v1/groups/icons?format=png&groupIds=${groupId}&size=150x150`,
(err, res, body) => {
body = JSON.parse(body);
if (res.statusCode !== 200)
return reject(body.errors[0].message);
resolve(body.data[0].imageUrl);
}
);
});
}
setInterval(main, checkInterval * 1000);