i broke it real bad so i fixed it

This commit is contained in:
404invalid-user 2021-08-28 23:27:38 +01:00
parent 425c617f23
commit fcb10e8b9a
7 changed files with 177 additions and 147 deletions

View file

@ -16,28 +16,34 @@ module.exports = {
if (currentUser == null) return res.render('404.ejs')
let currentServer = await Server.findOne({ id: req.params.serverid })
if (currentServer == null) return res.render('404.ejs')
let guild = await currentUser.guilds[currentServer.id];
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
let hasAccess = false;
let listedRoles = [];
let listedChannels = [];
let server = await client.guilds.cache.get(currentServer.id);
let user = await server.members.fetch(currentUser.userId);
//push server roles to array
server.roles.cache.map((role) => listedRoles.push({ id: role.id, name: role.name }));
//push only channels user can see to array
server.channels.cache.filter(c => c.type == 'text').forEach(channel => {
if (server.channels.cache.get(channel.id).permissionsFor(user).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])) listedChannels.push({ name: channel.name, id: channel.id });
});
await currentUser.accessCodes.forEach(async(userCode) => {
if (res.locals.cookie.accesscode == userCode.code) {
hasAccess = true;
return res.cookie('id', currentUser.userId, { expires: new Date(253402300000000), httpOnly: true }).cookie('accesscode', res.locals.cookie.accesscode, { expires: new Date(253402300000000), httpOnly: true }).render('dashboard/reactionroles.ejs', { domain: conf.domain, server: { channels: listedChannels, roles: listedRoles }, user: { id: currentUser.userId, accesscode: res.locals.cookie.accesscode }, currentUser: currentUser, currentServer: currentServer });
let gAccess = false;
await currentUser.guilds.forEach(guild => {
if (guild.id == currentServer.id) {
gAccess = true;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
let hasAccess = false;
let listedRoles = [];
let listedChannels = [];
let server = await client.guilds.cache.get(currentServer.id);
let user = await server.members.fetch(currentUser.userId);
//push server roles to array
server.roles.cache.map((role) => listedRoles.push({ id: role.id, name: role.name }));
//push only channels user can see to array
server.channels.cache.filter(c => c.type == 'text').forEach(channel => {
if (server.channels.cache.get(channel.id).permissionsFor(user).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])) listedChannels.push({ name: channel.name, id: channel.id });
});
await currentUser.accessCodes.forEach(async(userCode) => {
if (res.locals.cookie.accesscode == userCode.code) {
hasAccess = true;
return res.cookie('id', currentUser.userId, { expires: new Date(253402300000000), httpOnly: true }).cookie('accesscode', res.locals.cookie.accesscode, { expires: new Date(253402300000000), httpOnly: true }).render('dashboard/reactionroles.ejs', { domain: conf.domain, server: { channels: listedChannels, roles: listedRoles }, user: { id: currentUser.userId, accesscode: res.locals.cookie.accesscode }, currentUser: currentUser, currentServer: currentServer });
};
});
if (hasAccess == false) return res.redirect('/login?ninvalidcode');
};
});
if (hasAccess == false) return res.redirect('/login?ninvalidcode');
} else {
await res.status(401).render('error.ejs', { errorMessage: null, error: "you do not have access to the admin dashboard if you are a member of staff tell the bot owner", userInfo: { id: req.query.userid, username: req.query.userame, avatar: req.query.userAvatar } })
};
});
if (gAccess == false) {
return res.status(401).render('error.ejs', { errorMessage: null, error: "you do not have access to the admin dashboard if you are a member of staff tell the bot owner" })
}
} catch (error) {
console.log(error)