Spaces:
Running
Running
File size: 1,139 Bytes
9cd6ddb |
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 |
export const useMessage = () => {
const post = (url: string, message: any) => {
const data = JSON.parse(JSON.stringify(message));
if (data?.embeds?.length > 0) {
data.embeds = data.embeds.map((embed: any) => {
if (typeof embed?.color === "string" && embed?.color?.includes("#")) {
embed.color = parseInt(embed.color.replace("#", ""), 16);
}
return embed;
});
}
if (data?.buttons?.length > 0) {
data.components = [
{
type: 1,
components: data.buttons.map((button: any) => {
const { style, label, emoji, url, disabled } = button;
return {
type: 2,
style,
label,
emoji,
url,
disabled,
};
}),
},
];
}
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
};
return { post };
};
|