@ -2,261 +2,191 @@ const GuildM = require('../models/guilds');
const STRIKES = require ( '../models/strikes' ) ;
const STRIKES = require ( '../models/strikes' ) ;
const roleRulesM = require ( '../models/autoRoleRule' ) ;
const roleRulesM = require ( '../models/autoRoleRule' ) ;
const feedsM = require ( '../models/feeds' ) ;
const feedsM = require ( '../models/feeds' ) ;
const xmlparser = require ( 'xml-js' )
const xmlparser = require ( 'xml-js' ) ;
const { isValidObjectId } = require ( 'mongoose' )
const { DiscordAPI , getRules , confirmArgsForYTFeed } = require ( '../lib' )
exports . home = async ( req , res ) =>
exports . getUser = ( io ) =>
{
return ( req , res ) =>
{
fetch ( 'https://discord.com/api/users/@me' ,
{
{
headers : {
res . render ( 'home.ejs' ) ;
authorization : req . headers . authorization ,
}
} ,
} )
exports . redirect = async ( req , res ) =>
. then ( result => result . json ( ) )
. then ( response =>
{
{
res . json ( response ) ;
res . render ( 'redirect.ejs' ) ;
} )
}
}
} ;
exports . guildData = ( io , bot ) =>
exports . dashboard = ( bot ) =>
{
{
return async ( req , res ) =>
return async ( req , res ) =>
{
let userGuilds = await fetch ( 'https://discord.com/api/users/@me/guilds' ,
{
headers : {
authorization : req . headers . authorization ,
} ,
} )
. then ( result => result . json ( ) )
. then ( response =>
{
{
if ( response . message ) return response . message
const userPlaceholder =
return response . filter ( x => x . owner == true ) ;
} )
var promises = [ ] ;
if ( typeof userGuilds == 'string' ) return res . json ( { Error : userGuilds } )
for ( var guild of userGuilds ) {
promises . push ( new Promise ( ( resolve , reject ) => {
( async ( guild ) =>
{
{
id : '' ,
username : 'placeholder' ,
avatar : '' ,
}
if ( ! req . headers . cookie ) return res . render ( 'dashboard.ejs' , { user : userPlaceholder , guilds : guildsPlaceholder } ) ;
const connector = new DiscordAPI ( req . headers . cookie , bot ) ;
const user = await connector . getUser ( ) ;
const guilds = await connector . getGuildsFull ( ) ;
var aux = await getSpecificGuildData ( guild . id ) ;
res . render ( 'dashboard.ejs' , { user , guilds } ) ;
var roleRules = aux ? await getRoleRules ( guild . id ) : null ;
var guildTextChannels = aux ? aux . TextChannels : null ;
var emojis = aux ? aux . emojis : null ;
var roles = aux ? aux . roles : null ;
const dataObject =
{
id : guild . id ,
music : aux . guild ? aux . guild . guild [ 0 ] . music : false ,
strikes : aux . guild ? aux . guild . guild [ 0 ] . strikes : false ,
allowInvites : aux ? . guild ? . guild [ 0 ] ? . allowInvites ,
name : guild . name ,
icon : guild . icon ? ` https://cdn.discordapp.com/icons/ ${ guild . id } / ${ guild . icon } .webp ` : 'https://cdn3.iconfinder.com/data/icons/popular-services-brands-vol-2/512/discord-512.png' ,
features : guild . features ,
hasRem : aux . extra ? true : false ,
memberCount : aux . extra ? aux . extra . memberCount : null ,
roleRules ,
guildTextChannels ,
emojis ,
roles
} ;
resolve ( dataObject ) ;
} ) ( guild )
} ) ) ;
}
}
Promise . all ( promises ) . then ( ( values ) => {
return res . json ( values ) ;
} ) ;
}
}
async function getSpecificGuildData ( guildID )
exports . getModerator = ( bot ) =>
{
var extra = bot . guilds . cache . get ( guildID )
var guild = await GuildM . find ( { gID : guildID } )
. then ( ( guild , err ) =>
{
{
if ( err || guild . length == 0 ) return ;
return async ( req , res ) =>
return { guild } ;
} ) ;
var TextChannels = [ ] ;
var emojis = [ ] ;
var roles = [ ] ;
if ( extra )
{
for ( var channel of extra . channels . cache )
{
if ( channel [ 1 ] . type == 0 )
{
TextChannels . push (
{
{
'id' : channel [ 0 ] ,
const modId = { moderatorid } = req . params ;
'name' : channel [ 1 ] . name
const user = await bot . users . cache . get ( '1203446477024927764' ) ;
} ) ;
res . render ( 'user.ejs' , { user } )
}
}
}
for ( var emoji of extra . emojis . cache )
{
emojis . push (
{
'id' : emoji [ 0 ] ,
'name' : emoji [ 1 ] . name
} ) ;
}
}
for ( var role of extra . roles . cache )
exports . guilds = ( bot ) =>
{
{
roles . push (
return async ( req , res ) =>
{
{
'id' : role [ 0 ] ,
try {
'name' : role [ 1 ] . name
const connector = new DiscordAPI ( req . headers . cookie , bot ) ;
} ) ;
const userGuilds = await connector . getUserGuilds ( ) ;
const guilds = await connector . getGuildsFull ( userGuilds ) ;
res . render ( 'guilds.ejs' , { guilds } ) ;
} catch ( err ) {
console . error ( err ) ;
res . status ( 500 ) . send ( 'Internal Server Error' ) ;
}
}
}
}
return { guild , extra , TextChannels , emojis , roles } ;
}
}
async function getRoleRules ( guildid )
exports . gDash = ( bot ) =>
{
{
return await roleRulesM . find ( { gID : guildid } ) . then ( ( err , rules ) =>
return async ( req , res ) =>
{
{
if ( err || rules . length == 0 ) return
const userid = await new DiscordAPI ( req . headers . cookie , bot ) . getUserId ( ) ;
return rules
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . id ) ;
} )
res . render ( 'guildPopup.ejs' , { guild , userid } )
}
}
}
}
exports . guildUpdate = ( bot ) =>
exports . updateGuild = ( io ) =>
{
{
return ( req , res ) =>
return async ( req , res ) =>
{
GuildM . findOne ( { gID : req . body . guildID } )
. then (
( guild , err ) =>
{
if ( err || guild . length ) return res . json ( { Error : 'No guild' } ) ;
guild [ ` ${ req . body . property } ` ] = ! guild [ ` ${ req . body . property } ` ] ;
GuildM . updateOne ( { gID : req . body . guildID } , guild ) . then ( ( ) =>
{
{
return res . json ( guild ) ;
/ * *
} )
* ! /gdash/ : id / : setting ? '
} )
* /
const original = await GuildM . find ( { gID : req . params . id } ) . then ( guild => { return guild [ 0 ] } ) ;
var aux = { }
aux [ req . params . setting ] = ! original [ req . params . setting ]
const updated = await GuildM . findOneAndUpdate ( { gID : req . params . id } , aux )
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . id ) ;
res . render ( 'guildPopup.ejs' , { guild } )
}
}
}
}
exports . getMessage = ( bot ) =>
exports . rDash = ( bot ) =>
{
{
//! /rolerulesdash/:id -> Discord Guild Id (GuildId)
return async ( req , res ) =>
return async ( req , res ) =>
{
{
if ( ! req . headers . guildid && ! req . headers . messageid ) return res . json ( { error : 'No gid or messageid or both.' } )
const roles = await getRules ( req . params . id ) ;
const TextChannels = bot . guilds . cache . get ( req . headers . guildid ) . channels . cache . filter ( x => x . type == 0 ) ;
res . render ( 'roleRules.ejs' , { roles , id : req . params . id } ) ;
TextChannels . forEach ( channel => {
}
( async ( channel ) =>
}
exports . roleChange = ( bot ) =>
{
{
var message
//! '/roleChange/:id/:guildid'
try {
return async ( req , res ) =>
message = await channel . messages . fetch ( req . headers . messageid ) ;
{
} catch ( error ) {
const role = await getRules ( req . params . id ) ;
//message doesn't exist on this channel or at all
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . guildid ) ;
}
res . render ( 'rolePopup.ejs' , { role , id : req . params . id , guild } ) ;
if ( message )
{
message = message . content
if ( message . split ( '***' ) . length % 2 == 1 ) message = message . replaceAll ( '***' , '' ) ;
if ( message . split ( '**' ) . length % 2 == 1 ) message = message . replaceAll ( '**' , '' ) ;
if ( message . split ( '*' ) . length % 2 == 1 ) message = message . replaceAll ( '*' , '' ) ;
if ( message . split ( '~~' ) . length % 2 == 1 ) message = message . replaceAll ( '~~' , '' ) ;
if ( message . split ( '```' ) . length % 2 == 1 ) message = message . replaceAll ( '```' , '' ) ;
if ( message . split ( '``' ) . length % 2 == 1 ) message = message . replaceAll ( '``' , '' ) ;
if ( message . split ( '`' ) . length % 2 == 1 ) message = message . replaceAll ( '`' , '' ) ;
res . json ( { message } )
}
} ) ( channel )
} ) ;
}
}
}
}
exports . getRules = async ( req , res ) =>
exports . saveRoleChange = ( bot ) =>
{
//! '/rolechange
return async ( req , res ) =>
{
{
var payload ;
const body = req . body ;
if ( req . headers . guildid )
if ( ! body . roleid || ! body . emojiid || ! body . messageid || ! body . guildid ) return res . status ( 400 ) . send ( 'Bad Request' ) ;
const extra = await getRoleName ( req . body , bot )
if ( extra . error ) return res . status ( 400 ) . send ( ` Bad Request - ${ extra . error } ` )
var rule =
{
{
payload = await roleRulesM . find ( { gID : req . headers . guildid } )
gID : body . guildid ,
. then ( rules => { return rules } )
mID : body . messageid ,
. catch ( ( ) => { return null } )
roleID : body . roleid ,
return res . json ( payload ) ;
roleEmoji : body . emojiid ,
roleName : extra . roleName ,
}
}
payload = await roleRulesM . findOne ( { _id : req . headers . id } )
const updatedRule = await roleRulesM . findOneAndUpdate ( { _id : req . params . id } , rule ) ;
. then ( rule => { return rule } )
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . guildid ) ;
. catch ( ( ) => { return null } )
res . render ( 'rolePopup.ejs' , { role : updatedRule , id : body . id , guild } ) ;
return res . json ( payload ) ;
}
}
exports . deleteRule = async ( req , res ) =>
}
exports . deleteRole = async ( req , res ) =>
{
{
var deleted = await roleRulesM . findByIdAndDelete ( req . headers . ruleid )
const deleted = await roleRulesM . findOneAndDelete ( { _id : req . params . id } ) ;
. then ( ( ) => { return { success : 'Done' } } )
const roles = await getRules ( req . params . guildid ) ;
. catch ( ( ) => { return { error : 'Failed to delete' } } ) ;
res . render ( 'roleRules.ejs' , { roles , id : req . params . guildid } ) ;
res . json ( deleted ) ;
}
}
exports . updateRule = ( bot ) =>
exports . newRoleRule = ( bot ) =>
{
{
//! '/newrolerule/:guildid'
return async ( req , res ) =>
return async ( req , res ) =>
{
{
let args = req . headers ;
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildData ( req . params . guildid ) ;
if ( args . isnew == 'true' )
const role = 'N/A' ;
{
res . render ( 'rolePopup.ejs' , { guild , role , id : req . params . guildid } )
const validationResult = await confirmArgs ( args ) ;
}
if ( validationResult . error ) return res . json ( { error : validationResult . error } )
var rule = new roleRulesM ( ) ;
rule . gID = validationResult . gID ;
rule . mID = validationResult . mID ;
rule . roleID = validationResult . roleID ;
rule . roleEmoji = validationResult . roleEmoji ;
rule . roleName = validationResult . roleName ;
rule . save ( err =>
{
if ( err ) res . json ( err ) ;
res . json ( { success : true , rule } )
} )
}
}
else
exports . newRule = ( bot ) =>
{
{
const validationResult = await confirmArgs ( args ) ;
return async ( req , res ) =>
if ( validationResult . error ) return res . json ( { error : validationResult . error } )
roleRulesM . findOne ( { id : args . id } ) . then ( rule =>
{
{
if ( ! rule ) return res . json ( { error : 'DB Error' } ) ;
const body = req . body ;
rule . gID = validationResult . gID ;
if ( ! body . roleid || ! body . emojiid || ! body . messageid || ! body . guildid ) return res . status ( 400 ) . send ( 'Bad Request' ) ;
rule . mID = validationResult . mID ;
const extra = await getRoleName ( req . body , bot )
rule . roleID = validationResult . roleID ;
if ( extra . error ) return res . status ( 400 ) . send ( ` Bad Request - ${ extra . error } ` )
rule . roleEmoji = validationResult . roleEmoji ;
var rule =
rule . roleName = validationResult . roleName ;
roleRulesM . updateOne ( { _id : rule . id } , rule , { upsert : true } ) . then ( updatedG =>
{
{
res . json ( { success : true , rule } )
gID : body . guildid ,
} )
mID : body . messageid ,
roleID : body . roleid ,
} )
roleEmoji : body . emojiid ,
roleName : extra . roleName ,
}
const newRule = await roleRulesM . create ( rule ) ; //Might need it later, not sure what for tho.
const roles = await getRules ( body . guildid ) ;
/ * *
* exports . rDash = ( bot ) =>
{
//! /rolerulesdash/:id -> Discord Guild Id (GuildId)
return async ( req , res ) =>
{
const roles = await getRules ( req . params . id ) ;
res . render ( 'roleRules.ejs' , { roles , id : req . params . id } ) ;
}
}
* /
res . render ( 'roleRules.ejs' , { roles , id : body . guildid } ) ;
}
}
}
}
async function confirmArgs ( args )
async function getRoleName ( args , bot )
{
{
var mID = args . messageid ;
var mID = args . messageid ;
var roleID = args . roleid ;
var roleID = args . roleid ;
var roleEmoji = args . emojiid ;
var roleEmoji = args . emojiid ;
var gID = args . gid ;
var gID = args . g uild id;
var roleName ;
var roleName ;
if ( ! mID ) return { error : 'Message ID' }
const guild = bot . guilds . cache . get ( gID ) ;
if ( ! roleID ) return { error : 'Role ID' }
if ( ! roleEmoji ) return { error : 'Emoji ID' }
if ( ! gID ) return { error : 'Guild ID' }
var m = await ( async ( ) =>
var m = await ( async ( ) =>
{
{
for ( const [ id , channel ] of bot . channels . cache )
for ( const [ id , channel ] of bot . channels . cache )
@ -270,33 +200,34 @@ exports.updateRule = (bot)=>
}
}
}
}
} ) ( ) ;
} ) ( ) ;
const r = bot . guilds . cache . get ( gID ) . roles . cache . get ( roleID ) ;
const r = guild . roles . cache . get ( roleID ) ;
const e = bot . guilds . cache . get ( gID ) . emojis . cache . get ( roleEmoji ) ;
const e = guild . emojis . cache . get ( roleEmoji ) ;
bot . guilds . cache . get ( gID ) . emojis . cache . forEach ( emoji =>
{
if ( emoji . name == 'tuturu' ) console . log ( emoji )
} )
console . log ( 'Emoji' , roleEmoji , e )
if ( ! m || ! r || ! e ) return m ? ( r ? ( e ? false : { error : 'Emoji ID' } ) : { error : 'Role ID' } ) : { error : 'Message ID' }
if ( ! m || ! r || ! e ) return m ? ( r ? ( e ? false : { error : 'Emoji ID' } ) : { error : 'Role ID' } ) : { error : 'Message ID' }
roleName = r . name ;
roleName = r . name ;
return { mID , roleID , roleEmoji , roleName , gID }
return { roleName }
}
}
}
exports . getFeeds = async ( req , res ) =>
{
var payload = await feedsM . find ( { gID : req . headers . guildid } ) . then ( res => { return res } ) . catch ( err => { return err } ) ;
res . json ( payload )
}
exports . getFeed = async ( req , res ) =>
{
var payload = await feedsM . find ( { _id : req . headers . feedid } ) . then ( res => { return res } ) . catch ( err => { return err } ) ;
res . json ( payload )
exports . fDash = ( bot ) =>
{
//! /feedsdash/:guildid'
return async ( req , res ) =>
{
const preFeeds = await feedsM . find ( { gID : req . params . guildid } ) . then ( feeds => { return feeds } ) ;
var feeds = [ ] ;
await Promise . all ( preFeeds . map ( async ( feed ) => {
feed [ 'channelName' ] = await getChannelName ( feed . YTChannelId ) ;
feeds . push ( feed ) ;
} ) ) ;
feeds . sort ( ( a , b ) => {
return a . channelName . localeCompare ( b . channelName ) ;
} ) ;
res . render ( 'feeds.ejs' , { feeds , id : req . params . guildid } ) ;
}
}
}
exports . getChannelName = async ( req , res ) =>
async function getChannelName ( channelID )
{
{
var payload = await fetch ( 'https://www.youtube.com/feeds/videos.xml?channel_id=' + req . headers . channelid ,
return await fetch ( 'https://www.youtube.com/feeds/videos.xml?channel_id=' + channelID ,
{
{
method : "GET" ,
method : "GET" ,
mode : "cors" ,
mode : "cors" ,
@ -319,169 +250,139 @@ exports.getChannelName = async (req,res)=>
{
{
return error ;
return error ;
} ) ;
} ) ;
res . json ( payload ) ;
}
exports . checkChannel = async ( req , res ) =>
{
var url = req . headers . id ;
var regExp = '^(?:(?:https?:)?\/\/)?(?:www\.|(m\.)?)(youtube\.com|youtu\.be)(\/[^\s]*)?$' ;
var rE = new RegExp ( regExp ) ;
if ( rE . test ( url ) ) {
url = req . headers . id ;
}
else
{
url = 'https://www.youtube.com/' + req . headers . id
}
}
var isValid = await fetch ( url ,
exports . feedChange = ( bot ) =>
{
method : "GET" ,
mode : "cors" ,
} )
. then ( response =>
{
{
if ( response . ok ) return response . text ( ) ;
//! /feedChange/:id/:guildid?
} )
return async ( req , res ) =>
. then ( data =>
{
return data ? true : false
} )
. catch ( error =>
{
{
return error ;
var feed = await feedsM . find ( { _id : req . params . id } ) . then ( feed => { return feed [ 0 ] } ) ;
} ) ;
feed . channelName = await getChannelName ( feed . YTChannelId ) ;
res . json ( isValid )
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . guildid ) ;
res . render ( 'feedPopup.ejs' , { feed , id : req . params . id , guild } ) ;
}
}
}
exports . addFeed = ( bot ) =>
exports . addFeed = ( bot ) =>
{
{
//! /feedChange/:guildid?
return async ( req , res ) =>
return async ( req , res ) =>
{
{
var headers = req . headers ;
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . guildid ) ;
var args = [ headers . gid , headers . dcchannelid , headers . ytchannelid ]
res . render ( 'feedPopup.ejs' , { feed : null , id : req . params . id , guild } ) ;
const validationResult = await confirmArgs ( args , bot ) ;
// console.log('Before new or old check', validationResult)
if ( validationResult . error ) return res . json ( { error : validationResult . error } ) ;
if ( ! headers . feedid )
{
//new
var feed = new feedsM ( ) ;
feed . gID = headers . gid ;
feed . ChannelId = validationResult . channelId
feed . YTChannelId = validationResult . YTChannelId ;
feed . CostumMessage = headers . costummessagei != '' ? headers . costummessagei : 'New video:' ;
feed . save ( err =>
{
if ( err ) res . json ( { error : err } ) ;
res . json ( { success : true , feed } )
} )
}
}
else
{
feedsM . findOne ( { id : args . id } ) . then ( feed =>
{
if ( ! feed ) return res . json ( { error : 'DB Error' } ) ;
feed . gID = headers . gid ;
feed . ChannelId = validationResult . channelId
feed . YTChannelId = validationResult . YTChannelId ;
feed . CostumMessage = headers . costummessagei != '' ? headers . costummessagei : 'New video:' ;
feedsM . updateOne ( { _id : feed . id } , feed , { upsert : true } ) . then ( updatedG =>
{
res . json ( { success : true , feed } )
} )
} )
}
}
}
}
exports . saveNewFeed = ( bot ) =>
async function confirmArgs ( args , bot )
{
var channelId = args [ 1 ] ;
var channelURL = args [ 2 ]
async function getChannelId ( url )
{
{
if ( url . split ( '@' ) . length < 1 ) return
//! /feedChange/:guildid?
return await fetch ( url )
return async ( req , res ) =>
. then ( handleResponse )
. then ( handleData )
. catch ( handleError ) ;
function handleResponse ( response )
{
if ( response . ok ) return response . text ( ) ;
}
function handleError ( error )
{
return { error : 'Bad youtube channel link.' } ;
}
function handleData ( data )
{
{
return data ? data . split ( 'https://www.youtube.com/feeds/videos.xml?channel_id=' ) [ 1 ] . split ( '"' ) [ 0 ] : false ;
const { DCchannelID , ytchannel , costummessage } = req . body
const { guildid } = req . params ;
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . guildid ) ;
var feed = {
ChannelId : '' ,
YTChannelId : '' ,
CostumMessage : '' ,
gID : guildid
} ;
if ( ! costummessage && ! ytchannel && ! DCchannelID ) return res . status ( 400 ) . send ( 'Bad Request' ) ;
const validated = await confirmArgsForYTFeed ( [ guildid , DCchannelID , ytchannel ] , bot ) ;
if ( validated . error ) return res . status ( 400 ) . send ( 'Bad Request' ) ;
feed . ChannelId = validated . channelId ;
feed . YTChannelId = validated . YTChannelId ;
feed . CostumMessage = costummessage ;
const newFeed = await feedsM . create ( feed ) . then ( f => { return f } ) . catch ( err => { console . log ( err ) } ) ;
newFeed . channelName = validated . channelName ;
res . render ( 'feedPopup.ejs' , { feed : newFeed , id : req . params . id , guild } ) ;
}
}
}
}
const YTChannelId = await getChannelId ( channelURL ) ;
exports . deleteFeed = ( bot ) =>
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 =>
{
return response . text ( )
} )
. then ( data =>
{
{
//! /feedChange/:id/:guildid?
data = xmlparser . xml2json ( data ,
return async ( req , res ) =>
{
{
compact : true ,
const deleted = await feedsM . findByIdAndDelete ( req . params . id ) . then ( deleted => { return deleted } ) . catch ( err => console . log ( err ) ) ;
space : 4
const preFeeds = await feedsM . find ( { gID : req . params . guildid } ) . then ( feeds => { return feeds } ) ;
var feeds = [ ] ;
await Promise . all ( preFeeds . map ( async ( feed ) => {
feed [ 'channelName' ] = await getChannelName ( feed . YTChannelId ) ;
feeds . push ( feed ) ;
} ) ) ;
feeds . sort ( ( a , b ) => {
return a . channelName . localeCompare ( b . channelName ) ;
} ) ;
} ) ;
data = JSON . parse ( data ) ;
res . render ( 'feeds.ejs' , { feeds , id : req . params . guildid } ) ;
return data . feed . author . name . _text
} )
. catch ( error => { return error ; } ) ;
return { YTChannelId , channelId , name , channelName : discordChannel . name }
}
}
exports . deleteFeed = ( req , res ) =>
}
exports . updateFeed = ( bot ) =>
{
{
feedsM . findOneAndDelete ( { _id : req . headers . feedid } ) . then ( ( ) => { res . json ( { success : true } ) } ) . catch ( error => { res . json ( { error } ) } )
//! /feedChange/:id/:guildid?
return async ( req , res ) =>
{
const { DCchannelID , ytchannel , costummessage } = req . body
const { guildid } = req . params ;
const guild = await new DiscordAPI ( req . headers . cookie , bot ) . getSpecificGuildDataForDash ( req . params . guildid ) ;
var feed = {
ChannelId : '' ,
YTChannelId : '' ,
CostumMessage : '' ,
gID : guildid
} ;
if ( ! costummessage && ! ytchannel && ! DCchannelID ) return res . status ( 400 ) . send ( 'Bad Request' ) ;
const validated = await confirmArgsForYTFeed ( [ guildid , DCchannelID , ytchannel ] , bot ) ;
if ( validated . error ) return res . status ( 400 ) . send ( 'Bad Request' ) ;
feed . ChannelId = validated . channelId ;
feed . YTChannelId = validated . YTChannelId ;
feed . CostumMessage = costummessage ;
const newFeed = await feedsM . findOneAndUpdate ( { _id : req . params . id } , feed ) . then ( f => { return f } ) . catch ( err => { console . log ( err ) } ) ;
res . render ( 'feedPopup.ejs' , { feed : newFeed , id : req . params . id , guild } ) ;
}
}
}
/ * *
*
* ! '/strikes/:id/:userid/:strikeid?'
* /
exports . strikeDashboard = ( bot ) =>
exports . strikeDashboard = ( bot ) =>
{
{
return async ( req , res ) =>
return async ( req , res ) =>
{
{
// const user = bot.users.cache.get(req.params.userid)
// const user = bot.users.cache.get(req.params.userid)
const guild = bot . guilds . cache . get ( req . params . id ) ;
const guild = bot . guilds . cache . get ( req . params . id ) ;
const strikes = await STRIKES . find ( { guildID : req . params . id } )
const strike Li st = await STRIKES . find ( { guildID : req . params . id } )
const moderator = req . params . userid ;
const moderator = req . params . userid ;
res . render ( 'strikesDashboard.ejs' , { strikes , guild , moderator } )
var strikes = [ ] ;
await Promise . all ( strikeList . map ( async ( strike ) => {
var aux = { ... strike . _doc }
if ( strike . validated )
{
if ( strike . validatedBy )
{
const user = bot . users . cache . get ( strike . validatedBy ) ;
const moderator = {
username : user . username ,
avatar : user . avatar ,
id : user . id
} ;
aux = { ... aux , moderator } ;
}
}
}
}
exports . getStrikes = ( bot ) =>
strikes . push ( aux ) ;
{
} ) ) ;
return async ( req , res ) =>
// console.log(strikes)
{
res . render ( 'strikesDashboard.ejs' , { strikes , guild , moderator } )
var strikes = await STRIKES . find ( { guildID : req . params . id } ) ;
const moderator = req . params . userid
res . render ( 'strikelist.ejs' , { strikes } )
}
}
}
}
exports . updateStrikes = ( bot ) =>
exports . updateStrikes = ( bot ) =>
{
{
return async ( req , res ) =>
return async ( req , res ) =>
{
{
const strike = await STRIKES . findByIdAndUpdate ( req . params . strikeid , { validated : true } ) ;
const strikes = await STRIKES . find ( { guildID : req . params . id } )
const moderator = req . params . userid ;
const moderator = req . params . userid ;
const strike = await STRIKES . findByIdAndUpdate ( req . params . strikeid , { validated : true , validatedBy : moderator } ) ;
const strikes = await STRIKES . find ( { guildID : req . params . id } )
res . render ( 'strikelist.ejs' , { strikes , moderator } )
res . render ( 'strikelist.ejs' , { strikes , moderator } )
}
}
}
}