-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.js
81 lines (69 loc) · 3.3 KB
/
monitor.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
const Discord = require('discord.js');
const client = new Discord.Client();
client.config = require('./settings/config.json');
client.on('ready', () => {
const guild = client.guilds.first();
const channel = guild.channels.find(c => c.name === client.config.channelName);
if(!client.users.id === client.config.botID){
console.log("\n[BOT_NOT_FOUND]: I need to be in the same guild as the bot I am monitoring.\n")
}
if(!client.config.token){
console.log("\n[NO_TOKEN_FOUND]: I cannot connect to Discord without a valid token.\n");
process.exit(1);
}
if(!client.config.botID){
console.log("\n[NO_BOT_ID_FOUND]: Please enter a BotID into my config.json.\n");
process.exit(1);
}
if(guild.length > 1){
console.log("\n[MORE_THAN_ONE_GUILD]: I can only be used in ONE_GUILD only.\n");
process.exit(1);
}
if(!guild){
console.log("\n[NO_GUILD_FOUND]: Please put me in a guild.\n");
process.exit(1);
}
if(!channel){
console.log(`\n[CHANNEL_MISSING]: I need the channel to post in to be able to function properly.\nMake sure the name is in lowercase.\n`)
process.exit(1);
}
console.log(`Bot Monitor v1.0.3 is Online.\n\nMonitoring Bot Name: ${client.user.tag}.\nMonitoring In Guild: ${guild}.\nMonitoring Posting In: ${channel.name}.`)
});
client.on('presenceUpdate', (oldMember, newMember) => {
const guild = client.guilds.first();
if (oldMember.presence.status == newMember.presence.status) return;
if (newMember.id !== client.config.botID) return;
const channel = guild.channels.find(c => c.name === client.config.channelName);
if (newMember.presence.status === 'offline') {
const embed = new Discord.RichEmbed()
.setTitle('Bot Monitor')
.setColor('GREY')
.setDescription('**Bot Is Currently Offline.**')
.setThumbnail('https://cdn.discordapp.com/attachments/506233661616816138/513747774638915584/offline.png')
.setTimestamp();
channel.send(embed)
.then(() => console.log('Bot has gone offline. Potential Crash?'))
.catch(e => console.error(e));
} else if (newMember.presence.status === 'online') {
const embed = new Discord.RichEmbed()
.setTitle('Bot Monitor')
.setColor(0x14ff1c)
.setDescription('**Everything is working as normal**')
.setThumbnail('https://cdn.discordapp.com/attachments/506233661616816138/513747775947669506/online.png')
.setTimestamp();
channel.send(embed)
.then(() => console.log('Bot is healthy and online.'))
.catch(e => console.error(e));
} else if (newMember.presence.status === 'dnd') {
const embed = new Discord.RichEmbed()
.setTitle('Bot Monitor')
.setColor('RED')
.setDescription('**Down For Maintenance**')
.setThumbnail('https://cdn.discordapp.com/attachments/506233661616816138/513747772848209921/dnd.png')
.setTimestamp();
channel.send(embed)
.then(() => console.log('Bot is down for maintenance.'))
.catch(e => console.error(e));
}
});
client.login(client.config.token);