|
|
|
@ -71,7 +71,7 @@ function handleSettigns(event)
|
|
|
|
|
|
|
|
|
|
function handleClose(element)
|
|
|
|
|
{
|
|
|
|
|
if(element.parentNode.id == 'roleRuleWrapper') document.getElementById('popup').classList.remove('hidden');
|
|
|
|
|
if(element.parentNode.id == 'roleRuleWrapper' || element.parentNode.id == 'FeedWrapper') document.getElementById('popup').classList.remove('hidden');
|
|
|
|
|
element.parentNode.classList.add('hidden');
|
|
|
|
|
}
|
|
|
|
|
async function requestChange()
|
|
|
|
@ -178,13 +178,103 @@ async function handleToggleRules(element)
|
|
|
|
|
<i onclick="handleClose(this)" class="close material-symbols-outlined" id="close_bt">
|
|
|
|
|
cancel
|
|
|
|
|
</i>
|
|
|
|
|
<p id="newRole" onclick="addRule(this)">New Role</p>
|
|
|
|
|
<p id="newRole" onclick="addRule(this)">New Rule</p>
|
|
|
|
|
${ruleArr.join('')}
|
|
|
|
|
`
|
|
|
|
|
rulesElement.classList.remove('hidden')
|
|
|
|
|
}
|
|
|
|
|
function handleToggleFeeds(element)
|
|
|
|
|
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)
|
|
|
|
@ -242,7 +332,6 @@ function updateRule(element)
|
|
|
|
|
.then(result => result.json())
|
|
|
|
|
.then(res =>
|
|
|
|
|
{
|
|
|
|
|
console.log(res);
|
|
|
|
|
if(res.success)
|
|
|
|
|
{
|
|
|
|
|
element.parentNode.classList.add('hidden')
|
|
|
|
@ -294,9 +383,88 @@ async function changeRule(element)
|
|
|
|
|
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').placeholder = rule.roleID;
|
|
|
|
|
document.getElementById('emojiID').placeholder = rule.roleEmoji;
|
|
|
|
|
document.getElementById('messageID').placeholder = rule.mID;
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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 = '';
|
|
|
|
|
}
|
|
|
|
|
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('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 = feed.YTChannelId;
|
|
|
|
|
document.getElementById('CostumMessageI').value = feed.CostumMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteFeed(element)
|
|
|
|
|
{
|
|
|
|
|
var feedID = document.getElementById('ChannelName').classList[1];
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _updateFeed(element)
|
|
|
|
|
{
|
|
|
|
|
var isNew=false;
|
|
|
|
|
if(element.parentNode.children[1].innerText == 'New Feed') isNew = true;
|
|
|
|
|
var feedID;
|
|
|
|
|
if(!isNew) feedID = document.getElementById('ChannelName').classList[1];
|
|
|
|
|
console.log('fid', feedID)
|
|
|
|
|
var gid = document.getElementsByClassName('guildname')[0].id;
|
|
|
|
|
console.log('gid', gid)
|
|
|
|
|
var DCchannelID = document.getElementById('DCchannelID').value;
|
|
|
|
|
var YTchannelID = document.getElementById('YTchannelID').value;
|
|
|
|
|
var CostumMessageI = document.getElementById('CostumMessageI').value;
|
|
|
|
|
fetch(`${window.location.origin}/api/addFeed`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
headers: {DCchannelID, YTchannelID, CostumMessageI, gid,isNew, 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);
|
|
|
|
|
}
|