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
const ChannelAction = require('./ChannelAction.js');
class SendPlayerRankMessageAction extends ChannelAction {
constructor() {
super((hg, game, channel) => {
const current = game.currentGame;
const rankEmbed = new hg._parent.Discord.EmbedBuilder();
rankEmbed.setColor([255, 0, 255]);
rankEmbed.setTitle('Final Ranks (kills)');
const rankList =
current.includedUsers.sort((a, b) => a.rank - b.rank).map((obj) => {
let shortName;
if (obj.nickname && game.options.useNicknames) {
shortName = obj.nickname.substring(0, 16);
if (shortName != obj.nickname) {
shortName = `${shortName.substring(0, 13)}...`;
}
} else {
shortName = obj.name.substring(0, 16);
if (shortName != obj.name) {
shortName = `${shortName.substring(0, 13)}...`;
}
}
shortName = shortName.replace(/_/g, '\\_');
const kills = obj.kills > 0 ? ` (${obj.kills})` : '';
return `${obj.rank}) ${shortName}${kills}`;
});
if (rankList.length == 0) {
return;
} else if (rankList.length <= 20) {
rankEmbed.setDescription(rankList.join('\n'));
} else if (rankList.length > 100) {
rankList.splice(100);
const thirdLength = Math.floor(rankList.length / 3);
for (let i = 0; i < 2; i++) {
const thisMessage =
rankList.splice(0, thirdLength).join('\n').slice(0, 1024);
rankEmbed.addFields([{name: `${i + 1}`, value: thisMessage}]);
}
rankEmbed.addFields(
[{name: '3', value: rankList.join('\n').slice(0, 1024)}]);
} else {
const thirdLength = Math.floor(rankList.length / 3);
for (let i = 0; i < 2; i++) {
const thisMessage =
rankList.splice(0, thirdLength).join('\n').slice(0, 1024);
rankEmbed.addFields([{name: `${i + 1}`, value: thisMessage}]);
}
rankEmbed.addFields(
[{name: '3', value: rankList.join('\n').slice(0, 1024)}]);
}
if (!game.options.disableOutput) {
channel.send({embeds: [rankEmbed]}).catch((err) => {
hg._parent.error(`Failed to send ranks message: ${channel.id}`);
console.error(err);
});
}
}, 5000);
}
static create() {
return new SendPlayerRankMessageAction();
}
}
module.exports = SendPlayerRankMessageAction;