-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
118 lines (105 loc) · 3.41 KB
/
commands.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
const memberManager = require("./db/memberManager");
const Discord = require("discord.js");
const TeamCaptainManager = require("./util/TeamCaptainManager");
const hardIDs = require("./util/hardIDs");
const compCaptainRoleIds = hardIDs.compCaptainRoleIds;
const compVcIds = hardIDs.compVcIds;
const scrimCaptainRoleIds = hardIDs.scrimCaptainRoleIds;
const scrimVcIds = hardIDs.scrimVcIds;
module.exports = client => {
let server = client.guilds.cache.get("833801666557247528");
const commandsList = ["playerinfo", "captain"];
client.on("message", msg => {
if (!msg.content.startsWith("!") || msg.author.bot) return;
const args = msg.content.slice(1).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!commandsList.includes(command)) return;
if (!args) return;
if (command === "playerinfo") getPLayerInfo(msg, args, server);
if (command === "captain") TeamCaptainManager.addTempTeamCaptain(msg, args, server);
});
client.on("voiceStateUpdate", (oldState, newState) => {
if (
oldState.channel &&
newState.channel &&
oldState.channel !== newState.channel
)
TeamCaptainManager.removeCaptain(oldState, newState);
else if (oldState.channel && !newState.channel) TeamCaptainManager.removeCaptain(oldState, newState);
});
};
function getPLayerInfo(msg, args, server) {
let tagged = false;
let userId = "";
if (args.length !== 1) {
msg.channel.send("Inavlid Usage! !playerinfo @username");
return;
}
if (args[0].charAt(0) == "<") {
userId = args[0].slice(3, -1);
tagged = true;
}
server.members
.fetch(tagged ? userId : { query: args[0], limit: 1 })
.then(members => {
const member = tagged ? members : members.first();
if (typeof member !== "undefined") {
memberManager
.getById(member.id)
.then(memberInfo => {
if (memberInfo) {
let embed = createPlayerInfoEmbed(memberInfo, member);
msg.channel.send(embed);
} else {
msg.channel.send(
"That person hasn't completed the registration process yet!"
);
}
})
.catch(err => {
console.log(err);
});
} else {
msg.channel.send("There is no one by that username in this server!");
}
})
.catch(err => {
console.log(err);
});
}
function createPlayerInfoEmbed(memberInfo, member) {
let ranks = [
"iron",
"bronze",
"silver",
"gold",
"platinum",
"diamond",
"immortal",
"radiant",
];
let embed = new Discord.MessageEmbed()
.setColor(member.displayHexColor)
.setTitle(`@${memberInfo.tag}`)
.setDescription("Player Information")
.addFields(
{ name: "Grade: ", value: `${memberInfo.grade}th` },
{ name: "School: ", value: `${memberInfo.school.toUpperCase()}` }
)
.setThumbnail(member.user.avatarURL())
.setTimestamp()
.setFooter("(Dev'd by [email protected])");
if (memberInfo.valorant.active) {
embed.addFields(
{ name: "IGN", value: `${memberInfo.valorant.ign}` },
{
name: "Rank",
value: `${
ranks[memberInfo.valorant.rank].charAt(0).toUpperCase() +
ranks[memberInfo.valorant.rank].slice(1)
}`,
}
);
}
return embed;
}