-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
237 lines (218 loc) · 7.66 KB
/
Copy pathbot.js
File metadata and controls
237 lines (218 loc) · 7.66 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
require("dotenv").config();
const fs = require("node:fs");
const path = require("node:path");
const { TOKEN, RIOT_KEY } = process.env;
const {
GatewayIntentBits,
Client,
Events,
Collection,
AttachmentBuilder,
EmbedBuilder,
} = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.commands = new Collection();
const commandsPath = path.join(__dirname, "commands");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" of "execute" property.`
);
}
}
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.log(error);
await interaction.reply({
content: "there was an error while executing this command",
ephemeral: true,
});
}
console.log(interaction);
});
//Command to add role
//TOP 1065357331874975805
//JUNGLE 1065356753098776616
//MID 1065357011249811537
//ADC 1065357124135292969
//SUPPORT 1065357242808934500
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isStringSelectMenu()) return;
if (interaction.customId === "select") {
let selectedRoles = "";
await interaction.member.roles.cache.forEach((r) => {
if (
r.id === "1065357331874975805" ||
r.id === "1065356753098776616" ||
r.id === "1065357011249811537" ||
r.id === "1065357124135292969" ||
r.id === "1065357242808934500"
) {
interaction.member.roles.remove(r.id);
}
});
await interaction.values.forEach(async (value) => {
let role = interaction.guild.roles.cache.find(
(role) => role.name === `${value}`
);
selectedRoles += `${value} `;
interaction.member.roles.add(role);
});
interaction.reply({
content: `${interaction.user.username} has changed thier roles to ${selectedRoles}.`,
components: [],
});
}
});
//Checks summoner
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isModalSubmit()) return;
const summoner = interaction.fields.getTextInputValue("summonerNameInput");
const summonerResponse = await fetch(
"https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/" +
encodeURIComponent(summoner),
{ headers: { "X-Riot-Token": RIOT_KEY } }
).then((res) => res.json());
if (summonerResponse) {
console.log(summonerResponse);
let summonerID = summonerResponse.id;
let summonerLevel = summonerResponse.summonerLevel;
let summonerIcon = summonerResponse.profileIconId;
const leagueResponse = await fetch(
`https://na1.api.riotgames.com/lol/league/v4/entries/by-summoner/${summonerID}`,
{ headers: { "X-Riot-Token": RIOT_KEY } }
).then((res) => res.json());
if (leagueResponse) {
for (let type of leagueResponse) {
if (type.queueType === "RANKED_SOLO_5x5") {
let summonerRank = type.rank;
let summonerTier = type.tier;
let summonerWins = type.wins;
let summonerLosses = type.losses;
console.log(
summonerRank,
summonerTier,
Math.round((summonerWins / (summonerWins + summonerLosses)) * 100)
);
const image = new AttachmentBuilder(`./assets/${summonerTier}.png`);
const embed = new EmbedBuilder()
.setTitle("Summoner Info")
.setURL(
`https://www.op.gg/summoners/na/${encodeURIComponent(summoner)}`
)
.setDescription("Check if you should flame them or not")
.setColor(0x18e1ee)
.setImage(`attachment://${summonerTier}.png`)
.setThumbnail(
`http://ddragon.leagueoflegends.com/cdn/13.1.1/img/profileicon/${summonerIcon}.png`
)
.addFields([
{ name: `${summoner}`, value: "\u200B" },
{
name: `Level: ${summonerLevel}`,
value: `Solo Rank: ${summonerTier} ${summonerRank}`,
},
{ name: "Wins", value: `${summonerWins}`, inline: true },
{ name: "Losses", value: `${summonerLosses}`, inline: true },
{
name: "Percent",
value: `${Math.round(
(summonerWins / (summonerWins + summonerLosses)) * 100
)}%`,
inline: true,
},
]);
return interaction.reply({ embeds: [embed], files: [image] });
} else if (type.queueType === "RANKED_TEAM_5v5") {
let summonerRank = type.rank;
let summonerTier = type.tier;
let summonerWins = type.wins;
let summonerLosses = type.losses;
console.log(
summonerRank,
summonerTier,
Math.round((summonerWins / (summonerWins + summonerLosses)) * 100)
);
const image = new AttachmentBuilder(`./assets/${summonerTier}.png`);
const embed = new EmbedBuilder()
.setTitle("Summoner Info")
.setURL(
`https://www.op.gg/summoners/na/${encodeURIComponent(summoner)}`
)
.setDescription("Check if you should flame them or not")
.setColor(0x18e1ee)
.setImage(`attachment://${summonerTier}.png`)
.setThumbnail(
`http://ddragon.leagueoflegends.com/cdn/13.1.1/img/profileicon/${summonerIcon}.png`
)
.addFields([
{ name: `${summoner}`, value: "\u200B" },
{
name: `Level: ${summonerLevel}`,
value: `Flex Rank: ${summonerTier} ${summonerRank}`,
},
{ name: "Wins", value: `${summonerWins}`, inline: true },
{ name: "Losses", value: `${summonerLosses}`, inline: true },
{
name: "Percent",
value: `${Math.round(
(summonerWins / (summonerWins + summonerLosses)) * 100
)}%`,
inline: true,
},
]);
return interaction.reply({ embeds: [embed], files: [image] });
}
}
const embed = new EmbedBuilder()
.setTitle("Summoner Info")
.setURL(
`https://www.op.gg/summoners/na/${encodeURIComponent(summoner)}`
)
.setDescription("Check if you should flame them or not")
.setColor(0x18e1ee)
.setThumbnail(
`http://ddragon.leagueoflegends.com/cdn/13.1.1/img/profileicon/${summonerIcon}.png`
)
.addFields([
{ name: `${summoner}`, value: "\u200B" },
{
name: `Level: ${summonerLevel}`,
value: `Have no rank this season.`,
},
]);
return interaction.reply({ embeds: [embed] });
}
}
return interaction.reply({
content: `${summoner} does not exist in NA`,
ephemeral: true,
});
});
client.once(Events.ClientReady, (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.login(TOKEN);