mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 08:45:55 +00:00
add cs comp endpoint
This commit is contained in:
parent
299ee23d32
commit
41ae6f74b4
1 changed files with 69 additions and 49 deletions
|
@ -10,20 +10,30 @@ module.exports = {
|
||||||
.setName("steam_id")
|
.setName("steam_id")
|
||||||
.setDescription("The Steam ID to fetch stats for.")
|
.setDescription("The Steam ID to fetch stats for.")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("stats_type")
|
||||||
|
.setDescription("The type of stats to fetch (premier or competitive).")
|
||||||
|
.setRequired(true)
|
||||||
|
.addChoices(
|
||||||
|
{ name: "Premier", value: "premier" },
|
||||||
|
{ name: "Competitive", value: "competitive" }
|
||||||
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const steamId = interaction.options.getString("steam_id");
|
const steamId = interaction.options.getString("steam_id");
|
||||||
|
const statsType = interaction.options.getString("stats_type");
|
||||||
|
|
||||||
const apiUrl = process.env.TRACKER_API_URL;
|
const apiUrl = process.env.TRACKER_API_URL;
|
||||||
const apiKey = process.env.TRACKER_API_KEY;
|
const apiKey = process.env.TRACKER_API_KEY;
|
||||||
|
|
||||||
const url = `https://${apiUrl}/cs2/player/${steamId}`;
|
const url = `https://${apiUrl}/cs2/player/${steamId}/${statsType}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
// Fetch data from the API
|
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"X-API-Key": apiKey,
|
"X-API-Key": apiKey,
|
||||||
|
@ -34,54 +44,64 @@ module.exports = {
|
||||||
|
|
||||||
const statsEmbed = new EmbedBuilder()
|
const statsEmbed = new EmbedBuilder()
|
||||||
.setColor("#ff4500")
|
.setColor("#ff4500")
|
||||||
.setTitle(`CS2 Stats for Steam ID: ${data.steam_id}`)
|
.setTitle(`CS2 Stats for Steam ID: ${data.steam_id} (${statsType})`);
|
||||||
.addFields(
|
|
||||||
{
|
const rankField = {
|
||||||
name: "🏆 Current Rank",
|
name:
|
||||||
value: data.current_rank,
|
statsType === "competitive"
|
||||||
},
|
? "🏆 Highest Rank (All maps)"
|
||||||
{
|
: "🏆 Current Rank",
|
||||||
name: "🔝 Peak Rank",
|
value: data.current_rank,
|
||||||
value: data.peak_rank,
|
};
|
||||||
},
|
|
||||||
{
|
const fields = [
|
||||||
name: "⏳ Hours Played",
|
rankField,
|
||||||
value: `${data.hours_played}h`,
|
{
|
||||||
},
|
name: "⏳ Hours Played",
|
||||||
{
|
value: `${data.hours_played}h`,
|
||||||
name: "🎮 Matches Played",
|
},
|
||||||
value: `${data.matches_played}`,
|
{
|
||||||
},
|
name: "🎮 Matches Played",
|
||||||
{
|
value: `${data.matches_played}`,
|
||||||
name: "🏅 Wins",
|
},
|
||||||
value: `${data.wins}`,
|
{
|
||||||
},
|
name: "🏅 Wins",
|
||||||
{
|
value: `${data.wins}`,
|
||||||
name: "📊 Win Percentage",
|
},
|
||||||
value: `${data.win_percentage}%`,
|
{
|
||||||
},
|
name: "📊 Win Percentage",
|
||||||
{
|
value: `${data.win_percentage}%`,
|
||||||
name: "⚔️ Kills",
|
},
|
||||||
value: `${data.kills}`,
|
{
|
||||||
},
|
name: "⚔️ Kills",
|
||||||
{
|
value: `${data.kills}`,
|
||||||
name: "📈 K/D Ratio",
|
},
|
||||||
value: `${data.kd_ratio}`,
|
{
|
||||||
},
|
name: "📈 K/D Ratio",
|
||||||
{
|
value: `${data.kd_ratio}`,
|
||||||
name: "🎯 Headshot Percentage",
|
},
|
||||||
value: `${data.headshot_percentage}%`,
|
{
|
||||||
},
|
name: "🎯 Headshot Percentage",
|
||||||
{
|
value: `${data.headshot_percentage}%`,
|
||||||
name: "💯 Tracker Score",
|
},
|
||||||
value: `${data.tracker_score}/1000`,
|
{
|
||||||
}
|
name: "💯 Tracker Score",
|
||||||
)
|
value: `${data.tracker_score}/1000`,
|
||||||
.setTimestamp()
|
},
|
||||||
.setFooter({
|
];
|
||||||
text: "CS2 Stats API made by Ayden",
|
|
||||||
iconURL: interaction.guild.iconURL(),
|
// Only add Peak Rank if statsType is not "competitive"
|
||||||
|
if (statsType !== "competitive") {
|
||||||
|
fields.splice(1, 0, {
|
||||||
|
name: "🔝 Peak Rank",
|
||||||
|
value: data.peak_rank || "N/A",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
statsEmbed.addFields(fields).setTimestamp().setFooter({
|
||||||
|
text: "CS2 Stats API made by Ayden",
|
||||||
|
iconURL: interaction.guild.iconURL(),
|
||||||
|
});
|
||||||
|
|
||||||
return interaction.editReply({ embeds: [statsEmbed] });
|
return interaction.editReply({ embeds: [statsEmbed] });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in a new issue