You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
571 lines
19 KiB
571 lines
19 KiB
var userID;
|
|
var guildsCache = new Map();
|
|
window.onload = async () =>
|
|
{
|
|
const fragment = new URLSearchParams(window.location.hash.slice(1));
|
|
const [accessToken, tokenType] = [fragment.get('access_token'), fragment.get('token_type')];
|
|
if (!accessToken) return window.location.href = '/';
|
|
updateUser(accessToken, tokenType);
|
|
updateGuildData(accessToken, tokenType);
|
|
document.getElementById('RoleRules').onclick = handleToggleRules;
|
|
};
|
|
|
|
function updateUser(accessToken, tokenType)
|
|
{
|
|
const avatar = document.getElementById('avatar');
|
|
const userName = document.getElementById('userName');
|
|
fetch(`${window.location.origin}/api/getUser`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
authorization: `${tokenType} ${accessToken}`,
|
|
},
|
|
})
|
|
.then(result => result.json())
|
|
.then(response =>
|
|
{
|
|
userID = response.id;
|
|
avatar.style.backgroundImage = `url(https://cdn.discordapp.com/avatars/${response.id}/${response.avatar}.jpeg)`
|
|
userName.textContent = response.username+"'s servers"
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
function updateGuildData(accessToken, tokenType)
|
|
{
|
|
fetch(`${window.location.origin}/api/getGuildData`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
authorization: `${tokenType} ${accessToken}`,
|
|
},
|
|
})
|
|
.then(result => result.json())
|
|
.then(guilds =>
|
|
{
|
|
if(guilds.Error) return console.log(guilds.Error)
|
|
guildsCache = new Map();
|
|
guilds.forEach(guild => {
|
|
console.log(guild)
|
|
guildsCache.set(guild.id, guild)
|
|
});
|
|
makeCards(guilds);
|
|
})
|
|
.catch(console.error);
|
|
|
|
}
|
|
|
|
function handleSettigns(event)
|
|
{
|
|
var popup = document.getElementById('popup');
|
|
var guild = guildsCache.get(event.target.id);
|
|
if(!guild.hasRem) return window.open('https://discord.com/api/oauth2/authorize?client_id=356104008366030863&permissions=8&scope=bot')
|
|
popup.classList.remove('hidden');
|
|
popup.children[1].textContent = guild.name;
|
|
popup.children[1].id = guild.id;
|
|
let music = document.getElementById('music');
|
|
music.textContent = guild.music? 'check_box' :'check_box_outline_blank';
|
|
let strikes = document.getElementById('strikes');
|
|
strikes.textContent = guild.strikes? 'check_box' :'check_box_outline_blank';
|
|
let allowInvites = document.getElementById('allowInvites');
|
|
allowInvites.textContent = guild.allowInvites? 'check_box' : 'check_box_outline_blank';
|
|
music.onclick = requestChange;
|
|
strikes.onclick = requestChange;
|
|
allowInvites.onclick = requestChange;
|
|
|
|
}
|
|
|
|
function handleClose(element)
|
|
{
|
|
if(element.parentNode.id == 'roleRuleWrapper' || element.parentNode.id == 'FeedWrapper')
|
|
{
|
|
document.getElementById('popup').classList.remove('hidden');
|
|
document.getElementById('change').innerText = 'Change';
|
|
document.getElementById('change2').innerText = 'Change';
|
|
}
|
|
if(element.parentNode.id =="FeedWrapper") document.getElementById('ChannelName').classList = '';
|
|
element.parentNode.classList.add('hidden');
|
|
}
|
|
async function requestChange()
|
|
{
|
|
return await fetch(`${window.location.origin}/api/change`,
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({guildID:event.target.parentNode.parentNode.children[1].id,userID, property:event.target.id}), // body data type must match "Content-Type" header
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
if(!res.error)
|
|
{
|
|
let music = document.getElementById('music')
|
|
music.textContent = res.music? 'check_box' :'check_box_outline_blank';
|
|
let strikes = document.getElementById('strikes')
|
|
strikes.textContent = res.strikes? 'check_box' :'check_box_outline_blank';
|
|
let allowInvites = document.getElementById('allowInvites');
|
|
allowInvites.textContent = res.allowInvites? 'check_box' : 'check_box_outline_blank';
|
|
}
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
|
|
async function makeCards(data)
|
|
{
|
|
const canvas = document.createElement('div')
|
|
canvas.classList.add('cards');
|
|
canvas.id = 'cards';
|
|
for(var item of data)
|
|
{
|
|
(async ()=>
|
|
{
|
|
var card = await makeCard(item);
|
|
canvas.appendChild(card);
|
|
})(item)
|
|
}
|
|
document.getElementById('Guilds').appendChild(canvas)
|
|
document.getElementById("cards").onmousemove = e =>
|
|
{
|
|
for(const card of document.getElementsByClassName("card"))
|
|
{
|
|
const rect = card.getBoundingClientRect(),
|
|
x = e.clientX - rect.left,
|
|
y = e.clientY - rect.top;
|
|
|
|
card.style.setProperty("--mouse-x", `${x}px`);
|
|
card.style.setProperty("--mouse-y", `${y}px`);
|
|
let interval = null;
|
|
let target = card.children[0].children[1].children[0].children[0].children[0];
|
|
let imgTarget = card.children[0].children[0].children[0]
|
|
card.addEventListener('mouseenter', ()=>
|
|
{
|
|
if(imgTarget.classList.contains('imgfalse')) return
|
|
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
let iteration = 0;
|
|
interval = setInterval(() =>
|
|
{
|
|
target.innerText = target.innerText
|
|
.split("")
|
|
.map((letter, index) => {
|
|
if(index < iteration) {
|
|
return target.dataset.value[index];
|
|
}
|
|
|
|
return letters[Math.floor(Math.random() * 26)]
|
|
})
|
|
.join("");
|
|
|
|
if(iteration >= target.dataset.value.length)
|
|
{
|
|
clearInterval(interval);
|
|
}
|
|
iteration += 4 ;
|
|
}, 1)
|
|
|
|
})
|
|
card.addEventListener('mouseleave', ()=>
|
|
{
|
|
clearInterval(interval);
|
|
target.innerText = target.dataset.value;
|
|
//reset
|
|
})
|
|
}
|
|
}
|
|
document.getElementById('cards').onclick = handleSettigns;
|
|
}
|
|
async function makeCard(guild)
|
|
{
|
|
const card = document.createElement('div')
|
|
card.innerHTML = ` <div id='${guild.id}'class="card">
|
|
<div class="card-content ">
|
|
<div class="card-image ">
|
|
<div class="img img${guild.hasRem}" style="background-image:url(${guild.icon});" ></div>
|
|
</div>
|
|
<div class="card-info-wrapper ${guild.hasRem}">
|
|
<div class="card-info">
|
|
<div class="card-info-title">
|
|
<h3 data-value="${guild.name}" class="fancy">${guild.name}</h3>
|
|
<h4>${guild.memberCount?guild.memberCount + ' users on the server.':'Rem is not on this server yet.'} </h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>`
|
|
return card
|
|
//background-position:0%; filter:grayscale(${guild.hasRem?0.4:0.7})
|
|
}
|
|
async function getRules(guildID)
|
|
{
|
|
return await fetch(`${window.location.origin}/api/getRules`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {guildID},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
return res
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
async function handleToggleRules(element)
|
|
{
|
|
var guildID = element.target.parentNode.getElementsByTagName('h3')[0].id;
|
|
var rulesElement=document.getElementById('rules');
|
|
var rules = await getRules(guildID);
|
|
document.getElementById('roleID').innerHTML = '';
|
|
for(var role of guildsCache.get(guildID).roles)
|
|
{
|
|
document.getElementById('roleID').innerHTML += `<option value="${role.id}">${role.name}</option>`;
|
|
}
|
|
document.getElementById('emojiID').innerHTML = '';
|
|
for(var emoji of guildsCache.get(guildID).emojis)
|
|
{
|
|
document.getElementById('emojiID').innerHTML += `<option value="${emoji.id}">${emoji.name}</option>`;
|
|
}
|
|
|
|
if(!rules) return
|
|
var ruleArr = []
|
|
for(var rule of rules)
|
|
{
|
|
ruleArr.push(`<p id="${rule._id}" onclick="changeRule(this)" class="addRoleName">${rule.roleName}</p>`)
|
|
}
|
|
rulesElement.innerHTML = `
|
|
<i onclick="handleClose(this)" class="close material-symbols-outlined" id="close_bt">
|
|
cancel
|
|
</i>
|
|
<p id="newRole" onclick="addRule(this)">New Rule</p>
|
|
${ruleArr.join('')}
|
|
`
|
|
rulesElement.classList.remove('hidden')
|
|
}
|
|
async function getFeeds(gid)
|
|
{
|
|
return await fetch(`${window.location.origin}/api/getFeeds`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {guildid:gid},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
return res
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
async function getFeed(feedID)
|
|
{
|
|
return await fetch(`${window.location.origin}/api/getFeed`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {feedID},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
return res[0]
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
async function getChannelID(id)
|
|
{
|
|
if(url.split('@').length<1) return false
|
|
return await fetch(url)
|
|
.then(handleResponse)
|
|
.then(handleData)
|
|
.catch(handleError);
|
|
function handleResponse(response)
|
|
{
|
|
if(response.ok) return response.text();
|
|
}
|
|
function handleError(error)
|
|
{
|
|
return error;
|
|
}
|
|
function handleData(data)
|
|
{
|
|
return data ? data.split('https://www.youtube.com/feeds/videos.xml?channel_id=')[1].split('"')[0] : false;
|
|
}
|
|
}
|
|
async function getChannelName(channelID)
|
|
{
|
|
return await fetch(`${window.location.origin}/api/getChannelName`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {channelID},
|
|
})
|
|
.then(response=>
|
|
{
|
|
if(response.ok) return response.text();
|
|
})
|
|
.then(data=>
|
|
{
|
|
return data.replaceAll('"','')
|
|
})
|
|
.catch(error=>
|
|
{
|
|
return error;
|
|
});
|
|
}
|
|
async function handleToggleFeeds(element)
|
|
{
|
|
var guildID = element.parentNode.getElementsByTagName('h3')[0].id;
|
|
var feedElement=document.getElementById('feeds');
|
|
var feeds = await getFeeds(guildID);
|
|
if(!feeds) return
|
|
var ruleArr = [];
|
|
for (let i = 0; i < feeds.length; i++) {
|
|
var ytchannelname = await getChannelName(feeds[i].YTChannelId)
|
|
ruleArr.push(`<p id="${feeds[i]._id}" onclick="updateFeed(this)">${ytchannelname}</p>`)
|
|
}
|
|
|
|
feedElement.innerHTML = `
|
|
<i onclick="handleClose(this)" class="close material-symbols-outlined" id="close_bt">
|
|
cancel
|
|
</i>
|
|
<p id="newFeed" onclick="addFeed(this)">New Feed</p>
|
|
${ruleArr.join('')}
|
|
`
|
|
feedElement.classList.remove('hidden');
|
|
|
|
|
|
}
|
|
function deleteRule(element)
|
|
{
|
|
var ruleID = document.getElementById('roleRule').classList[1];
|
|
fetch(`${window.location.origin}/api/deleteRule`,
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
headers: {ruleID},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
console.log(res);
|
|
if(res.success)
|
|
{
|
|
element.parentNode.classList.add('hidden')
|
|
document.getElementById('popup').classList.remove('hidden');
|
|
}
|
|
else alert(res.error);
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
function addRule(element)
|
|
{
|
|
|
|
element.parentNode.classList.add('hidden');
|
|
element.parentNode.parentNode.classList.add('hidden');
|
|
var ruleWrapper = document.getElementById('roleRuleWrapper');
|
|
ruleWrapper.classList.remove('hidden');
|
|
document.getElementsByClassName('roleRuleWrapper')[0].setAttribute('data-before','Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in elit vel nisi sagittis egestas. Donec a laoreet justo. Morbi interdum orci quis tempor tempor. Aenean tempus urna eget placerat maximus. Maecenas vitae condimentum felis, et mollis velit. Duis diam arcu, volutpat ut lectus et, aliquam vestibulum ante. Mauris dignissim libero quis condimentum interdum. Morbi dictum ex faucibus mi vehicula, sed blandit ex molestie. Pellentesque lacinia blandit pellentesque. Nullam at nisl dui.')
|
|
document.getElementById('roleRule').innerText = 'New Rule'
|
|
document.getElementById('roleID').placeholder = 'Role ID'
|
|
document.getElementById('emojiID').placeholder = 'Emoji ID'
|
|
document.getElementById('messageID').placeholder = 'Message ID'
|
|
document.getElementById('emojiImg').src = 'images/favicon.ico';
|
|
document.getElementById('change').innerText = 'Add';
|
|
}
|
|
function updateRule(element)
|
|
{
|
|
var isNew=false;
|
|
if(element.parentNode.children[1].innerText == 'New Rule') isNew = true;
|
|
var ruleID;
|
|
if(!isNew) ruleID = document.getElementById('roleRule').classList[1];
|
|
var messageid = document.getElementById('messageID').value;
|
|
var roleid =document.getElementById('roleID').value;
|
|
var emojiid =document.getElementById('emojiID').value;
|
|
var gid = document.getElementsByClassName('guildname')[0].id;
|
|
fetch(`${window.location.origin}/api/updateRule`,
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
headers: {messageid, roleid, emojiid, gid,isNew, ruleID},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
if(res.success)
|
|
{
|
|
element.parentNode.classList.add('hidden')
|
|
document.getElementById('popup').classList.remove('hidden');
|
|
}
|
|
else alert(res.error);
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
|
|
async function getRule(id)
|
|
{
|
|
return await fetch(`${window.location.origin}/api/getRules`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {id},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
return res
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
async function getMessage(guildid, messageid)
|
|
{
|
|
return await fetch(`${window.location.origin}/api/getMessage`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {guildid, messageid},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
return res
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
async function changeRule(element)
|
|
{
|
|
var rule = await getRule(element.id)
|
|
var message = await getMessage(rule.gID,rule.mID);
|
|
message = message.message;
|
|
element.parentNode.classList.add('hidden');
|
|
element.parentNode.parentNode.classList.add('hidden')
|
|
var ruleWrapper = document.getElementById('roleRuleWrapper');
|
|
ruleWrapper.classList.remove('hidden');
|
|
document.getElementsByClassName('roleRuleWrapper')[0].setAttribute('data-before', message)
|
|
document.getElementById('roleRule').innerText = rule.roleName;
|
|
document.getElementById('roleRule').classList = 'roleRule';
|
|
document.getElementById('roleRule').classList.add(rule._id);
|
|
document.getElementById('roleID').value = rule.roleID;
|
|
document.getElementById('emojiID').value = rule.roleEmoji;
|
|
document.getElementById('messageID').value = rule.mID;
|
|
document.getElementById('emojiImg').src = `https://cdn.discordapp.com/emojis/${rule.roleEmoji}.webp`;
|
|
}
|
|
function addFeed(element)
|
|
{
|
|
document.getElementById('DCchannelID').innerHTML = '';
|
|
for(var channel of guildsCache.get(element.parentNode.parentNode.childNodes[3].id).guildTextChannels)
|
|
{
|
|
document.getElementById('DCchannelID').innerHTML += `<option value="${channel.id}">${channel.name}</option>`;
|
|
}
|
|
element.parentNode.classList.add('hidden');
|
|
element.parentNode.parentNode.classList.add('hidden');
|
|
var FeedWrapper = document.getElementById('FeedWrapper');
|
|
FeedWrapper.classList.remove('hidden');
|
|
document.getElementById('ChannelName').innerText = 'New Feed'
|
|
// document.getElementById('DCchannelID').placeholder = '';
|
|
document.getElementById('YTchannelID').placeholder = '';
|
|
document.getElementById('CostumMessageI').placeholder = '';
|
|
document.getElementById('change2').innerText = 'Add';
|
|
}
|
|
async function updateFeed(element)
|
|
{
|
|
var feed = await getFeed(element.id)
|
|
element.parentNode.classList.add('hidden');
|
|
element.parentNode.parentNode.classList.add('hidden');
|
|
var FeedWrapper = document.getElementById('FeedWrapper');
|
|
FeedWrapper.classList.remove('hidden');
|
|
document.getElementById('DCchannelID').innerHTML = '';
|
|
for(var channel of guildsCache.get(element.parentNode.parentNode.childNodes[3].id).guildTextChannels)
|
|
{
|
|
document.getElementById('DCchannelID').innerHTML += `<option value="${channel.id}">${channel.name}</option>`;
|
|
}
|
|
document.getElementById('ChannelName').innerText = element.textContent;
|
|
document.getElementById('ChannelName').classList ='';
|
|
document.getElementById('ChannelName').classList.add(element.id);
|
|
document.getElementById('DCchannelID').value = feed.ChannelId;
|
|
document.getElementById('YTchannelID').value = 'https://www.youtube.com/@' + await getChannelName(feed.YTChannelId);
|
|
document.getElementById('CostumMessageI').value = feed.CostumMessage;
|
|
}
|
|
|
|
function deleteFeed(element)
|
|
{
|
|
var feedID = document.getElementById('ChannelName').classList[0];
|
|
fetch(`${window.location.origin}/api/deleteFeed`,
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
headers: {feedID},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
if(res.success)
|
|
{
|
|
element.parentNode.classList.add('hidden')
|
|
document.getElementById('popup').classList.remove('hidden');
|
|
}
|
|
else alert(res.error);
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
|
|
async function _updateFeed(element)
|
|
{
|
|
feedID = document.getElementById('ChannelName').classList.value;
|
|
var gid = document.getElementsByClassName('guildname')[0].id;
|
|
var DCchannelID = document.getElementById('DCchannelID').value;
|
|
var YTchannelID = document.getElementById('YTchannelID').value;
|
|
var CostumMessageI = document.getElementById('CostumMessageI').value;
|
|
var YTValid = await channelCheck(YTchannelID);
|
|
if(!YTValid) return handleWrongLink();
|
|
fetch(`${window.location.origin}/api/addFeed`,
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
headers: {DCchannelID, YTchannelID, CostumMessageI, gid, feedID},
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
if(res.success)
|
|
{
|
|
element.parentNode.classList.add('hidden')
|
|
document.getElementById('popup').classList.remove('hidden');
|
|
}
|
|
else alert(res.error);
|
|
})
|
|
.catch(console.error);
|
|
|
|
}
|
|
function handleWrongLink()
|
|
{
|
|
window.alert('Youtube channel not found, verify the link.')
|
|
return document.getElementById('YTchannelID').style = "border: 2px solid red"
|
|
}
|
|
async function channelCheck(yt)
|
|
{
|
|
var res = await fetch(`${window.location.origin}/api/checkChannel`,
|
|
{
|
|
method: "GET",
|
|
mode: "cors",
|
|
headers: {id:yt},
|
|
})
|
|
.then(response=>
|
|
{
|
|
if(response.ok) return response.text();
|
|
})
|
|
.then(data=>
|
|
{
|
|
return data.replaceAll('"','')
|
|
})
|
|
.catch(error=>
|
|
{
|
|
return error;
|
|
});
|
|
return res
|
|
}
|
|
function handleStrikesDashboard(element)
|
|
{
|
|
const guildID = element.parentNode.getElementsByTagName('h3')[0].id;
|
|
window.open(`${window.location.origin}/strikes/${guildID}/${userID}`, '_blank');
|
|
} |