From f1a846a04463929da8cdfbd3e863b4b73927acd1 Mon Sep 17 00:00:00 2001 From: jenz Date: Mon, 16 Feb 2026 21:21:15 +0100 Subject: [PATCH] sending stoat messages to adminchat-ze --- mapinfo_stoat.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mapinfo_stoat.js b/mapinfo_stoat.js index 9c5d141..3e80669 100644 --- a/mapinfo_stoat.js +++ b/mapinfo_stoat.js @@ -9,6 +9,7 @@ const API_URL = ""; const CHANNEL_ID = ""; const channel_livechat = ""; const channel_rcon_ze = ""; +const channel_adminchat_ze = ""; var recentStats = []; var currentStats = []; @@ -20,7 +21,7 @@ var pendingQueries = 0; function stoatAPI(method, endpoint, data = null) { return new Promise((resolve, reject) => { const options = { - hostname: 'add hostname here', + hostname: '', path: `/api${endpoint}`, method: method, headers: { @@ -135,7 +136,7 @@ function checkAndUpdateMessage() { //AI slop function async function sendServerInfo(messageContent) { - const url = 'add here'; + const url = ''; const data = { name: 'Server-01', content: messageContent @@ -230,14 +231,14 @@ function () { let lastProcessedMessageId = null; -async function checkNewMessages() { +async function checkNewMessages(channel_selected, admin_chat_bool) { try { let url = ""; // If it's the very first time, we just want to get the // current latest message ID and STOP so we don't spam old messages. if (!lastProcessedMessageId) { - url = `/channels/${channel_livechat}/messages?limit=1`; + url = `/channels/${channel_selected}/messages?limit=1`; const response = await stoatAPI('GET', url); //console.log(JSON.stringify(response, null, 2)); //console.log(` ${lastProcessedMessageId}. ${response[0]["content"]}`); @@ -249,7 +250,7 @@ async function checkNewMessages() { } // Subsequent polls: Get everything AFTER the last ID, sorted Oldest -> Newest - url = `/channels/${channel_livechat}/messages?limit=50&include_users=true&sort=Oldest&after=${lastProcessedMessageId}`; + url = `/channels/${channel_selected}/messages?limit=50&include_users=true&sort=Oldest&after=${lastProcessedMessageId}`; const response = await stoatAPI('GET', url); const messages = response.messages || []; @@ -272,7 +273,14 @@ async function checkNewMessages() { //console.log(`[New] ${username}: ${content}`); await remotecon_css_ze.connect(); - await remotecon_css_ze.command('sm_printtoallchat_stoat "{0}" "{1}"'.formatUnicorn(username, content)); + if (admin_chat_bool) + { + await remotecon_css_ze.command('sm_printtoadminchat_stoat "{0}" "{1}"'.formatUnicorn(username, content)); + } + else + { + await remotecon_css_ze.command('sm_printtoallchat_stoat "{0}" "{1}"'.formatUnicorn(username, content)); + } await remotecon_css_ze.disconnect(); } @@ -342,7 +350,6 @@ async function checkNewMessages_rcon_ze() { }); }); - lastProcessedMessageId_rcon_ze = message._id; } catch (error) { console.error('Error checking messages:', error.message); @@ -356,16 +363,17 @@ async function start() { // Update stats every 5 minutes setInterval(updateServerStats, 300000); // Check for new messages 5 every second - setInterval(checkNewMessages, 5000); + setInterval(() => checkNewMessages(channel_livechat, false), 5000); + setInterval(() => checkNewMessages(channel_adminchat_ze, true), 5000); // Check rcon ze channel for new messages every 5 seconds setInterval(checkNewMessages_rcon_ze, 5000); // Initial update updateServerStats(); - checkNewMessages(); + checkNewMessages(channel_livechat, false); + checkNewMessages(channel_adminchat_ze, true); checkNewMessages_rcon_ze(); } start(); -