This repository has been archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
150 lines (129 loc) · 5.46 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const { Client, RichEmbed } = require('discord.js');
const express = require("express");
const { HLTV } = require('hltv');
const client = new Client();
const app = express();
const port = 8123;
const config = require("./config.json")
// Prefix
var prefix = '*hltv ';
// Init
client.on('ready', () => {
console.log("HLTV Bot is ready!");
client.user.setActivity("ZywOo performing", {type: "WATCHING"});
let statistics = {"servers": client.guilds.size}
app.get('/', (req, res) => res.send(statistics));
});
// Help message
client.on('message', message => {
if(message.content === prefix + "help"){
const embed = new RichEmbed()
.setTitle("HLTV Bot Help")
.setURL('https://hltvbot.js.org/')
.setColor(0x3E6E9F)
.addField("Prefix", "*hltv")
.addBlankField()
.addField("teams", "Retrieve the latest top 10 ranking", true)
.addField("players", "Retrieve the top 10 players of all time", true)
.addField("player <player name>", "Retrieve informations of the given player")
.setFooter('HLTV Bot', 'https://www.hltv.org/img/static/TopSmallLogo2x.png');
message.channel.send(embed);
}
});
// Top 10 teams/players
client.on('message', message => {
if (message.content === prefix + 'teams') {
HLTV.getTeamRanking().then( (res) => {
team_ranking = res;
let top10teams = [];
for (let i = 0; i < 10; i++) {
const element = team_ranking[i];
let team = {
place: element['place'],
name: element['team']['name'],
points: element['points']
}
top10teams.push(team)
}
const embed = new RichEmbed()
.setTitle('**Latest top 10 HLTV ranking**')
.setURL('https://www.hltv.org/ranking/teams/')
.setColor(0x3E6E9F)
.setFooter('HLTV Bot', 'https://www.hltv.org/img/static/TopSmallLogo2x.png');
top10teams.forEach(element => {
embed.addField("**#" + element.place + " " + element.name + "**", "Points : " + element.points);
});
message.channel.send(embed);
}).catch((reason) => {
if(reason != undefined){
message.channel.send("Action couldn't be performed.").then( msg => {msg.delete(3000)})
}
});
} else if (message.content === prefix + 'players') {
HLTV.getPlayerRanking({startDate: '', endDate: ''}).then( (res) => {
player_ranking = res;
let top10players = [];
for (let i = 0; i < 10; i++) {
const element = player_ranking[i];
let player = {
place: i + 1,
name: element['name'],
rating: element['rating']
}
top10players.push(player)
}
const embed = new RichEmbed()
.setTitle('**Top 10 players of all time**')
.setURL('https://www.hltv.org/stats/players/')
.setColor(0x3E6E9F)
.setFooter('HLTV Bot', 'https://www.hltv.org/img/static/TopSmallLogo2x.png');
top10players.forEach(element => {
embed.addField("**#" + element.place + " " + element.name + "**", "Rating : " + element.rating);
});
message.channel.send(embed);
}).catch((reason) => {
if(reason != undefined){
message.channel.send("Action couldn't be performed.").then( msg => {msg.delete(3000)})
}
});
}
});
// Get Player Info
client.on('message', message => {
if (message.content.startsWith(prefix + 'player ')) {
const pName = message.content.substring(13, message.content.length);
HLTV.getPlayerByName({name: pName}).then( (res) => {
const names = res.name.split(' ');
const achiv = res.achievements;
let teamName = "";
if(res.team == undefined) {
teamName = "No team";
} else {
teamName = res.team.name;
}
const embed = new RichEmbed()
.setTitle(names[0] + ' "' + res.ign + '" ' + names[1])
.setURL('https://www.hltv.org/stats/players/'+ res.id + '/' + res.ign + ')')
.setColor(0x3E6E9F)
.setThumbnail(res.image)
.addField("Age", res.age + " years old", true)
.addField("Country", res.country.name, true)
.addField("Team", teamName, true)
.addBlankField()
.addField("Rating 2.0", res.statistics.rating, true)
.addField("Kill per Round", res.statistics.killsPerRound, true)
.addField("Headshot %", res.statistics.headshots, true)
.addBlankField()
.addField("__**Achievements**__", "[View achievements](https://www.hltv.org/player/"+ res.id +"/"+ res.ign +"#tab-achievementBox)")
.setFooter('HLTV Bot', 'https://www.hltv.org/img/static/TopSmallLogo2x.png');
message.channel.send(embed);
}).catch((reason) => {
if(reason != undefined){
message.channel.send("Action couldn't be performed.").then( msg => {msg.delete(3000)})
}
});
}
});
// Bot Token
client.login(config.token);
app.listen(port, () => console.log("HLTV Bot statistics server is ready!"));