feat: Agregar lógica para verificar la presencia del bot en los gremios y actualizar la interfaz de usuario
This commit is contained in:
@@ -14,18 +14,32 @@
|
||||
if(!btn) return;
|
||||
btn.addEventListener('click', async function(e){
|
||||
e.preventDefault();
|
||||
const guildId = '<%= selectedGuild %>';
|
||||
const injected = '<%= selectedGuild || "" %>';
|
||||
let guildId = injected || '';
|
||||
if(!guildId && typeof location !== 'undefined'){
|
||||
try{
|
||||
const parts = location.pathname.split('/').filter(Boolean);
|
||||
// expect /dashboard/<guildId>/...
|
||||
if(parts.length >= 2 && parts[0] === 'dashboard') guildId = parts[1];
|
||||
}catch(e){ guildId = '' }
|
||||
}
|
||||
if(!guildId) return;
|
||||
|
||||
// visual feedback: disable while loading
|
||||
btn.disabled = true;
|
||||
btn.classList.add('opacity-50','pointer-events-none');
|
||||
try{
|
||||
const res = await fetch(`/api/dashboard/${encodeURIComponent(guildId)}/roles`, { method: 'GET', headers: { 'Accept': 'application/json' } });
|
||||
if(!res.ok) {
|
||||
return;
|
||||
}
|
||||
const j = await res.json();
|
||||
if(j && Array.isArray(j.roles)){
|
||||
window.dispatchEvent(new CustomEvent('roles:loaded', { detail: { roles: j.roles } }));
|
||||
if(res && res.ok){
|
||||
const j = await res.json();
|
||||
if(j && Array.isArray(j.roles)){
|
||||
window.dispatchEvent(new CustomEvent('roles:loaded', { detail: { roles: j.roles } }));
|
||||
}
|
||||
}
|
||||
}catch(err){ /* ignore errors */ }
|
||||
// restore
|
||||
btn.disabled = false;
|
||||
btn.classList.remove('opacity-50','pointer-events-none');
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
@@ -135,6 +135,39 @@
|
||||
// close other menus first
|
||||
closeAllMenus();
|
||||
openDropdown(btn, list);
|
||||
// runtime-check: for items that were not marked as having the bot, try fetching roles
|
||||
(async function refreshMissingBotFlags(){
|
||||
try{
|
||||
const items = Array.from(list.querySelectorAll('.guild-item')) || [];
|
||||
for(const el of items){
|
||||
try{
|
||||
const botAttr = el.getAttribute('data-bot');
|
||||
if(botAttr === '1') continue;
|
||||
const gid = el.getAttribute('data-id');
|
||||
if(!gid) continue;
|
||||
const res = await fetch(`/api/dashboard/${encodeURIComponent(gid)}/roles`, { method: 'GET', headers: { 'Accept': 'application/json' } });
|
||||
if(res && res.ok){
|
||||
// update element to show the bot is present
|
||||
el.setAttribute('data-bot','1');
|
||||
el.classList.remove('opacity-60');
|
||||
const infoSpan = el.querySelector('.text-xs');
|
||||
if(infoSpan) infoSpan.textContent = '(Bot)';
|
||||
const nameDiv = el.querySelector('.flex-1');
|
||||
if(nameDiv){
|
||||
// ensure (Bot) marker exists after name
|
||||
let marker = nameDiv.querySelector('.bot-marker');
|
||||
if(!marker){
|
||||
marker = document.createElement('span');
|
||||
marker.className = 'ml-2 text-xs text-emerald-300 bot-marker';
|
||||
marker.textContent = '(Bot)';
|
||||
nameDiv.appendChild(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(e){ /* ignore per-item errors */ }
|
||||
}
|
||||
}catch(e){ /* ignore */ }
|
||||
})();
|
||||
}
|
||||
});
|
||||
// Use event delegation on the list so clicks on children are handled reliably
|
||||
|
||||
Reference in New Issue
Block a user