Fix JavaScript integer precision loss for Discord IDs in web UI
- Removed parseInt() calls that were causing Discord snowflake IDs to lose precision - Discord IDs exceed JavaScript's safe integer limit (2^53-1), causing corruption - Fixed sendBedtime(), triggerAutonomous(), custom prompt, and addServer() functions - Keep guild_id and channel_id values as strings throughout the frontend - Backend FastAPI correctly parses string IDs to Python integers without precision loss - Resolves issue where wrong server ID was sent (e.g., 1429954521576116200 instead of 1429954521576116337)
This commit is contained in:
@@ -1150,8 +1150,12 @@ async function populateServerDropdowns() {
|
|||||||
manualServerSelect.innerHTML = '<option value="all">All Servers</option>';
|
manualServerSelect.innerHTML = '<option value="all">All Servers</option>';
|
||||||
customPromptServerSelect.innerHTML = '<option value="all">All Servers</option>';
|
customPromptServerSelect.innerHTML = '<option value="all">All Servers</option>';
|
||||||
|
|
||||||
|
console.log('🎭 Populating server dropdowns with', servers.length, 'servers');
|
||||||
|
|
||||||
// Add server options
|
// Add server options
|
||||||
servers.forEach(server => {
|
servers.forEach(server => {
|
||||||
|
console.log(`🎭 Adding server to dropdown: ${server.guild_name} (guild_id: ${server.guild_id}, type: ${typeof server.guild_id})`);
|
||||||
|
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = server.guild_id;
|
option.value = server.guild_id;
|
||||||
option.textContent = server.guild_name;
|
option.textContent = server.guild_name;
|
||||||
@@ -1161,6 +1165,12 @@ async function populateServerDropdowns() {
|
|||||||
customPromptServerSelect.appendChild(option.cloneNode(true));
|
customPromptServerSelect.appendChild(option.cloneNode(true));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Debug: Check what's actually in the manual-server-select dropdown
|
||||||
|
console.log('🎭 manual-server-select options:');
|
||||||
|
Array.from(manualServerSelect.options).forEach((opt, idx) => {
|
||||||
|
console.log(` [${idx}] value="${opt.value}" text="${opt.textContent}"`);
|
||||||
|
});
|
||||||
|
|
||||||
// Populate autonomous stats dropdown
|
// Populate autonomous stats dropdown
|
||||||
populateAutonomousServerDropdown();
|
populateAutonomousServerDropdown();
|
||||||
}
|
}
|
||||||
@@ -1333,12 +1343,13 @@ async function sendFigurineNow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addServer() {
|
async function addServer() {
|
||||||
const guildId = parseInt(document.getElementById('new-guild-id').value);
|
// Don't use parseInt() for Discord IDs - they're too large for JS integers
|
||||||
|
const guildId = document.getElementById('new-guild-id').value.trim();
|
||||||
const guildName = document.getElementById('new-guild-name').value;
|
const guildName = document.getElementById('new-guild-name').value;
|
||||||
const autonomousChannelId = parseInt(document.getElementById('new-autonomous-channel-id').value);
|
const autonomousChannelId = document.getElementById('new-autonomous-channel-id').value.trim();
|
||||||
const autonomousChannelName = document.getElementById('new-autonomous-channel-name').value;
|
const autonomousChannelName = document.getElementById('new-autonomous-channel-name').value;
|
||||||
const bedtimeChannelIds = document.getElementById('new-bedtime-channel-ids').value
|
const bedtimeChannelIds = document.getElementById('new-bedtime-channel-ids').value
|
||||||
.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id));
|
.split(',').map(id => id.trim()).filter(id => id.length > 0);
|
||||||
|
|
||||||
const enabledFeatures = [];
|
const enabledFeatures = [];
|
||||||
if (document.getElementById('feature-autonomous').checked) enabledFeatures.push('autonomous');
|
if (document.getElementById('feature-autonomous').checked) enabledFeatures.push('autonomous');
|
||||||
@@ -1659,7 +1670,8 @@ async function triggerAutonomous(actionType) {
|
|||||||
|
|
||||||
// Add guild_id as query parameter if a specific server is selected
|
// Add guild_id as query parameter if a specific server is selected
|
||||||
if (selectedServer !== 'all') {
|
if (selectedServer !== 'all') {
|
||||||
endpoint += `?guild_id=${parseInt(selectedServer)}`;
|
// Don't use parseInt() - Discord IDs are too large for JS integers
|
||||||
|
endpoint += `?guild_id=${selectedServer}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
@@ -1968,7 +1980,8 @@ async function sendCustomPrompt() {
|
|||||||
|
|
||||||
// Add guild_id as query parameter if a specific server is selected
|
// Add guild_id as query parameter if a specific server is selected
|
||||||
if (selectedServer !== 'all') {
|
if (selectedServer !== 'all') {
|
||||||
endpoint += `?guild_id=${parseInt(selectedServer)}`;
|
// Don't use parseInt() - Discord IDs are too large for JS integers
|
||||||
|
endpoint += `?guild_id=${selectedServer}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
requestData = { prompt: prompt };
|
requestData = { prompt: prompt };
|
||||||
@@ -2024,14 +2037,24 @@ async function wakeUp() {
|
|||||||
async function sendBedtime() {
|
async function sendBedtime() {
|
||||||
const selectedServer = document.getElementById('manual-server-select').value;
|
const selectedServer = document.getElementById('manual-server-select').value;
|
||||||
|
|
||||||
|
// Debug logging
|
||||||
|
console.log('🛏️ sendBedtime() called');
|
||||||
|
console.log('🛏️ Selected server value:', selectedServer);
|
||||||
|
console.log('🛏️ Selected server type:', typeof selectedServer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let endpoint = '/bedtime';
|
let endpoint = '/bedtime';
|
||||||
|
|
||||||
// Add guild_id as query parameter if a specific server is selected
|
// Add guild_id as query parameter if a specific server is selected
|
||||||
if (selectedServer !== 'all') {
|
if (selectedServer !== 'all') {
|
||||||
endpoint += `?guild_id=${parseInt(selectedServer)}`;
|
// IMPORTANT: Don't use parseInt() - it causes precision loss!
|
||||||
|
// Keep as string since Discord IDs are too large for JS integers
|
||||||
|
console.log('🛏️ Using guild_id (as string):', selectedServer);
|
||||||
|
endpoint += `?guild_id=${selectedServer}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('🛏️ Final endpoint:', endpoint);
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
|||||||
Reference in New Issue
Block a user