fix permissions and support for users categories
This commit is contained in:
parent
849a93887a
commit
d0abeb56b4
5 changed files with 38 additions and 54 deletions
|
@ -1,4 +1,4 @@
|
||||||
const { Permissions } = require("discord.js");
|
const { PermissionsBitField, ChannelType } = require("discord.js");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
select: (list, disabled, themeOptions = {}) => {
|
select: (list, disabled, themeOptions = {}) => {
|
||||||
|
@ -80,7 +80,7 @@ module.exports = {
|
||||||
themeOptions,
|
themeOptions,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
channelsSelect: (disabled, channelTypes = ["GUILD_TEXT"], hideNSFW, onlyNSFW, hideNoAccess, themeOptions = {}) => {
|
channelsSelect: (disabled, channelTypes = [ChannelType.GuildText], hideNSFW, onlyNSFW, hideNoAccess, themeOptions = {}) => {
|
||||||
return {
|
return {
|
||||||
type: "channelsSelect",
|
type: "channelsSelect",
|
||||||
function: (client, guildid, userid) => {
|
function: (client, guildid, userid) => {
|
||||||
|
@ -98,8 +98,8 @@ module.exports = {
|
||||||
if (hideNSFW && channel.nsfw) return;
|
if (hideNSFW && channel.nsfw) return;
|
||||||
if (onlyNSFW && !channel.nsfw) return;
|
if (onlyNSFW && !channel.nsfw) return;
|
||||||
if (hideNoAccess) {
|
if (hideNoAccess) {
|
||||||
if (!user.permissionsIn(channel).has(Permissions.FLAGS.SEND_MESSAGES) || !user.permissionsIn(channel).has(Permissions.FLAGS.VIEW_CHANNEL)) return;
|
if (!user.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages) || !user.permissionsIn(channel).has(PermissionsBitField.Flags.ViewChannel)) return;
|
||||||
if (!bot.permissionsIn(channel).has(Permissions.FLAGS.SEND_MESSAGES) || !bot.permissionsIn(channel).has(Permissions.FLAGS.SEND_MESSAGES)) return;
|
if (!bot.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages) || !bot.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
listCount[channel.name] ? (listCount[channel.name] = listCount[channel.name] + 1) : (listCount[channel.name] = 1);
|
listCount[channel.name] ? (listCount[channel.name] = listCount[channel.name] + 1) : (listCount[channel.name] = 1);
|
||||||
|
@ -145,8 +145,8 @@ module.exports = {
|
||||||
if (hideNSFW && channel.nsfw) return;
|
if (hideNSFW && channel.nsfw) return;
|
||||||
if (onlyNSFW && !channel.nsfw) return;
|
if (onlyNSFW && !channel.nsfw) return;
|
||||||
if (hideNoAccess) {
|
if (hideNoAccess) {
|
||||||
if (!user.permissionsIn(channel).has(Permissions.FLAGS.SEND_MESSAGES) || !user.permissionsIn(channel).has(Permissions.FLAGS.VIEW_CHANNEL)) return;
|
if (!user.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages) || !user.permissionsIn(channel).has(PermissionsBitField.Flags.ViewChannel)) return;
|
||||||
if (!bot.permissionsIn(channel).has(Permissions.FLAGS.SEND_MESSAGES) || !bot.permissionsIn(channel).has(Permissions.FLAGS.SEND_MESSAGES)) return;
|
if (!bot.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages) || !bot.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return;
|
||||||
}
|
}
|
||||||
listCount[channel.name] ? (listCount[channel.name] = listCount[channel.name] + 1) : (listCount[channel.name] = 1);
|
listCount[channel.name] ? (listCount[channel.name] = listCount[channel.name] + 1) : (listCount[channel.name] = 1);
|
||||||
|
|
||||||
|
|
|
@ -62,13 +62,12 @@ module.exports = (app, config, themeConfig) => {
|
||||||
|
|
||||||
let customThemeOptions;
|
let customThemeOptions;
|
||||||
if (themeConfig?.customThemeOptions?.getGuild) {
|
if (themeConfig?.customThemeOptions?.getGuild) {
|
||||||
customThemeOptions =
|
customThemeOptions = await themeConfig.customThemeOptions.getGuild({
|
||||||
await themeConfig.customThemeOptions.getGuild({
|
req: req,
|
||||||
req: req,
|
res: res,
|
||||||
res: res,
|
config: config,
|
||||||
config: config,
|
guildId: req.params.id,
|
||||||
guildId: req.params.id,
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bot = config.bot;
|
const bot = config.bot;
|
||||||
|
@ -85,11 +84,7 @@ module.exports = (app, config, themeConfig) => {
|
||||||
} catch (e) { /* ... */ }
|
} catch (e) { /* ... */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (const PermissionRequired of req.requiredPermissions) {
|
if (!bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id).permissions.has(config.requiredPermissions)) return res.redirect("/manage?error=noPermsToManageGuild");
|
||||||
// const permissionsReq = PermissionRequired[0];
|
|
||||||
|
|
||||||
// if (!bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id).permissions.has(permissionsReq)) return res.redirect("/manage?error=noPermsToManageGuild");
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (bot.guilds.cache.get(req.params.id).channels.cache.size < 1) {
|
if (bot.guilds.cache.get(req.params.id).channels.cache.size < 1) {
|
||||||
try {
|
try {
|
||||||
|
@ -109,6 +104,7 @@ module.exports = (app, config, themeConfig) => {
|
||||||
if (!config.useCategorySet)
|
if (!config.useCategorySet)
|
||||||
for (const s of config.settings) {
|
for (const s of config.settings) {
|
||||||
if (!canUseList[s.categoryId]) canUseList[s.categoryId] = {};
|
if (!canUseList[s.categoryId]) canUseList[s.categoryId] = {};
|
||||||
|
|
||||||
for (const c of s.categoryOptionsList) {
|
for (const c of s.categoryOptionsList) {
|
||||||
if (c.allowedCheck) {
|
if (c.allowedCheck) {
|
||||||
const canUse = await c.allowedCheck({
|
const canUse = await c.allowedCheck({
|
||||||
|
@ -126,21 +122,20 @@ module.exports = (app, config, themeConfig) => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.optionType == "spacer") { /* ... */ } else {
|
if (c.optionType.type == "spacer") { /* ... */ } else {
|
||||||
if (!actual[s.categoryId]) actual[s.categoryId] = {};
|
if (!actual[s.categoryId]) actual[s.categoryId] = {};
|
||||||
|
|
||||||
if (!actual[s.categoryId][c.optionId]) {
|
if (!actual[s.categoryId][c.optionId]) {
|
||||||
actual[s.categoryId][c.optionId] =
|
actual[s.categoryId][c.optionId] = await c.getActualSet({
|
||||||
await c.getActualSet({
|
guild: {
|
||||||
guild: {
|
id: req.params.id,
|
||||||
id: req.params.id,
|
object: bot.guilds.cache.get(req.params.id),
|
||||||
object: bot.guilds.cache.get(req.params.id),
|
},
|
||||||
},
|
user: {
|
||||||
user: {
|
id: req.session.user.id,
|
||||||
id: req.session.user.id,
|
object: bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id),
|
||||||
object: bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id),
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,22 +240,18 @@ module.exports = (app, config, themeConfig) => {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const bot = config.bot;
|
const bot = config.bot;
|
||||||
|
const member = bot.guilds.cache.get(req.params.guildId).members.cache.get(req.session.user.id);
|
||||||
|
|
||||||
if (!bot.guilds.cache.get(req.params.guildId)) return res.redirect("/manage?error=noPermsToManageGuild");
|
if (!bot.guilds.cache.get(req.params.guildId)) return res.redirect("/manage?error=noPermsToManageGuild");
|
||||||
|
|
||||||
await bot.guilds.cache.get(req.params.guildId).members.fetch(req.session.user.id);
|
await bot.guilds.cache.get(req.params.guildId).members.fetch(req.session.user.id);
|
||||||
|
|
||||||
// for (const PermissionRequired of req.requiredPermissions) {
|
if (!member.permissions.has(config.requiredPermissions)) return res.redirect("/manage?error=noPermsToManageGuild");
|
||||||
// const permissionsReq = PermissionRequired[0];
|
|
||||||
|
|
||||||
// if (!bot.guilds.cache.get(req.params.guildId).members.cache.get(req.session.user.id).permissions.has(permissionsReq))
|
|
||||||
// return res.redirect("/manage?error=noPermsToManageGuild");
|
|
||||||
// }
|
|
||||||
|
|
||||||
const cid = req.params.categoryId;
|
const cid = req.params.categoryId;
|
||||||
const settings = config.settings;
|
const settings = config.settings;
|
||||||
|
|
||||||
const category = settings.find((c) => c.categoryId == cid);
|
const category = settings.find(c => c.categoryId == cid);
|
||||||
|
|
||||||
if (!category)
|
if (!category)
|
||||||
return res.send({
|
return res.send({
|
||||||
|
@ -296,9 +287,7 @@ module.exports = (app, config, themeConfig) => {
|
||||||
error: canUse.errorMessage,
|
error: canUse.errorMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
errors.push(
|
errors.push(option.optionName + "%is%" + setNewRes.error + "%is%" + option.optionId);
|
||||||
option.optionName + "%is%" + setNewRes.error + "%is%" + option.optionId,
|
|
||||||
);
|
|
||||||
} else if (option.optionType != "spacer") {
|
} else if (option.optionType != "spacer") {
|
||||||
if (config.useCategorySet) {
|
if (config.useCategorySet) {
|
||||||
if (option.optionType.type == "rolesMultiSelect" || option.optionType.type == "channelsMultiSelect" || option.optionType.type == "multiSelect") {
|
if (option.optionType.type == "rolesMultiSelect" || option.optionType.type == "channelsMultiSelect" || option.optionType.type == "multiSelect") {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
const { Permissions } = require("discord.js");
|
|
||||||
|
|
||||||
module.exports = function (config, themeConfig) {
|
module.exports = function (config, themeConfig) {
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
config.guildSettings = async function (req, res, home, category) {
|
config.guildSettings = async function (req, res, home, category) {
|
||||||
|
@ -19,12 +17,7 @@ module.exports = function (config, themeConfig) {
|
||||||
} catch (e) { /* ... */ }
|
} catch (e) { /* ... */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (const PermissionRequired of req.requiredPermissions) {
|
if (!bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id).permissions.has(config.requiredPermissions)) return res.redirect("/manage?error=noPermsToManageGuild");
|
||||||
// const permissionsReq = Permissions.FLAGS[PermissionRequired[0]];
|
|
||||||
|
|
||||||
// if (!bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id).permissions.has(permissionsReq))
|
|
||||||
// return res.redirect("/manage?error=noPermsToManageGuild");
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (bot.guilds.cache.get(req.params.id).channels.cache.size < 1) {
|
if (bot.guilds.cache.get(req.params.id).channels.cache.size < 1) {
|
||||||
try {
|
try {
|
||||||
|
@ -44,7 +37,9 @@ module.exports = function (config, themeConfig) {
|
||||||
|
|
||||||
const canUseList = {};
|
const canUseList = {};
|
||||||
|
|
||||||
if (config.settings?.length)
|
if (config.settings?.length) {
|
||||||
|
config.settings = config.settings.filter(c => c.categoryPermissions ? bot.guilds.cache.get(req.params.id).members.cache.get(req.session.user.id).permissions.has(c.categoryPermissions) : true);
|
||||||
|
|
||||||
for (const category of config.settings) {
|
for (const category of config.settings) {
|
||||||
if (!canUseList[category.categoryId]) canUseList[category.categoryId] = {};
|
if (!canUseList[category.categoryId]) canUseList[category.categoryId] = {};
|
||||||
if (!actual[category.categoryId]) actual[category.categoryId] = {};
|
if (!actual[category.categoryId]) actual[category.categoryId] = {};
|
||||||
|
@ -216,6 +211,7 @@ module.exports = function (config, themeConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let errors;
|
let errors;
|
||||||
let success;
|
let success;
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
{name: "Theme", value: "Soft UI Theme"},
|
{name: "Theme", value: "Soft UI Theme"},
|
||||||
{name: "Modified", value: `${modded}`},
|
{name: "Modified", value: `${modded}`},
|
||||||
{name: "Uptime", value: `${filterUptime}`},
|
{name: "Uptime", value: `${filterUptime}`},
|
||||||
// {name: "Permissions", value: req.requiredPermissions},
|
{name: "Permissions", value: config.requiredPermissions},
|
||||||
{name: "Redirect URI", value: `${config.redirectUri?.includes("/discord/callback")}`}
|
{name: "Redirect URI", value: `${config.redirectUri?.includes("/discord/callback")}`}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body px-0 pt-0 pb-2">
|
<div class="card-body px-0 pt-0 pb-2">
|
||||||
<div style="margin-bottom: 35px; margin-top: 0px; text-align: center;">
|
<div style="margin-bottom: 35px; margin-top: 0px; text-align: center;">
|
||||||
<%
|
<% for(var i in req.session.guilds) { %>
|
||||||
for(var i in req.session.guilds){ %>
|
<% if((req.session.guilds[i].permissions & 0x0400) == 0x0400){ %>
|
||||||
<% if((req.session.guilds[i].permissions & 0x00000020) == 0x00000020){ %>
|
|
||||||
<% if(bot.guilds.cache.get(req.session.guilds[i].id)){
|
<% if(bot.guilds.cache.get(req.session.guilds[i].id)){
|
||||||
const guild = bot.guilds.cache.get(req.session.guilds[i].id);
|
const guild = bot.guilds.cache.get(req.session.guilds[i].id);
|
||||||
let icon;
|
let icon;
|
||||||
|
@ -47,7 +46,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="_4204" style="margin-bottom: 35px; text-align: center;">
|
<div class="_4204" style="margin-bottom: 35px; text-align: center;">
|
||||||
<% for (var i in req.session.guilds){ %>
|
<% for (var i in req.session.guilds){ %>
|
||||||
<% if((req.session.guilds[i].permissions & 0x00000020) == 0x00000020){ %>
|
<% if((req.session.guilds[i].permissions & 0x20) == 0x20){ %>
|
||||||
<%
|
<%
|
||||||
if(!bot.guilds.cache.get(req.session.guilds[i].id)){
|
if(!bot.guilds.cache.get(req.session.guilds[i].id)){
|
||||||
let icon = `https://cdn.discordapp.com/icons/${req.session.guilds[i].id}/${req.session.guilds[i].icon}.png`;
|
let icon = `https://cdn.discordapp.com/icons/${req.session.guilds[i].id}/${req.session.guilds[i].icon}.png`;
|
||||||
|
|
Loading…
Reference in a new issue