Skip to content

Commit

Permalink
mc user cmd, try to get user skin type automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Stef-00012 committed Jan 6, 2025
1 parent 91f68e2 commit 9247258
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,19 @@ export default [
// }
],
},
{
name: "user",
type: ApplicationCommandOptionType.Subcommand,
description: "Get info about a player",
options: [
{
name: "player",
description: "he player name or UUID (prefix with . for Bedrock)",
type: ApplicationCommandOptionType.String,
required: true,
},
],
},
],
},
{
Expand Down
26 changes: 19 additions & 7 deletions src/commands/slash/minecraft/skin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {
type ChatInputCommandInteraction,
EmbedBuilder,
MessageFlags,
} from "discord.js";
import type { Client } from "../../../structures/DiscordClient";
import type { Player } from "../../../types/minecraftPlayer";
import {
avaibleCropTypes,
customSkinsConfig,
renderTypes,
} from "../../../data/constants/minecraftSkin";
import type { Client } from "../../../structures/DiscordClient";
import type {
CropType,
RenderType,
SkinType,
} from "../../../types/minecraftSkin";
import axios from "axios";
import {
type ChatInputCommandInteraction,
EmbedBuilder,
MessageFlags,
} from "discord.js";

export default async function (
client: Client,
Expand All @@ -25,7 +27,7 @@ export default async function (
) as RenderType;
const cropType = int.options.getString("crop-type", true) as CropType;

const skinType =
let skinType =
(int.options.getString("skin-type", false) as SkinType) || "wide";

const defaultSkin = skinType === "wide" ? "MHF_Steve" : "MHF_Alex";
Expand Down Expand Up @@ -53,6 +55,16 @@ export default async function (
flags: MessageFlags.Ephemeral,
});

await int.deferReply();

try {
const playerInfo = await axios.get(`https://starlightskins.lunareclipse.studio/info/user/${player}`);

const playerData = playerInfo.data as Player;

if (playerData.skinType) skinType = playerData.skinType;
} catch (e) {}

const urlParams = new URLSearchParams({
skinType,
});
Expand Down
66 changes: 66 additions & 0 deletions src/commands/slash/minecraft/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { type ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
import type { Client } from "../../../structures/DiscordClient";
import type { Player } from "../../../types/minecraftPlayer";
import axios from "axios";

export default async function (
client: Client,
int: ChatInputCommandInteraction,
) {
const player = int.options.getString("player", true);

await int.deferReply();

try {
const playerInfo = await axios.get(`https://starlightskins.lunareclipse.studio/info/user/${player}`);

const playerData = playerInfo.data as Player;

const embedFields = [
{
name: "Skin",
value: `[View Skin](${playerData.skinUrl})`,
inline: true
},
]

if (playerData.processedSkinUrl) embedFields.push({
name: "Processed Skin (32px -> 64px)",
value: `[View Processed Skin](${playerData.processedSkinUrl})`,
inline: true
})

embedFields.push(
{
name: "Skin Type",
value: playerData.skinType,
inline: true
},
{
name: "Skin Texture Width",
value: `${playerData.skinTextureWidth}`,
inline: true
},
{
name: "Skin Texture Height",
value: `${playerData.skinTextureHeight}`,
inline: true
}
)

const embed = new EmbedBuilder()
.setTitle(player)
.addFields(embedFields)
.setFooter({
text: playerData.playerUUID
})

await int.editReply({
embeds: [embed]
})
} catch(e) {
await int.editReply({
content: "The user was not found"
})
}
}
11 changes: 11 additions & 0 deletions src/types/minecraftPlayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { SkinType } from "./minecraftSkin";

export interface Player {
processedSkinUrl?: string;
skinTextureHeight: number;
skinTextureWidth: number;
playerUUID: string;
skinType: SkinType;
userCape?: string;
skinUrl: string;
}

0 comments on commit 9247258

Please sign in to comment.