From 52c99a07f4d2c598d1080317e5642d34f63afd82 Mon Sep 17 00:00:00 2001 From: jenz Date: Mon, 23 Feb 2026 13:10:38 +0100 Subject: [PATCH] added live chat support both ways for mg --- mapinfo_stoat.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mapinfo_stoat.js b/mapinfo_stoat.js index 3e80669..449f2fc 100644 --- a/mapinfo_stoat.js +++ b/mapinfo_stoat.js @@ -8,6 +8,7 @@ const BOT_TOKEN = ""; const API_URL = ""; const CHANNEL_ID = ""; const channel_livechat = ""; +const channel_livechat_mg = ""; const channel_rcon_ze = ""; const channel_adminchat_ze = ""; @@ -209,6 +210,11 @@ const remotecon_css_ze = rcon({ password: '' }); +const remotecon_css_mg = rcon({ + address: '', + password: '' +}); + String.prototype.formatUnicorn = String.prototype.formatUnicorn || function () { "use strict"; @@ -272,16 +278,25 @@ async function checkNewMessages(channel_selected, admin_chat_bool) { const username = author.username || "Unknown"; //console.log(`[New] ${username}: ${content}`); - await remotecon_css_ze.connect(); - if (admin_chat_bool) + if (channel_selected == channel_livechat) { - await remotecon_css_ze.command('sm_printtoadminchat_stoat "{0}" "{1}"'.formatUnicorn(username, content)); + 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.disconnect(); } - else + else if (channel_selected == channel_livechat_mg) { - await remotecon_css_ze.command('sm_printtoallchat_stoat "{0}" "{1}"'.formatUnicorn(username, content)); + await remotecon_css_mg.connect(); + await remotecon_css_mg.command('sm_printtoallchat_stoat "{0}" "{1}"'.formatUnicorn(username, content)); + await remotecon_css_mg.disconnect(); } - await remotecon_css_ze.disconnect(); } } catch (error) { @@ -349,7 +364,6 @@ async function checkNewMessages_rcon_ze() { remotecon_css_ze.disconnect(); }); }); - lastProcessedMessageId_rcon_ze = message._id; } catch (error) { console.error('Error checking messages:', error.message); @@ -364,6 +378,7 @@ async function start() { setInterval(updateServerStats, 300000); // Check for new messages 5 every second setInterval(() => checkNewMessages(channel_livechat, false), 5000); + setInterval(() => checkNewMessages(channel_livechat_mg, false), 5000); setInterval(() => checkNewMessages(channel_adminchat_ze, true), 5000); // Check rcon ze channel for new messages every 5 seconds @@ -372,6 +387,7 @@ async function start() { // Initial update updateServerStats(); checkNewMessages(channel_livechat, false); + checkNewMessages(channel_livechat_mg, false); checkNewMessages(channel_adminchat_ze, true); checkNewMessages_rcon_ze(); }