fix: petpet command

added fallback to https://ptc.pwn3t.ru if
https://api.obamabot.me/v2/image/petpet fails
This commit is contained in:
kmmiio99o 2026-06-27 20:00:31 +02:00
parent 576299f2c7
commit 87f31daa56
No known key found for this signature in database
GPG key ID: AC9D7747D423B9BF
2 changed files with 25 additions and 10 deletions

View file

@ -12,18 +12,18 @@ export const petPetCommand = {
options: [ options: [
{ {
name: "user", name: "user",
description: "The user(or their id) to be patted", description: "The user (or their id) to be patted",
type: 6, type: 6,
required: true, required: true,
displayName: "user", 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) => { execute: async (args: any, ctx: any) => {
try { try {
const user = await UserStore.getUser(args[0].value); const user = await UserStore.getUser(args[0].value);
const image = user.getAvatarURL(512); const image = user.getAvatarURL(512);
const data = await getPetPetData(image); const data = await getPetPetData(image, user.id);
const fixNonce = Date.now().toString(); const fixNonce = Date.now().toString();
MessageActions.sendMessage( MessageActions.sendMessage(

View file

@ -30,13 +30,28 @@ export const catFact = async () => {
}; };
}; };
// Image APIs // Image APIs – primary: obamabot.me, fallback: ptc.pwn3t.ru
export const getPetPetData = async (image: string) => { export const getPetPetData = async (image: string, userId: string) => {
const data = await fetch( try {
`https://api.obamabot.me/v2/image/petpet?image=${image.replace("webp", "png")}`, const response = await fetch(
); `https://api.obamabot.me/v2/image/petpet?image=${image.replace("webp", "png")}`
const body = await data.json(); );
return body; 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 // Gary API function