From 87f31daa562c983a8a90f6e9ace2b07c612b0708 Mon Sep 17 00:00:00 2001 From: kmmiio99o Date: Sat, 27 Jun 2026 20:00:31 +0200 Subject: [PATCH] fix: petpet command added fallback to https://ptc.pwn3t.ru if https://api.obamabot.me/v2/image/petpet fails --- plugins/Commands/src/commands/petpet.ts | 6 ++--- plugins/Commands/src/utils/api.ts | 29 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/plugins/Commands/src/commands/petpet.ts b/plugins/Commands/src/commands/petpet.ts index 6c55881..15906e0 100644 --- a/plugins/Commands/src/commands/petpet.ts +++ b/plugins/Commands/src/commands/petpet.ts @@ -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( diff --git a/plugins/Commands/src/utils/api.ts b/plugins/Commands/src/utils/api.ts index 7b2112b..077e4d9 100644 --- a/plugins/Commands/src/utils/api.ts +++ b/plugins/Commands/src/utils/api.ts @@ -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