diff --git a/controller/api.js b/controller/api.js index 68726e0..8996251 100644 --- a/controller/api.js +++ b/controller/api.js @@ -281,9 +281,11 @@ exports.addFeed = (bot)=> var headers= req.headers; var args = [headers.gid, headers.dcchannelid, headers.ytchannelid] const validationResult = await confirmArgs(args, bot); - if(headers.isnew=="true") + // console.log('Before new or old check', validationResult) + if (validationResult.error) return res.json({error:validationResult.error}); + if(!headers.feedid) { - if (validationResult.error) return res.json({error:validationResult.error}) + //new var feed = new feedsM(); feed.gID = headers.gid; feed.ChannelId = validationResult.channelId @@ -299,7 +301,6 @@ exports.addFeed = (bot)=> { feedsM.findOne({id:args.id}).then(feed=> { - console.log('here', feed) if(!feed) return res.json({error:'DB Error'}); feed.gID = headers.gid; feed.ChannelId = validationResult.channelId @@ -320,7 +321,7 @@ async function confirmArgs(args, bot) var channelURL = args[2] async function getChannelId(url) { - if(url.split('@').length<1) return false + if(url.split('@').length<1) return return await fetch(url) .then(handleResponse) .then(handleData) @@ -331,7 +332,7 @@ async function confirmArgs(args, bot) } function handleError(error) { - return error; + return {error:'Bad youtube channel link.'}; } function handleData(data) { @@ -340,8 +341,9 @@ async function confirmArgs(args, bot) } const YTChannelId = await getChannelId(channelURL); - const exists = await bot.channels.fetch(channelId).then(channel=>{return channel }).catch(()=>{return null}); - if(!exists) return {error:'Provided channel id does not exist.'} + if(YTChannelId.error) return {error:YTChannelId.error} + const discordChannel = await bot.channels.fetch(channelId).then(channel=>{return channel }).catch(()=>{return null}); + if(!discordChannel) return {error:'Provided discord channel id does not exist.'} var name = await fetch(`https://www.youtube.com/feeds/videos.xml?channel_id=${YTChannelId}`) .then(response => { @@ -359,8 +361,7 @@ async function confirmArgs(args, bot) return data.feed.author.name._text }) .catch(error=>{return error;}); - if(!name) return {error:'Provided Youtube channel does not exist.'} - return {YTChannelId, channelId, name, channelName:exists.name} + return {YTChannelId, channelId, name, channelName:discordChannel.name} } exports.deleteFeed = (req,res) => { diff --git a/public/css/dashboard.css b/public/css/dashboard.css index 9751f5c..42476ae 100644 --- a/public/css/dashboard.css +++ b/public/css/dashboard.css @@ -473,6 +473,10 @@ input { left:70%; } +#change2 +{ + left:70%; +} #delete { left:30%; diff --git a/public/js/dashboard.js b/public/js/dashboard.js index 539b3fa..f2656cf 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -72,7 +72,13 @@ function handleSettigns(event) function handleClose(element) { - if(element.parentNode.id == 'roleRuleWrapper' || element.parentNode.id == 'FeedWrapper') document.getElementById('popup').classList.remove('hidden'); + 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() @@ -349,6 +355,7 @@ function addRule(element) 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) { @@ -437,6 +444,7 @@ function addFeed(element) document.getElementById('DCchannelID').placeholder = ''; document.getElementById('YTchannelID').placeholder = ''; document.getElementById('CostumMessageI').placeholder = ''; + document.getElementById('change2').innerText = 'Add'; } async function updateFeed(element) { @@ -449,7 +457,7 @@ async function updateFeed(element) 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('YTchannelID').value = 'https://www.youtube.com/@' + await getChannelName(feed.YTChannelId); document.getElementById('CostumMessageI').value = feed.CostumMessage; } @@ -477,13 +485,8 @@ function deleteFeed(element) 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) + feedID = document.getElementById('ChannelName').classList.value; 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; @@ -491,7 +494,7 @@ function _updateFeed(element) { method: "POST", mode: "cors", - headers: {DCchannelID, YTchannelID, CostumMessageI, gid,isNew, feedID}, + headers: {DCchannelID, YTchannelID, CostumMessageI, gid, feedID}, }) .then(result => result.json()) .then(res => diff --git a/views/dashboard.ejs b/views/dashboard.ejs index 7ac24c6..0537d09 100644 --- a/views/dashboard.ejs +++ b/views/dashboard.ejs @@ -60,14 +60,14 @@ cancel -

Discord Channel:

+

Discord Channel ID:

Youtube Channel:

Costum message:

- +