sending stoat messages to adminchat-ze

This commit is contained in:
jenz 2026-02-16 21:21:15 +01:00
parent 7e095f085f
commit f1a846a044

View File

@ -9,6 +9,7 @@ const API_URL = "";
const CHANNEL_ID = ""; const CHANNEL_ID = "";
const channel_livechat = ""; const channel_livechat = "";
const channel_rcon_ze = ""; const channel_rcon_ze = "";
const channel_adminchat_ze = "";
var recentStats = []; var recentStats = [];
var currentStats = []; var currentStats = [];
@ -20,7 +21,7 @@ var pendingQueries = 0;
function stoatAPI(method, endpoint, data = null) { function stoatAPI(method, endpoint, data = null) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const options = { const options = {
hostname: 'add hostname here', hostname: '',
path: `/api${endpoint}`, path: `/api${endpoint}`,
method: method, method: method,
headers: { headers: {
@ -135,7 +136,7 @@ function checkAndUpdateMessage() {
//AI slop function //AI slop function
async function sendServerInfo(messageContent) { async function sendServerInfo(messageContent) {
const url = 'add here'; const url = '';
const data = { const data = {
name: 'Server-01', name: 'Server-01',
content: messageContent content: messageContent
@ -230,14 +231,14 @@ function () {
let lastProcessedMessageId = null; let lastProcessedMessageId = null;
async function checkNewMessages() { async function checkNewMessages(channel_selected, admin_chat_bool) {
try { try {
let url = ""; let url = "";
// If it's the very first time, we just want to get the // 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. // current latest message ID and STOP so we don't spam old messages.
if (!lastProcessedMessageId) { if (!lastProcessedMessageId) {
url = `/channels/${channel_livechat}/messages?limit=1`; url = `/channels/${channel_selected}/messages?limit=1`;
const response = await stoatAPI('GET', url); const response = await stoatAPI('GET', url);
//console.log(JSON.stringify(response, null, 2)); //console.log(JSON.stringify(response, null, 2));
//console.log(` ${lastProcessedMessageId}. ${response[0]["content"]}`); //console.log(` ${lastProcessedMessageId}. ${response[0]["content"]}`);
@ -249,7 +250,7 @@ async function checkNewMessages() {
} }
// Subsequent polls: Get everything AFTER the last ID, sorted Oldest -> Newest // 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 response = await stoatAPI('GET', url);
const messages = response.messages || []; const messages = response.messages || [];
@ -272,7 +273,14 @@ async function checkNewMessages() {
//console.log(`[New] ${username}: ${content}`); //console.log(`[New] ${username}: ${content}`);
await remotecon_css_ze.connect(); await remotecon_css_ze.connect();
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.command('sm_printtoallchat_stoat "{0}" "{1}"'.formatUnicorn(username, content));
}
await remotecon_css_ze.disconnect(); await remotecon_css_ze.disconnect();
} }
@ -342,7 +350,6 @@ async function checkNewMessages_rcon_ze() {
}); });
}); });
lastProcessedMessageId_rcon_ze = message._id; lastProcessedMessageId_rcon_ze = message._id;
} catch (error) { } catch (error) {
console.error('Error checking messages:', error.message); console.error('Error checking messages:', error.message);
@ -356,16 +363,17 @@ async function start() {
// Update stats every 5 minutes // Update stats every 5 minutes
setInterval(updateServerStats, 300000); setInterval(updateServerStats, 300000);
// Check for new messages 5 every second // 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 // Check rcon ze channel for new messages every 5 seconds
setInterval(checkNewMessages_rcon_ze, 5000); setInterval(checkNewMessages_rcon_ze, 5000);
// Initial update // Initial update
updateServerStats(); updateServerStats();
checkNewMessages(); checkNewMessages(channel_livechat, false);
checkNewMessages(channel_adminchat_ze, true);
checkNewMessages_rcon_ze(); checkNewMessages_rcon_ze();
} }
start(); start();