Skip to content

Commit e02bda8

Browse files
authored
Merge pull request #54 from fb-sean/main
Added a little keepAlive system
2 parents 9b17b39 + 2575d0d commit e02bda8

5 files changed

Lines changed: 165 additions & 5 deletions

File tree

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ DEVELOPERSDUNGEON=
77
TOPGGTOKEN=
88
WEBHOOK=
99
WEBHOOKTOKEN=
10-
WEBHOOKVOTE=
10+
WEBHOOKVOTE=
11+
WARNWEBHOOKURL=
12+
ERRORWEBHOOKURL=

src/events/ready.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = async (client) => {
6464
activities: [{ name: `${process.env.BOTSTATUS || 'Would you?'}` }],
6565
status: 'dnd',
6666
});
67-
}, 15000);
67+
}, 60 * 60 * 1000); // Do this not so often because everytime you set the presence the bot won't receive any events for some seconds
6868

6969
await require('../util/dailyMsgs')(client);
7070
};

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const client = new Client({
1111
});
1212

1313
const wouldyouComponents = async () => {
14+
require('./util/keepAlive')(client);
1415
await require('./util/wouldyouClient')(client);
1516
await require('./util/dbHandler');
1617
await require('./util/voteLogs');

src/util/keepAlive.js

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
require('dotenv')
2+
.config();
3+
4+
const {
5+
WebhookClient,
6+
MessageEmbed,
7+
} = require('discord.js');
8+
9+
const { inspect } = require('util');
10+
11+
const warnWebhook = new WebhookClient({
12+
url: process.env.WARNWEBHOOKURL,
13+
});
14+
const errorWebhook = new WebhookClient({
15+
url: process.env.ERRORWEBHOOKURL,
16+
});
17+
18+
module.exports = (client) => {
19+
client.on('debug', (e) => {
20+
if (!e.includes('ratelimit')) return;
21+
22+
console.log('[BOT] Watch-out Possible Rate-limit...\n', e);
23+
const embed = new MessageEmbed()
24+
.setTitle('Watch-out Possible Rate-limit...')
25+
.addFields([{
26+
name: 'Info',
27+
value: `\`\`\`${inspect(e, { depth: 0 })}\`\`\``,
28+
}])
29+
.setTimestamp();
30+
31+
warnWebhook
32+
.send({
33+
embeds: [embed],
34+
})
35+
.catch((err) => {
36+
});
37+
});
38+
39+
client.on('error', (e) => {
40+
console.log('[BOT] Bot got a error...\n\n', e);
41+
const embed = new MessageEmbed()
42+
.setTitle('Bot got a error...')
43+
.addFields([{
44+
name: 'Error',
45+
value: `\`\`\`${inspect(e, { depth: 0 })}\`\`\``,
46+
}])
47+
.setTimestamp();
48+
49+
errorWebhook
50+
.send({
51+
embeds: [embed],
52+
})
53+
.catch((err) => {
54+
});
55+
});
56+
57+
client.on('warn', async (info) => {
58+
console.log('[BOT] Bot got a warn...\n\n', info);
59+
const embed = new MessageEmbed()
60+
.setTitle('Bot got a warn...')
61+
.addFields([{
62+
name: 'Info',
63+
value: `\`\`\`${inspect(info, { depth: 0 })}\`\`\``,
64+
}])
65+
.setTimestamp();
66+
67+
warnWebhook
68+
.send({
69+
embeds: [embed],
70+
})
71+
.catch((err) => {
72+
});
73+
});
74+
75+
process.on('unhandledRejection', async (reason, p) => {
76+
console.log('[BOT | FATAL ERROR] Unhandled Rejection/Catch');
77+
console.log(reason, p);
78+
79+
const embed = new MessageEmbed()
80+
.setTitle('New Unhandled Rejection/Catch')
81+
.setDescription(`\`\`\`${reason}\`\`\``)
82+
.setColor('#4E5D94')
83+
.addFields([
84+
{
85+
name: 'Reason',
86+
value: `\`\`\`${inspect(reason, { depth: 0 })}\`\`\``,
87+
},
88+
{
89+
name: 'Promise',
90+
value: `\`\`\`${inspect(p, { depth: 0 })}\`\`\``,
91+
},
92+
])
93+
.setTimestamp();
94+
95+
errorWebhook
96+
.send({
97+
embeds: [embed],
98+
})
99+
.catch((err) => {
100+
});
101+
});
102+
103+
process.on('uncaughtException', async (err, origin) => {
104+
console.log('[BOT | FATAL ERROR] Uncaught Exception/Catch');
105+
console.log(err, origin);
106+
107+
const embed = new MessageEmbed()
108+
.setTitle('New uncaughtException')
109+
.setDescription(`\`\`\`${err}\`\`\``)
110+
.setColor('#4E5D94')
111+
.addFields([
112+
{
113+
name: 'Error',
114+
value: `\`\`\`${inspect(err, { depth: 0 })}\`\`\``,
115+
},
116+
{
117+
name: 'Origin',
118+
value: `\`\`\`${inspect(origin, { depth: 0 })}\`\`\``,
119+
},
120+
])
121+
.setTimestamp();
122+
123+
errorWebhook
124+
.send({
125+
embeds: [embed],
126+
})
127+
.catch((err) => {
128+
});
129+
});
130+
process.on('uncaughtExceptionMonitor', async (err, origin) => {
131+
console.log('[BOT | FATAL ERROR] Uncaught Exception/Catch (MONITOR)');
132+
console.log(err, origin);
133+
134+
const embed = new MessageEmbed()
135+
.setTitle('New uncaughtExceptionMonitor' + `${global?.CustomBot ? ' (Custom Bot)' : ''}`)
136+
.setDescription(`\`\`\`${err}\`\`\``)
137+
.setColor('#4E5D94')
138+
.addFields([
139+
{
140+
name: 'Error',
141+
value: `\`\`\`${inspect(err, { depth: 0 })}\`\`\``,
142+
},
143+
{
144+
name: 'Origin',
145+
value: `\`\`\`${inspect(origin, { depth: 0 })}\`\`\``,
146+
},
147+
])
148+
.setTimestamp();
149+
150+
errorWebhook
151+
.send({
152+
embeds: [embed],
153+
})
154+
.catch((err) => {
155+
});
156+
});
157+
};

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ axios@^0.27.2:
260260
form-data "^4.0.0"
261261

262262
axios@^0.27.3:
263-
version "1.1.2"
264-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.2.tgz#8b6f6c540abf44ab98d9904e8daf55351ca4a331"
265-
integrity sha512-bznQyETwElsXl2RK7HLLwb5GPpOLlycxHCtrpDR/4RqqBzjARaOTo3jz4IgtntWUYee7Ne4S8UHd92VCuzPaWA==
263+
version "1.2.1"
264+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.1.tgz#44cf04a3c9f0c2252ebd85975361c026cb9f864a"
265+
integrity sha512-I88cFiGu9ryt/tfVEi4kX2SITsvDddTajXTOFmt2uK1ZVA8LytjtdeyefdQWEf5PU8w+4SSJDoYnggflB5tW4A==
266266
dependencies:
267267
follow-redirects "^1.15.0"
268268
form-data "^4.0.0"

0 commit comments

Comments
 (0)