Spaces:
Runtime error

README / index.js
AlexIsSoPro's picture
Create index.js
6e93a96 verified
Raw History Blame Contribute Delete
4.14 kB
import express from "express";
import fetch from "node-fetch";
const app = express();
const PORT = process.env.PORT || 5000;
// The Auth Token is now embedded directly into the URL query parameters
const AUTH_TOKEN = "AIzaSyBokCjJ7bIUOk_beo2gWQXst6PKqlFFEpc";
const API_URL = `https://yalohsosipisky-default-rtdb.firebaseio.com/servers.json?auth=${AUTH_TOKEN}`;
const DISCORD_WEBHOOK_URL = process.env.DISCORD_WEBHOOK_URL;
const REFRESH_RATE = 2000;
const PLACE_ID = "109983668079237";
let jobData = [];
let sentJobIds = new Set();
let isSending = false;
app.get("/", (req, res) => {
const html = `
<!DOCTYPE html>
<html>
<head>
<title>Job IDs</title>
<meta http-equiv="refresh" content="2">
<style>
body { font-family: monospace; background: #1a1a1a; color: #0f0; padding: 20px; }
h1 { color: #0f0; }
.job-id { padding: 5px 0; font-size: 16px; border-bottom: 1px solid #333; }
a { color: #0f0; text-decoration: none; font-weight: bold; }
a:hover { color: #fff; }
</style>
</head>
<body>
<h1>Job IDs (Authenticated)</h1>
${jobData.length > 0
? jobData.map(job => `<div class="job-id">${job.name} - ${job.money}/s - <a href="${job.link}" target="_blank">JOIN LINK</a></div>`).join('')
: '<p>Waiting for data from Firebase...</p>'}
</body>
</html>
`;
res.send(html);
});
app.get("/jobids", (req, res) => {
res.json(jobData);
});
async function sendToDiscord(newJobs) {
if (!DISCORD_WEBHOOK_URL || newJobs.length === 0 || isSending) return;
isSending = true;
for (const job of newJobs) {
if (sentJobIds.has(job.jobId)) continue;
sentJobIds.add(job.jobId);
try {
const message = {
embeds: [{
title: "πŸš€ NEW SERVER FOUND",
color: 0x783cc4, // Purple color to match your UI
fields: [
{ name: "πŸ‘‘ Name", value: job.name, inline: true },
{ name: "🧬 Mutation", value: job.mutation, inline: true },
{ name: "πŸ’° Money/Sec", value: `${job.money}`, inline: true },
{ name: "🐾 Tier", value: job.tier, inline: true },
{ name: "πŸ†” Job ID", value: `\`${job.jobId}\``, inline: false },
{ name: "πŸ”— Join Link", value: `[Click to Join](https://www.roblox.com/games/${PLACE_ID}/?gameInstanceId=${job.jobId})`, inline: false }
],
timestamp: new Date()
}]
};
await fetch(DISCORD_WEBHOOK_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(message)
});
console.log(`βœ… Notified Discord: ${job.name}`);
await new Promise(r => setTimeout(r, 1000)); // Prevent Discord rate limit
} catch (err) {
console.error("Discord Error:", err.message);
}
}
isSending = false;
}
async function fetchJobIds() {
try {
const response = await fetch(API_URL);
const data = await response.json();
if (data && typeof data === 'object') {
const formattedJobs = [];
// Firebase returns an object of objects, so we iterate through keys
for (const key in data) {
const server = data[key];
const jobId = server.jobId || key;
formattedJobs.push({
name: server.name || "Unknown",
mutation: server.isBrainrot ? "Brainrot" : "Normal",
money: server.moneyPerSec || "0",
tier: (server.name === "Strawberry Elephant" || server.name === "Meowl") ? "OG TIER" : "Secret",
jobId: jobId,
link: `https://www.roblox.com/games/${PLACE_ID}/?gameInstanceId=${jobId}`
});
}
jobData = formattedJobs;
const newJobs = jobData.filter(job => !sentJobIds.has(job.jobId));
if (newJobs.length > 0) {
sendToDiscord(newJobs);
}
}
} catch (err) {
console.error("Firebase Fetch Error:", err.message);
}
}
// Initial fetch and start interval
fetchJobIds();
setInterval(fetchJobIds, REFRESH_RATE);
app.listen(PORT, "0.0.0.0", () => {
console.log(`Server is live on port ${PORT}`);
});