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

@ -17,7 +17,7 @@ module.exports = {
if (currentServer == null) return; if (currentServer == null) return;
['caps', 'swearfilter'].forEach(addon => { ['caps', 'swearfilter'].forEach(addon => {
require(`../addons/${addon}`)(message, server, messageUser, client); require(`../addons/${addon}`)(message, currentServer, messageUser, client);
}) })
//eval command //eval command

View file

@ -15,21 +15,25 @@ module.exports = {
let currentUser = await Userdashboard.findOne({ userId: res.locals.cookie.id }) let currentUser = await Userdashboard.findOne({ userId: res.locals.cookie.id })
let currentServer = await Server.findOne({ id: req.params.serverid }) let currentServer = await Server.findOne({ id: req.params.serverid })
if (currentServer == null) return res.render('404.ejs') if (currentServer == null) return res.render('404.ejs')
let guild = await currentUser.guilds[currentServer.id]; let gAccess = false;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) { await currentUser.guilds.forEach(guild => {
let hasAccess = false; if (guild.id == currentServer.id) {
await currentUser.accessCodes.forEach(async(userCode) => { gAccess = true;
if (res.locals.cookie.accesscode == userCode.code) { if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
let hasAccess = false;
await currentUser.accessCodes.forEach(async(userCode) => {
if (res.locals.cookie.accesscode == userCode.code) {
hasAccess = true; 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/filter.ejs', { domain: conf.domain, user: { id: currentUser.userId, accesscode: res.locals.cookie.accesscode }, currentUser: currentUser, currentServer: currentServer }); 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/filter.ejs', { domain: conf.domain, 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'); 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" })
} 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 } })
} }
} catch (error) { } catch (error) {
console.log(error) console.log(error)

View file

@ -16,28 +16,34 @@ module.exports = {
if (currentUser == null) return res.render('404.ejs') if (currentUser == null) return res.render('404.ejs')
let currentServer = await Server.findOne({ id: req.params.serverid }) let currentServer = await Server.findOne({ id: req.params.serverid })
if (currentServer == null) return res.render('404.ejs') if (currentServer == null) return res.render('404.ejs')
let guild = await currentUser.guilds[currentServer.id]; let gAccess = false;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) { await currentUser.guilds.forEach(guild => {
let hasAccess = false; if (guild.id == currentServer.id) {
let listedRoles = []; gAccess = true;
let listedChannels = []; if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
let server = await client.guilds.cache.get(currentServer.id); let hasAccess = false;
let user = await server.members.fetch(currentUser.userId); let listedRoles = [];
//push server roles to array let listedChannels = [];
server.roles.cache.map((role) => listedRoles.push({ id: role.id, name: role.name })); let server = await client.guilds.cache.get(currentServer.id);
//push only channels user can see to array let user = await server.members.fetch(currentUser.userId);
server.channels.cache.filter(c => c.type == 'text').forEach(channel => { //push server roles to array
if (server.channels.cache.get(channel.id).permissionsFor(user).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])) listedChannels.push({ name: channel.name, id: channel.id }); server.roles.cache.map((role) => listedRoles.push({ id: role.id, name: role.name }));
}); //push only channels user can see to array
await currentUser.accessCodes.forEach(async(userCode) => { server.channels.cache.filter(c => c.type == 'text').forEach(channel => {
if (res.locals.cookie.accesscode == userCode.code) { if (server.channels.cache.get(channel.id).permissionsFor(user).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])) listedChannels.push({ name: channel.name, id: channel.id });
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 }); 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 { if (gAccess == false) {
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 } }) 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) { } catch (error) {
console.log(error) console.log(error)

View file

@ -16,21 +16,28 @@ module.exports = {
if (currentUser == null) return res.redirect('/login'); if (currentUser == null) return res.redirect('/login');
let currentServer = await Server.findOne({ id: req.params.serverid }) let currentServer = await Server.findOne({ id: req.params.serverid })
if (currentServer == null) return res.render('404.ejs'); if (currentServer == null) return res.render('404.ejs');
let guild = await currentUser.guilds[currentServer.id]; let gAccess = false;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) { await currentUser.guilds.forEach(guild => {
let hasAccess = false; if (guild.id == currentServer.id) {
await currentUser.accessCodes.forEach(async(userCode) => { gAccess = true;
if (res.locals.cookie.accesscode == userCode.code) { if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
hasAccess = true; let hasAccess = false;
const memberCount = await client.guilds.cache.get(currentServer.id).memberCount; await currentUser.accessCodes.forEach(async(userCode) => {
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/server.ejs', { domain: conf.domain, user: { id: currentUser.userId, accesscode: res.locals.cookie.accesscode }, currentUser: currentUser, currentServer: currentServer, memberCount: memberCount }); if (res.locals.cookie.accesscode == userCode.code) {
}; hasAccess = true;
}); const memberCount = await client.guilds.cache.get(currentServer.id).memberCount;
if (hasAccess == false) return res.redirect('/login?ninvalidcode'); 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/server.ejs', { domain: conf.domain, user: { id: currentUser.userId, accesscode: res.locals.cookie.accesscode }, currentUser: currentUser, currentServer: currentServer, memberCount: memberCount });
} 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 (hasAccess == false) return res.redirect('/login?ninvalidcode');
}
};
});
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) { } catch (error) {
console.log(error) console.log(error)
res.status(500).render('error.ejs', { errorMessage: error, error: "there has been an issue with your request please try again, if this continuous report it at http://knightrider.rf.gd/er/admin.php" }) res.status(500).render('error.ejs', { errorMessage: error, error: "there has been an issue with your request please try again, if this continuous report it at http://knightrider.rf.gd/er/admin.php" })

View file

@ -13,25 +13,29 @@ module.exports = {
if (currentUser == null) return res.status(404).json({ error: "404 - cant find you in the db" }); if (currentUser == null) return res.status(404).json({ error: "404 - cant find you in the db" });
let currentServer = await Server.findOne({ id: req.body.server.id }); let currentServer = await Server.findOne({ id: req.body.server.id });
if (currentServer == null) return res.status(404).json({ error: "404 - cant find that server in the db" }); if (currentServer == null) return res.status(404).json({ error: "404 - cant find that server in the db" });
let guild = await currentUser.guilds[currentServer.id]; let gAccess = false;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) { await currentUser.guilds.forEach(guild => {
if (guild.id == currentServer.id) {
let hasAccess = false; gAccess = true;
await currentUser.accessCodes.forEach(async(userCode) => { if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
if (req.body.user.accesscode == userCode.code) {
hasAccess = true;
currentServer.filter.normal = await req.body.normalFilter;
currentServer.filter.safe = await req.body.safeFilter;
currentServer.save();
return res.status(200).json({ error: "no", message: "filters have been updates" });
};
});
} else {
return res.status(401).json({ error: "401 - unauthorised", info: "your user does not own the server or have a staff role or pi is listed as a staff member" });
};
let hasAccess = false;
await currentUser.accessCodes.forEach(async(userCode) => {
if (req.body.user.accesscode == userCode.code) {
hasAccess = true;
currentServer.filter.normal = await req.body.normalFilter;
currentServer.filter.safe = await req.body.safeFilter;
currentServer.save();
return res.status(200).json({ error: "no", message: "filters have been updates" });
};
});
}
}
});
if (hasAccess == false) return res.status(401).json({ error: "401 - unauthorised", info: "please include your accesscode and user id to use this api more info in the docs " + conf.domain + '/docs' }); if (hasAccess == false) return res.status(401).json({ error: "401 - unauthorised", info: "please include your accesscode and user id to use this api more info in the docs " + conf.domain + '/docs' });
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) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: "some error happened", info: "report this if it happenes again." + domain + '/er' }); res.status(500).json({ error: "some error happened", info: "report this if it happenes again." + domain + '/er' });

View file

@ -13,31 +13,35 @@ module.exports = {
if (currentUser == null) return res.status(404).json({ error: "404 - cant find you in the db", message: "that user id cant be found" }); if (currentUser == null) return res.status(404).json({ error: "404 - cant find you in the db", message: "that user id cant be found" });
let currentServer = await Server.findOne({ id: req.body.server.id }); let currentServer = await Server.findOne({ id: req.body.server.id });
if (currentServer == null) return res.status(404).json({ error: "404 - cant find that server in the db", message: "that server id cant be found" }); if (currentServer == null) return res.status(404).json({ error: "404 - cant find that server in the db", message: "that server id cant be found" });
let guild = await currentUser.guilds[currentServer.id]; let gAccess = false;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) { 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 hasAccess = false;
await currentUser.accessCodes.forEach(async(userCode) => { await currentUser.accessCodes.forEach(async(userCode) => {
if (req.body.user.accesscode == userCode.code) { if (req.body.user.accesscode == userCode.code) {
hasAccess = true; hasAccess = true;
//apply all data from the req to the db (probabbly a better way to do this) //apply all data from the req to the db (probabbly a better way to do this)
currentServer.prefix = req.body.prefix || prefix; currentServer.prefix = req.body.prefix || prefix;
currentServer.staff = req.body.staffids || []; currentServer.staff = req.body.staffids || [];
currentServer.staffRoles = req.body.staffRoles || []; currentServer.staffRoles = req.body.staffRoles || [];
currentServer.channels.modLogs = req.body.channels.modlogs || ' '; currentServer.channels.modLogs = req.body.channels.modlogs || ' ';
currentServer.channels.announcments = req.body.channels.announcments || ' '; currentServer.channels.announcments = req.body.channels.announcments || ' ';
currentServer.channels.townhall = req.body.channels.townhall || ' '; currentServer.channels.townhall = req.body.channels.townhall || ' ';
currentServer.channels.townhallLogs = req.body.channels.townhallLogs || ' '; currentServer.channels.townhallLogs = req.body.channels.townhallLogs || ' ';
currentServer.save(); currentServer.save();
return res.status(200); return res.status(200);
}; };
}); });
} else { }
return res.status(401).json({ error: "401 - unauthorised", info: "your user does not own the server or have a staff role or pi is listed as a staff member" }); }
}; });
if (hasAccess == false) return res.status(401).json({ error: "401 - unauthorised", info: "please include your accesscode and user id to use this api more info in the docs " + conf.domain + '/docs' });
if (gAccess == false) {
if (hasAccess == false) return res.status(401).JSON({ error: "401 - unauthorised", info: "please include your accesscode and user id to use this api more info in the docs " + conf.domain + '/docs' }); 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) { } catch (error) {
console.log(error); console.log(error);
res.status(500).JSON({ error: "some error happened", info: "report this if it happenes again. " + domain + '/er' }); res.status(500).JSON({ error: "some error happened", info: "report this if it happenes again. " + domain + '/er' });

View file

@ -12,68 +12,73 @@ module.exports = {
if (currentUser == null) return res.status(404).json({ error: "404 - cant find you in the db" }); if (currentUser == null) return res.status(404).json({ error: "404 - cant find you in the db" });
let currentServer = await Server.findOne({ id: req.body.server.id }); let currentServer = await Server.findOne({ id: req.body.server.id });
if (currentServer == null) return res.status(404).json({ error: "404 - cant find that server in the db" }); if (currentServer == null) return res.status(404).json({ error: "404 - cant find that server in the db" });
let guild = await currentUser.guilds[currentServer.id]; let gAccess = false;
if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) { await currentUser.guilds.forEach(guild => {
let hasAccess = false; if (guild.id == currentServer.id) {
await currentUser.accessCodes.forEach(async(userCode) => { gAccess = true;
if (req.body.user.accesscode == userCode.code) { if (guild.userPermission == 'owner' || guild.userPermission == 'MANAGE_GUILD' || currentServer.staff.includes(currentUser.userId)) {
hasAccess = true; let hasAccess = false;
currentServer.reactionRoles = await req.body.reactionRoles; await currentUser.accessCodes.forEach(async(userCode) => {
currentServer.save(); if (req.body.user.accesscode == userCode.code) {
let eachChannelRoles = {}; hasAccess = true;
await currentServer.reactionRoles.forEach(role => { currentServer.reactionRoles = await req.body.reactionRoles;
if (!eachChannelRoles[role.channelID]) { currentServer.save();
eachChannelRoles[role.channelID] = [{ let eachChannelRoles = {};
roleID: role.roleID, await currentServer.reactionRoles.forEach(role => {
emoji: role.emoji if (!eachChannelRoles[role.channelID]) {
}]; eachChannelRoles[role.channelID] = [{
} else { roleID: role.roleID,
eachChannelRoles[role.channelID].push({ emoji: role.emoji
roleID: role.roleID, }];
emoji: role.emoji } else {
eachChannelRoles[role.channelID].push({
roleID: role.roleID,
emoji: role.emoji
});
};
}); });
for (let i in eachChannelRoles) {
let rolesEmbed = {
color: conf.colour.ok,
title: 'ReactionRoles',
url: conf.domain,
author: {
name: conf.bot.name,
icon_url: conf.bot.logo,
url: conf.bot.url,
},
description: 'react with the appropriate emoji to get your role',
fields: [],
timestamp: new Date(),
footer: {
text: currentServer.name,
},
};
await eachChannelRoles[i].forEach(role => {
rolesEmbed.fields.push({
name: '\u200B',
value: '<@&' + role.roleID + '> - ' + role.emoji,
});
});
const channel = client.guilds.cache.get(currentServer.id).channels.cache.get(i)
if (channel !== undefined) {
const msg = await channel.send({ embed: rolesEmbed });
eachChannelRoles[i].forEach(role => {
msg.react(role.emoji);
});
};
};
return res.status(200).json({ error: "no", message: "reactionroles have been updates" });
}; };
}); });
for (let i in eachChannelRoles) { }
let rolesEmbed = { }
color: conf.colour.ok, });
title: 'ReactionRoles',
url: conf.domain,
author: {
name: conf.bot.name,
icon_url: conf.bot.logo,
url: conf.bot.url,
},
description: 'react with the appropriate emoji to get your role',
fields: [],
timestamp: new Date(),
footer: {
text: currentServer.name,
},
};
await eachChannelRoles[i].forEach(role => {
rolesEmbed.fields.push({
name: '\u200B',
value: '<@&' + role.roleID + '> - ' + role.emoji,
});
});
const channel = client.guilds.cache.get(currentServer.id).channels.cache.get(i)
if (channel !== undefined) {
const msg = await channel.send({ embed: rolesEmbed });
eachChannelRoles[i].forEach(role => {
msg.react(role.emoji);
});
};
};
return res.status(200).json({ error: "no", message: "reactionroles have been updates" });
};
});
} else {
return res.status(401).json({ error: "401 - unauthorised", info: "your user does not own the server or have a staff role or pi is listed as a staff member" });
}
if (hasAccess == false) return res.status(401).json({ error: "401 - unauthorised", info: "please include your accesscode and user id to use this api more info in the docs " + conf.domain + '/docs' }); if (hasAccess == false) return res.status(401).json({ error: "401 - unauthorised", info: "please include your accesscode and user id to use this api more info in the docs " + conf.domain + '/docs' });
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) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: "some error happened", info: "report this if it happenes again." + conf.domain + '/er' }); res.status(500).json({ error: "some error happened", info: "report this if it happenes again." + conf.domain + '/er' });