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