mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
more bot stuff
This commit is contained in:
@@ -69,6 +69,32 @@ function formatChargeState(batteryState) {
|
|||||||
return `${chargeText} (${percentText})`;
|
return `${chargeText} (${percentText})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDockEmoji(docked) {
|
||||||
|
return docked ? '🏠' : '🧭';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatChargeEmoji(charging) {
|
||||||
|
return charging ? '⚡' : '🔌';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatLockEmoji(locked) {
|
||||||
|
return locked ? '🔒' : '🔓';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatBatteryEmoji(batteryState) {
|
||||||
|
if (batteryState?.urgentActive) return '🛑';
|
||||||
|
if (batteryState?.warnActive) return '⚠️';
|
||||||
|
return '🔋';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatOiEmoji(oiMode) {
|
||||||
|
if (oiMode === 'full') return '🕹️';
|
||||||
|
if (oiMode === 'safe') return '🧰';
|
||||||
|
if (oiMode === 'passive') return '🟢';
|
||||||
|
if (oiMode === 'off') return '⏹️';
|
||||||
|
return '❔';
|
||||||
|
}
|
||||||
|
|
||||||
function isCharging(sensors) {
|
function isCharging(sensors) {
|
||||||
const label = sensors?.chargingState?.label?.toLowerCase();
|
const label = sensors?.chargingState?.label?.toLowerCase();
|
||||||
const chargingByLabel =
|
const chargingByLabel =
|
||||||
@@ -100,24 +126,6 @@ function buildRoverStatusSnapshot(record) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatRoverStatus(snapshot) {
|
|
||||||
if (!snapshot) return 'Unknown rover';
|
|
||||||
const lockLabel = snapshot.locked
|
|
||||||
? `locked${snapshot.lockReason ? ` (${snapshot.lockReason})` : ''}`
|
|
||||||
: 'unlocked';
|
|
||||||
const dockLabel = snapshot.docked ? 'docked' : 'undocked';
|
|
||||||
const chargingLabel = snapshot.charging ? `charging (${snapshot.chargingLabel})` : 'not charging';
|
|
||||||
return [
|
|
||||||
`**${snapshot.name}** — ${lockLabel}`,
|
|
||||||
`dock: ${dockLabel}`,
|
|
||||||
`charge: ${chargingLabel}`,
|
|
||||||
`battery: ${formatChargeState(snapshot.batteryState)}`,
|
|
||||||
`voltage: ${formatVoltage(snapshot.voltageMv)}`,
|
|
||||||
`current: ${formatCurrent(snapshot.currentMa)}`,
|
|
||||||
`oi: ${snapshot.oiMode}`,
|
|
||||||
].join(' — ');
|
|
||||||
}
|
|
||||||
|
|
||||||
function countReady() {
|
function countReady() {
|
||||||
const roster = getRoster();
|
const roster = getRoster();
|
||||||
const total = roster.length;
|
const total = roster.length;
|
||||||
@@ -190,19 +198,19 @@ function findRoverRecord(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleStatusCommand(message, roverId) {
|
async function handleStatusCommand(message, roverId) {
|
||||||
if (!roverId) {
|
const record = roverId ? findRoverRecord(roverId) : null;
|
||||||
const snapshots = Array.from(rovers.values()).map(buildRoverStatusSnapshot).filter(Boolean);
|
if (roverId && !record) {
|
||||||
const summary = snapshots.map((snapshot) => formatRoverStatus(snapshot)).join('\n') || 'No rovers online.';
|
const embed = buildEmbed({ title: 'Rover Status', description: 'Unknown rover.', color: 0x2196f3 });
|
||||||
await message.reply({
|
await message.reply({
|
||||||
content: sanitizeMentions(summary.slice(0, 1900)),
|
embeds: [embed],
|
||||||
allowedMentions: { parse: [], repliedUser: false },
|
allowedMentions: { parse: [], repliedUser: false },
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const record = findRoverRecord(roverId);
|
const records = roverId ? [record] : Array.from(rovers.values());
|
||||||
const rover = buildRoverStatusSnapshot(record);
|
const embed = buildBatteryStatusEmbed(0x2196f3, records);
|
||||||
await message.reply({
|
await message.reply({
|
||||||
content: sanitizeMentions(formatRoverStatus(rover).slice(0, 1900)),
|
embeds: [embed],
|
||||||
allowedMentions: { parse: [], repliedUser: false },
|
allowedMentions: { parse: [], repliedUser: false },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -323,9 +331,10 @@ function buildEmbed({ title, description, color }) {
|
|||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildBatteryStatusEmbed(color) {
|
function buildBatteryStatusEmbed(color, records = null) {
|
||||||
const embed = buildEmbed({ title: 'Rover Battery Status', color: color || 0x2196f3 });
|
const embed = buildEmbed({ title: 'Rover Battery Status', color: color || 0x2196f3 });
|
||||||
const snapshots = Array.from(rovers.values()).map(buildRoverStatusSnapshot).filter(Boolean);
|
const baseRecords = records || Array.from(rovers.values());
|
||||||
|
const snapshots = baseRecords.map(buildRoverStatusSnapshot).filter(Boolean);
|
||||||
if (snapshots.length === 0) {
|
if (snapshots.length === 0) {
|
||||||
embed.setDescription('No rovers online.');
|
embed.setDescription('No rovers online.');
|
||||||
return embed;
|
return embed;
|
||||||
@@ -336,16 +345,26 @@ function buildBatteryStatusEmbed(color) {
|
|||||||
: 'unlocked';
|
: 'unlocked';
|
||||||
const dockLabel = snapshot.docked ? 'docked' : 'undocked';
|
const dockLabel = snapshot.docked ? 'docked' : 'undocked';
|
||||||
const chargingLabel = snapshot.charging ? `charging (${snapshot.chargingLabel})` : 'not charging';
|
const chargingLabel = snapshot.charging ? `charging (${snapshot.chargingLabel})` : 'not charging';
|
||||||
|
const header = [
|
||||||
|
formatBatteryEmoji(snapshot.batteryState),
|
||||||
|
formatDockEmoji(snapshot.docked),
|
||||||
|
formatChargeEmoji(snapshot.charging),
|
||||||
|
formatLockEmoji(snapshot.locked),
|
||||||
|
].join(' ');
|
||||||
const lines = [
|
const lines = [
|
||||||
`Dock: ${dockLabel}`,
|
`Dock: ${dockLabel}`,
|
||||||
`Charging: ${chargingLabel}`,
|
`Charging: ${chargingLabel}`,
|
||||||
`Battery: ${formatChargeState(snapshot.batteryState)}`,
|
`Battery: ${formatChargeState(snapshot.batteryState)}`,
|
||||||
`Voltage: ${formatVoltage(snapshot.voltageMv)}`,
|
`Voltage: ${formatVoltage(snapshot.voltageMv)}`,
|
||||||
`Current: ${formatCurrent(snapshot.currentMa)}`,
|
`Current: ${formatCurrent(snapshot.currentMa)}`,
|
||||||
`OI: ${snapshot.oiMode}`,
|
`OI: ${snapshot.oiMode} ${formatOiEmoji(snapshot.oiMode)}`,
|
||||||
`Lock: ${lockLabel}`,
|
`Lock: ${lockLabel}`,
|
||||||
];
|
];
|
||||||
embed.addFields({ name: snapshot.name, value: lines.join('\n'), inline: false });
|
embed.addFields({
|
||||||
|
name: `${header} ${snapshot.name}`,
|
||||||
|
value: lines.join('\n'),
|
||||||
|
inline: true,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user