-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzeavelbot.js
115 lines (93 loc) · 4.41 KB
/
zeavelbot.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
const Discord = require('discord.js');
const client = new Discord.Client();
const CC = require('./command_create.js');
const Command = CC.Command;
var Commandss = new CC.Commands();
var fs = require("fs");
function commandIs(str, msg){
return msg.content.toLowerCase().startsWith("." + str);
}
function pluck(array) {
return array.map(function(item) { return item["name"]; });
}
function hasRole(mem, role)
{
if (pluck(mem.roles).includes(role))
{
return true;
}
else
{
return false;
}
}
client.on("ready", r=>{
function sec() {
var cheerio = require('cheerio');
var request = require('request');
var urle = "https://squad-servers.com/server/7124/"
request(urle, function (error, response, body) {
if (!error) {
var $ = cheerio.load(body)
var status = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-7 > table > tbody > tr:nth-child(3) > td:nth-child(2) > button").text()
var players = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-7 > table > tbody > tr:nth-child(4) > td:nth-child(2) > strong").text().trim()
if(status == "Online")
{
client.user.setActivity(players + " players", { type: "PLAYING"})
/* client.user.setPresence({ game: { name: players }, status: 'online' })
.then(console.log)
.catch(console.error);*/
}
if(status == "Offline")
{
client.user.setPresence({status: 'dnd', activity: {name: "Offline"}})
}
}})
}
setInterval(sec, 5000)
})
client.on('message', message => {
if(commandIs("info+", message))
{
var cheerio = require('cheerio');
var request = require('request');
var urle = "https://squad-servers.com/server/7124/"
request(urle, function (error, response, body) {
if (!error) {
var $ = cheerio.load(body)
var name = $("body > div.content > div > div:nth-child(3) > div > h1").text()
var status = $("body > div.content > div > div:nth-child(3) > div > div.row > div.col-12.col-md-7 > table > tbody > tr:nth-child(3) > td:nth-child(2) > button").text()
var playerss = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-7 > table > tbody > tr:nth-child(4) > td:nth-child(2) > strong").text().trim()
var map = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-7 > table > tbody > tr:nth-child(8) > td:nth-child(2) > strong").text()
var regsin = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-7 > table > tbody > tr:nth-child(9) > td:nth-child(2)").text()
var mapimg = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-5 > div:nth-child(3) > img").attr("src").replace(/[']/g, "%27").replace(/[ ]/g,"%20")
var mapimg2= "https://squad-servers.com"+mapimg
var players = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(6) > div > div").text().replace(/[,]/g,"\n")
var location = $("body > div.content > div > div:nth-child(3) > div > div:nth-child(4) > div.col-12.col-md-7 > table > tbody > tr:nth-child(5) > td:nth-child(2) > a").text()
var color;
if(status === "Online")
{
color = "#00FF00"
}
else
{
color = "#FF0000"
}
const Discord = require('discord.js')
const embed = new Discord.MessageEmbed()
.setThumbnail("https://cdn.discordapp.com/attachments/486990358455123978/523920686570405898/2_2.png")
.setTitle(name)
.setImage(mapimg2)
.addField("Players", "**"+playerss+"**")
.addField("Status", "**"+status+"**")
.addField("Location", "**"+location+"**")
.addField("Map", "**"+map+"**")
.addField("Registered since", "**"+regsin+"**")
.setColor(color)
.setFooter(players)
message.channel.send({embed})
console.log("test")
}})
}
});
client.login(process.env.BOT_TOKEN);