clean my code + fix permissions error?
This commit is contained in:
1 parent
b396cd742b
commit
a24a616459
8 files changed
+18
-25
No files matched your search
@@ -30,7 +30,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command", flags: (1 << 6) });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command", flags: (1 << 6) });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id": interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id": interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ module.exports = {
|
|||||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true);
|
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||||
|
|
||||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||||
|
|||||||
@@ -216,25 +216,16 @@ class LinesPoliceCadBot extends Client {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkRoleStatus(rolesCache, serverID, isList) {
|
async checkRoleStatus(rolesCache, serverID) {
|
||||||
let hasRole = false;
|
let guild = await this.dbo.collection("prefixes").findOne({ "server.serverID": serverID }).then(guild => guild);
|
||||||
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID": serverID}).then(guild => guild);
|
|
||||||
|
if (guild.server.allowedRoles.length == 0) return true; // If we are in this function, and there are no roles to compare to, return true as if we had the role anyway
|
||||||
|
|
||||||
// If user has one of any in the list of allowed roles, hasRole is true
|
|
||||||
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
||||||
if (!isList) {
|
if (rolesCache.some(role => role.id == guild.server.allowedRoles[i])) return true; // they have at least one matching role
|
||||||
if (rolesCache.some(role => role.id == guild.server.allowedRoles[i])) {
|
|
||||||
hasRole = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (rolesCache.includes(guild.server.allowedRoles[i])) {
|
|
||||||
hasRole = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return hasRole;
|
|
||||||
|
return false; // they have no matching roles.
|
||||||
}
|
}
|
||||||
|
|
||||||
async GetGuild(GuildId) {
|
async GetGuild(GuildId) {
|
||||||
@@ -266,7 +257,7 @@ class LinesPoliceCadBot extends Client {
|
|||||||
command ie. has cop role to use
|
command ie. has cop role to use
|
||||||
name-search
|
name-search
|
||||||
*/
|
*/
|
||||||
async verifyUseCommand(serverID, rolesCache, isList) {
|
async verifyUseCommand(serverID, rolesCache) {
|
||||||
let { customRoleStatus } = await this.GetGuild(serverID)
|
let { customRoleStatus } = await this.GetGuild(serverID)
|
||||||
if (!customRoleStatus) return false; // There is no role limits
|
if (!customRoleStatus) return false; // There is no role limits
|
||||||
|
|
||||||
@@ -281,7 +272,9 @@ class LinesPoliceCadBot extends Client {
|
|||||||
if (!role) update = true;
|
if (!role) update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
// If some roles no longer exists, update
|
||||||
|
// or if customRoleStatus is true but no roles exist, update
|
||||||
|
if (update || (filteredRoles == 0 && customRoleStatus)) {
|
||||||
let newHasCustomRoles = filteredRoles > 0;
|
let newHasCustomRoles = filteredRoles > 0;
|
||||||
|
|
||||||
await this.dbo.collection("prefixes").updateOne({ 'server.serverID': serverID }, { $set: {
|
await this.dbo.collection("prefixes").updateOne({ 'server.serverID': serverID }, { $set: {
|
||||||
|
|||||||
Reference in new issue
Block a user