mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
bot tag and profile images yay urls only though...
This commit is contained in:
@@ -26,6 +26,19 @@ function isPrivateClosedRoverId(roverId) {
|
||||
return roverManager.canReplayRoverId(roverId) !== true;
|
||||
}
|
||||
|
||||
function normalizeProfileImageUrl(value) {
|
||||
const raw = String(value || '').trim();
|
||||
if (!raw) return null;
|
||||
try {
|
||||
const parsed = new URL(raw);
|
||||
const protocol = String(parsed.protocol || '').toLowerCase();
|
||||
if (protocol !== 'http:' && protocol !== 'https:') return null;
|
||||
return parsed.toString();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function isChargingFromSensors(sensors = {}) {
|
||||
const label = String(sensors?.chargingState?.label || '').toLowerCase();
|
||||
if (label === 'waiting' || label === 'full charging' || label === 'trickle charging') return true;
|
||||
@@ -103,10 +116,10 @@ function buildMessage(socket, text, meta = {}) {
|
||||
discordUserId: meta.discordUserId || null,
|
||||
discordUserName: meta.discordUserName || null,
|
||||
discordUserAvatarUrl: meta.discordUserAvatarUrl || null,
|
||||
profileImage: normalizeProfileImageUrl(meta.profileImage),
|
||||
roverCtx: meta.roverCtx || null,
|
||||
text,
|
||||
tts: meta.tts || null,
|
||||
system: Boolean(meta.system),
|
||||
bot: Boolean(meta.bot),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ function createHandlers({ sendSystemMessage }) {
|
||||
cb({ success: true });
|
||||
}
|
||||
|
||||
function sendExternalMessage({ text, nickname = 'Discord', role = 'admin', roverId = null, discordGuildId = null, discordGuildName = null, discordGuildIconUrl = null, discordChannelId = null, discordUserId = null, discordUserName = null, discordUserAvatarUrl = null }) {
|
||||
function sendExternalMessage({ text, nickname = 'Discord', role = 'admin', roverId = null, discordGuildId = null, discordGuildName = null, discordGuildIconUrl = null, discordChannelId = null, discordUserId = null, discordUserName = null, discordUserAvatarUrl = null, bot = false, profileImage = null }) {
|
||||
const normalized = normalizeUserText(text);
|
||||
const clean = normalized.trim();
|
||||
if (!clean || clean.length > 400) throw new Error('Message invalid');
|
||||
@@ -66,6 +66,8 @@ function createHandlers({ sendSystemMessage }) {
|
||||
discordUserId,
|
||||
discordUserName,
|
||||
discordUserAvatarUrl,
|
||||
bot,
|
||||
profileImage,
|
||||
});
|
||||
|
||||
logger.info('External chat message', { roverId, nickname });
|
||||
|
||||
@@ -17,8 +17,8 @@ function sendSystemMessage(text, options = {}) {
|
||||
nickname: String(options.nickname || 'The Overseer'),
|
||||
role: 'user',
|
||||
fromDiscord: false,
|
||||
system: true,
|
||||
bot: true,
|
||||
bot: options.bot !== false,
|
||||
profileImage: options.profileImage || null,
|
||||
});
|
||||
broadcastMessage(message);
|
||||
return message;
|
||||
|
||||
@@ -49,7 +49,7 @@ function buildAccessNoticeText(mode, reasonText) {
|
||||
}
|
||||
|
||||
function shouldSendAccessNotice(message) {
|
||||
if (!message?.text || message.system) return false;
|
||||
if (!message?.text || message.bot) return false;
|
||||
const mode = getMode();
|
||||
if (mode !== MODES.ADMIN && mode !== MODES.LOCKDOWN) return false;
|
||||
if (!ACCESS_KEYWORD_RE.test(message.text)) return false;
|
||||
|
||||
@@ -28,7 +28,7 @@ function pushHistory(message) {
|
||||
function getRecentMessages(limit = 20, options = {}) {
|
||||
const safeLimit = Number.isFinite(limit) ? Math.max(0, Math.floor(limit)) : 20;
|
||||
const includeSystem = options?.includeSystem !== false;
|
||||
const source = includeSystem ? history : history.filter((entry) => !entry?.system);
|
||||
const source = includeSystem ? history : history.filter((entry) => !entry?.bot);
|
||||
return source.slice(-safeLimit);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user