Skip to content

Commit

Permalink
better mc skin command
Browse files Browse the repository at this point in the history
  • Loading branch information
Stef-00012 committed Jan 3, 2025
1 parent ca775b4 commit e903c11
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 100 deletions.
40 changes: 34 additions & 6 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,6 @@ export default [
type: ApplicationCommandOptionType.Subcommand,
description: "Get the skin of a player",
options: [
{
name: "player",
description: "The player name or UUID",
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: "render-type",
description: "How to render the player skin",
Expand All @@ -510,6 +504,40 @@ export default [
autocomplete: true,
required: true,
},
{
name: "player",
description: "he player name or UUID (prefix with . for Bedrock)",
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: "skin-url",
description: "The URL to a minecraft skin",
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: "skin-type",
description: "The player skin type (default: wide)",
type: ApplicationCommandOptionType.String,
choices: [
{
name: "Slim",
value: "slim",
},
{
name: "Wide",
value: "wide",
},
],
required: false
},
// {
// name: "bedrock",
// description: "If the player is a bedrock player",
// type: ApplicationCommandOptionType.Boolean,
// required: false,
// }
],
},
],
Expand Down
69 changes: 7 additions & 62 deletions src/commands/slash/minecraft.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { avaibleCropTypes, avaibleRenderTypes } from "../../data/constants/lunarEclypse";
import type { Client } from "../../structures/DiscordClient";
import type { CropType } from "../../types/lunarEclypse";
import type { Command } from "../../types/command";
import type {
AutocompleteInteraction,
Expand All @@ -18,36 +20,6 @@ export default {

switch (option.name) {
case "render-type": {
const avaibleRenderTypes = [
{ name: "Default", value: "default" },
{ name: "Marching", value: "marching" },
{ name: "Walking", value: "walking" },
{ name: "Crouching", value: "crouching" },
{ name: "Crossed", value: "crossed" },
{ name: "Criss Cross", value: "criss_cross" },
{ name: "Ultimate", value: "ultimate" },
{ name: "Isometric", value: "isometric" },
{ name: "Head", value: "head" },
{ name: "Cheering", value: "cheering" },
{ name: "Relaxing", value: "relaxing" },
{ name: "Trudging", value: "trudging" },
{ name: "Cowering", value: "cowering" },
{ name: "Pointing", value: "pointing" },
{ name: "Lunging", value: "lunging" },
{ name: "Dungeons", value: "dungeons" },
{ name: "Facepalm", value: "facepalm" },
{ name: "Sleeping", value: "sleeping" },
{ name: "Dead", value: "dead" },
{ name: "Archer", value: "archer" },
{ name: "Kicking", value: "kicking" },
{ name: "Mojavatar", value: "mojavatar" },
{ name: "Reading", value: "reading" },
{ name: "Bitzel", value: "bitzel" },
{ name: "Pixel", value: "pixel" },
{ name: "Ornament", value: "ornament" },
{ name: "Skin", value: "skin" },
];

let matches = avaibleRenderTypes.filter((renderType) =>
renderType.value.toLowerCase().startsWith(option.value.toLowerCase()),
);
Expand All @@ -60,42 +32,15 @@ export default {
case "crop-type": {
const renderType = int.options.getString("render-type", true);

const avaibleCropTypes = {
default: ["full", "bust", "face"],
marching: ["full", "bust", "face"],
walking: ["full", "bust", "face"],
crouching: ["full", "bust", "face"],
crossed: ["full", "bust", "face"],
criss_cross: ["full", "bust", "face"],
ultimate: ["full", "bust", "face"],
isometric: ["full", "bust", "face", "head"],
head: ["full"],
cheering: ["full", "bust", "face"],
relaxing: ["full", "bust", "face"],
trudging: ["full", "bust", "face"],
cowering: ["full", "bust", "face"],
pointing: ["full", "bust", "face"],
lunging: ["full", "bust", "face"],
dungeons: ["full", "bust", "face"],
facepalm: ["full", "bust", "face"],
sleeping: ["full", "bust"],
dead: ["full", "bust", "face"],
archer: ["full", "bust", "face"],
kicking: ["full", "bust", "face"],
mojavatar: ["full", "bust"],
reading: ["full", "bust", "face"],
bitzel: ["full", "bust", "face"],
pixel: ["full", "bust", "face"],
ornament: ["full"],
skin: ["default", "processed"],
};

const matches = (avaibleCropTypes[renderType] || [])
.map((cropType) => ({
.map((cropType: CropType) => ({
name: cropType,
value: cropType,
}))
.filter((cropType) =>
.filter((cropType: {
name: CropType,
value: CropType
}) =>
cropType.name.toLowerCase().startsWith(option.value.toLowerCase()),
);

Expand Down
57 changes: 25 additions & 32 deletions src/commands/slash/minecraft/skin.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,48 @@
import { type ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
import { avaibleCropTypes } from "../../../data/constants/lunarEclypse";
import type { Client } from "../../../structures/DiscordClient";
import type { SkinType } from "../../../types/lunarEclypse";

export default async function (
client: Client,
int: ChatInputCommandInteraction,
) {
const player = int.options.getString("player", true);
const renderType = int.options.getString("render-type", true);
const cropType = int.options.getString("crop-type", true);

const avaibleCropTypes = {
default: ["full", "bust", "face"],
marching: ["full", "bust", "face"],
walking: ["full", "bust", "face"],
crouching: ["full", "bust", "face"],
crossed: ["full", "bust", "face"],
criss_cross: ["full", "bust", "face"],
ultimate: ["full", "bust", "face"],
isometric: ["full", "bust", "face", "head"],
head: ["full"],
cheering: ["full", "bust", "face"],
relaxing: ["full", "bust", "face"],
trudging: ["full", "bust", "face"],
cowering: ["full", "bust", "face"],
pointing: ["full", "bust", "face"],
lunging: ["full", "bust", "face"],
dungeons: ["full", "bust", "face"],
facepalm: ["full", "bust", "face"],
sleeping: ["full", "bust"],
dead: ["full", "bust", "face"],
archer: ["full", "bust", "face"],
kicking: ["full", "bust", "face"],
mojavatar: ["full", "bust"],
reading: ["full", "bust", "face"],
bitzel: ["full", "bust", "face"],
pixel: ["full", "bust", "face"],
ornament: ["full"],
skin: ["default", "processed"],
};
const skinType = int.options.getString("skin-type", false) as SkinType || "wide"

const defaultSkin = skinType === "wide" ? "MHF_Steve" : "MHF_Alex"

const skinUrl = int.options.getString("skin-url", false);
const player = int.options.getString("player", false) || defaultSkin;

const urlRegex = /^http:\/\/(.*)?|https:\/\/(.*)?$/;

if (!avaibleCropTypes[renderType].includes(cropType))
return await int.reply({
content: "Invalid crop type",
ephemeral: true,
});

const url = `https://starlightskins.lunareclipse.studio/render/${renderType}/${player}/${cropType}`;
if (skinUrl && !urlRegex.test(skinUrl)) return await int.reply({
content: "This skin URL is not a valid URL",
ephemeral: true
});

const urlParams = new URLSearchParams({
skinType
})

if (skinUrl) urlParams.append("skinUrl", skinUrl)

const url = `https://starlightskins.lunareclipse.studio/render/${renderType}/${player}/${cropType}?${urlParams.toString()}`;

const embed = new EmbedBuilder()
.setAuthor({
name: "Minecraft Player Skin",
})
.setTitle(player)
.setTitle(skinUrl || player)
.setImage(url)
.addFields([
{
Expand All @@ -66,6 +57,8 @@ export default async function (
},
]);

if (skinUrl) embed.setURL(skinUrl)

await int.reply({
embeds: [embed],
});
Expand Down
102 changes: 102 additions & 0 deletions src/data/constants/lunarEclypse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import type { CropType, RenderType } from "../../types/lunarEclypse";

export const renderTypes: Array<RenderType> = [
"default",
"marching",
"walking",
"crouching",
"crossed",
"criss_cross",
"ultimate",
"isometric",
"head",
"cheering",
"relaxing",
"trudging",
"cowering",
"pointing",
"lunging",
"dungeons",
"facepalm",
"sleeping",
"dead",
"archer",
"kicking",
"mojavatar",
"reading",
"high_ground",
"bitzel",
"pixel",
"ornament",
"skin",
"profile"
]

export const avaibleCropTypes: {
[key in RenderType]: Array<CropType>;
} = {
default: ["full", "bust", "face"],
marching: ["full", "bust", "face"],
walking: ["full", "bust", "face"],
crouching: ["full", "bust", "face"],
crossed: ["full", "bust", "face"],
criss_cross: ["full", "bust", "face"],
ultimate: ["full", "bust", "face"],
isometric: ["full", "bust", "face", "head"],
head: ["full"],
cheering: ["full", "bust", "face"],
relaxing: ["full", "bust", "face"],
trudging: ["full", "bust", "face"],
cowering: ["full", "bust", "face"],
pointing: ["full", "bust", "face"],
lunging: ["full", "bust", "face"],
dungeons: ["full", "bust", "face"],
facepalm: ["full", "bust", "face"],
sleeping: ["full", "bust"],
dead: ["full", "bust", "face"],
archer: ["full", "bust", "face"],
kicking: ["full", "bust", "face"],
mojavatar: ["full", "bust"],
reading: ["full", "bust", "face"],
high_ground: ["full", "bust", "face"],
bitzel: ["full", "bust", "face"],
pixel: ["full", "bust", "face"],
ornament: ["full"],
skin: ["default", "processed"],
profile: ["full", "bust", "face"]
};

export const avaibleRenderTypes: Array<{
name: string;
value: RenderType;
}> = [
{ name: "Default", value: "default" },
{ name: "Marching", value: "marching" },
{ name: "Walking", value: "walking" },
{ name: "Crouching", value: "crouching" },
{ name: "Crossed", value: "crossed" },
{ name: "Criss Cross", value: "criss_cross" },
{ name: "Ultimate", value: "ultimate" },
{ name: "Isometric", value: "isometric" },
{ name: "Head", value: "head" },
{ name: "Cheering", value: "cheering" },
{ name: "Relaxing", value: "relaxing" },
{ name: "Trudging", value: "trudging" },
{ name: "Cowering", value: "cowering" },
{ name: "Pointing", value: "pointing" },
{ name: "Lunging", value: "lunging" },
{ name: "Dungeons", value: "dungeons" },
{ name: "Facepalm", value: "facepalm" },
{ name: "Sleeping", value: "sleeping" },
{ name: "Dead", value: "dead" },
{ name: "Archer", value: "archer" },
{ name: "Kicking", value: "kicking" },
{ name: "Mojavatar", value: "mojavatar" },
{ name: "Reading", value: "reading" },
{ name: "High Grounds", value: "high_ground" },
{ name: "Bitzel", value: "bitzel" },
{ name: "Pixel", value: "pixel" },
{ name: "Ornament", value: "ornament" },
{ name: "Skin", value: "skin" },
{ name: "Profile", value: "profile" }
]
32 changes: 32 additions & 0 deletions src/types/lunarEclypse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export type SkinType = "wide" | "slim";
export type CropType = "full" | "bust" | "face" | "head" | "default" | "processed";
export type RenderType =
|"default"
| "marching"
| "walking"
| "crouching"
| "crossed"
| "criss_cross"
| "ultimate"
| "isometric"
| "head"
| "cheering"
| "relaxing"
| "trudging"
| "cowering"
| "pointing"
| "lunging"
| "dungeons"
| "facepalm"
| "sleeping"
| "dead"
| "archer"
| "kicking"
| "mojavatar"
| "reading"
| "high_ground"
| "bitzel"
| "pixel"
| "ornament"
| "skin"
| "profile";

0 comments on commit e903c11

Please sign in to comment.