forked from SundayMC/hetrixstatus-discordbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
119 lines (103 loc) · 3.19 KB
/
index.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
110
111
112
113
114
115
116
117
118
119
const {
serviceName,
pageLink,
guildId,
channelId,
messageId,
updateInterval,
} = require("./config.json");
const { Client, GatewayIntentBits, EmbedBuilder } = require("discord.js");
const puppeteer = require("puppeteer-extra");
const process = require("process");
const statusName = `${serviceName} Status`;
const statusColor = "#3F51B5";
async function updateStatus() {
await getScreenshot();
await new Promise((resolve) => setTimeout(resolve, 6000));
let embed = new EmbedBuilder()
.setColor(statusColor)
.setTitle(statusName)
.setURL(pageLink)
.setAuthor({
name: serviceName,
iconURL: client.guilds.cache.get(guildId).iconURL({ dynamic: true }),
url: pageLink,
})
.setImage("attachment://screen.png")
.setTimestamp();
const timeStamp = Math.floor(Date.now() / 1000) + updateInterval + 9;
const formattedTimeStamp = `<t:${timeStamp}:R>`;
client.channels.cache
.get(channelId)
.messages.fetch(messageId)
.then((msg) =>
msg.edit({
content: `Next update ${formattedTimeStamp}`,
embeds: [embed],
files: ["./screen.png"],
})
);
}
async function getScreenshot() {
puppeteer
.launch({
headless: true,
executablePath: process.env.CHROME_PATH,
ignoreDefaultArgs: ["--disable-extensions"],
args: ["--no-sandbox", "--disable-setuid-sandbox"],
})
.then(async (browser) => {
const page = await browser.newPage();
await page.setViewport({ width: 1820, height: 1024 });
await page.goto(pageLink);
await page.waitForTimeout(3500);
await page.screenshot({ path: "screen.png", fullPage: true });
await browser.close();
});
}
const client = new Client({
intents: [
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
],
});
client.on("ready", async () => {
console.log("Discord client is ready.");
if (!messageId) {
console.log(
"Initial message ID was not set. Creating a new message with the embed."
);
const initialEmbed = new EmbedBuilder()
.setColor(statusColor)
.setTitle(statusName)
.setURL(pageLink)
.setAuthor({
name: statusName,
iconURL: client.guilds.cache.get(guildId).iconURL({ dynamic: true }),
url: pageLink,
});
await client.channels.cache.get(channelId).send({ embeds: [initialEmbed] });
}
await updateStatus();
setInterval(async function () {
await updateStatus();
}, updateInterval * 1000);
});
client.login(process.env.DISCORD_TOKEN);