Skip to content

Instantly share code, notes, and snippets.

@Rico040
Created September 24, 2024 16:24
Show Gist options
  • Save Rico040/aafb75961920d8c2b022ff38fff633e8 to your computer and use it in GitHub Desktop.
Save Rico040/aafb75961920d8c2b022ff38fff633e8 to your computer and use it in GitHub Desktop.
A little script that fetches current Neko Atsume aikotoba and posts it to Discord through webhook.
// For Japanese aikotoba, use https://hpmobile.jp/app/nekoatsume/neko_daily.php
const apiUrl = "https://hpmobile.jp/app/nekoatsume/neko_daily_en.php";
const webhookUrl =
"https://discord.com/api/webhooks/.../...";
async function fetchNekoAtsumeData() {
try {
// mimic game's get request
const response = await fetch(apiUrl, {
method: "GET",
headers: {
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip",
"User-Agent": "okhttp/3.12.13",
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.text();
return data.trim();
} catch (error) {
console.error("Error fetching Neko Atsume data:", error);
return null;
}
}
async function sendToDiscord(password, fishes, goldFishes) {
try {
const response = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
embeds: [
{
title: `Today's daily password <a:peachescelebrate:1281291728862576731>`,
description: `${password}`,
footer: { text: `${fishes} 🐟 | ${goldFishes} 🐠` },
},
],
}),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
console.log("Message sent successfully to Discord");
} catch (error) {
console.error("Error sending message to Discord:", error);
}
}
async function main() {
const data = await fetchNekoAtsumeData();
if (data) {
const [, password, fishes, goldFishes] = data.split(",");
await sendToDiscord(password, fishes, goldFishes);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment