fix: petpet command
added fallback to https://ptc.pwn3t.ru if https://api.obamabot.me/v2/image/petpet fails
This commit is contained in:
parent
576299f2c7
commit
87f31daa56
2 changed files with 25 additions and 10 deletions
|
|
@ -12,18 +12,18 @@ export const petPetCommand = {
|
|||
options: [
|
||||
{
|
||||
name: "user",
|
||||
description: "The user(or their id) to be patted",
|
||||
description: "The user (or their id) to be patted",
|
||||
type: 6,
|
||||
required: true,
|
||||
displayName: "user",
|
||||
displayDescription: "The user(or their id) to be patted",
|
||||
displayDescription: "The user (or their id) to be patted",
|
||||
},
|
||||
],
|
||||
execute: async (args: any, ctx: any) => {
|
||||
try {
|
||||
const user = await UserStore.getUser(args[0].value);
|
||||
const image = user.getAvatarURL(512);
|
||||
const data = await getPetPetData(image);
|
||||
const data = await getPetPetData(image, user.id);
|
||||
|
||||
const fixNonce = Date.now().toString();
|
||||
MessageActions.sendMessage(
|
||||
|
|
|
|||
|
|
@ -30,13 +30,28 @@ export const catFact = async () => {
|
|||
};
|
||||
};
|
||||
|
||||
// Image APIs
|
||||
export const getPetPetData = async (image: string) => {
|
||||
const data = await fetch(
|
||||
`https://api.obamabot.me/v2/image/petpet?image=${image.replace("webp", "png")}`,
|
||||
);
|
||||
const body = await data.json();
|
||||
return body;
|
||||
// Image APIs – primary: obamabot.me, fallback: ptc.pwn3t.ru
|
||||
export const getPetPetData = async (image: string, userId: string) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.obamabot.me/v2/image/petpet?image=${image.replace("webp", "png")}`
|
||||
);
|
||||
if (response.ok) {
|
||||
const body = await response.json();
|
||||
if (body && body.url) {
|
||||
return body; // returns { url: ... }
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("[PetPet] Obama API failed, falling back to .ru:", error);
|
||||
}
|
||||
if (userId) {
|
||||
const url = `https://ptc.pwn3t.ru/${userId}.gif`;
|
||||
return { url };
|
||||
}
|
||||
|
||||
// If all fail, throw error
|
||||
throw new Error("All PetPet APIs are down");
|
||||
};
|
||||
|
||||
// Gary API function
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue