Have multiple preferred channels
This commit is contained in:
1 parent
c09484f617
commit
0b312947f1
3 files changed
+95
-77
No files matched your search
@@ -439,7 +439,7 @@ class Bot {
|
|||||||
return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`);
|
return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`);
|
||||||
} else {
|
} else {
|
||||||
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||||
if (guild.server.allowedRoles.length==0) return message.channel.send(`There are no roles to be removed ${message.author}!`);
|
if (guild.server.hasCustomRoles==false) return message.channel.send(`There are no roles to be removed ${message.author}!`);
|
||||||
if (!guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} is not added to your roles ${message.author}!`);
|
if (!guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} is not added to your roles ${message.author}!`);
|
||||||
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
||||||
if (guild.server.allowedRoles[i]==roleid) {
|
if (guild.server.allowedRoles[i]==roleid) {
|
||||||
@@ -464,44 +464,75 @@ class Bot {
|
|||||||
if (guild.server.hasCustomRoles==false) {
|
if (guild.server.hasCustomRoles==false) {
|
||||||
return message.channel.send('There are no roles set for the bot.');
|
return message.channel.send('There are no roles set for the bot.');
|
||||||
}
|
}
|
||||||
let rolesEmbed = new Discord.MessageEmbed()
|
|
||||||
.setColor('#0099ff')
|
|
||||||
.setTitle('Lines Police CAD')
|
|
||||||
.setURL('https://discord.gg/w2g2FFmHbF')
|
|
||||||
.setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t')
|
|
||||||
.setDescription('Allowed Roles:')
|
|
||||||
|
|
||||||
let roles = "Allowed Roles:";
|
let roles = "Allowed Roles:";
|
||||||
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
||||||
if (guild.server.allowedRoles[i] == undefined) break;
|
if (guild.server.allowedRoles[i] == undefined) break;
|
||||||
roles = roles + `\n<@&${guild.server.allowedRoles[i]}>`;
|
roles += `\n<@&${guild.server.allowedRoles[i]}>`;
|
||||||
}
|
}
|
||||||
return message.channel.send(roles);
|
return message.channel.send(roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setChannel(message, args) {
|
async setChannel(message, args) {
|
||||||
if (args.length==0) return message.channel.send(`You must provide a channel ${message.author}!`);
|
if (args.length==0) return message.channel.send(`You must provide a channel ${message.author}!`);
|
||||||
let channel = client.channels.cache.get(args[0].replace('<#', '').replace('>', ''));
|
let channelid = args[0].replace('<#', '').replace('>', '');
|
||||||
|
let channel = client.channels.cache.get(channelid);
|
||||||
if (!channel) return message.channel.send(`Cannot find that channel ${message.author}!`);
|
if (!channel) return message.channel.send(`Cannot find that channel ${message.author}!`);
|
||||||
if (channel.type=="voice") return message.channel.send(`Connot set voice channel to preferred channel ${message.author}!`);
|
if (channel.type=="voice") return message.channel.send(`Connot set voice channel to preferred channel ${message.author}!`);
|
||||||
if (channel.deleted) return message.channel.send(`Connot set deleted channel to preferred channel ${message.author}!`);
|
if (channel.deleted) return message.channel.send(`Connot set deleted channel to preferred channel ${message.author}!`);
|
||||||
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.preferredChannelId":channel.id}},function(err, res) {
|
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||||
|
if (guild.server.allowedChannels!=undefined&&guild.server.allowedChannels.includes(channelid)) return message.channel.send(`The channel ${args[0]} has already been added ${message.author}!`);
|
||||||
|
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":true}},function(err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
return message.channel.send(`Successfuly set \` ${channel.name} \` to prefered channel ${message.author}!`);
|
return message.channel.send(`Successfuly added ${args[0]} to allowed channels ${message.author}!`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeChannel(message) {
|
async removeChannel(message, args) {
|
||||||
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.preferredChannelId":null}},function(err, res) {
|
if (args.length==0) return message.channel.send(`You must provide a channel ${message.author}!`);
|
||||||
if (err) throw err;
|
let channelid = args[0].replace('<#', '').replace('>', '');
|
||||||
return message.channel.send(`Successfuly removed preferred channel ${message.author}!`);
|
let channel = client.channels.cache.get(channelid);
|
||||||
});
|
if (!channel) return message.channel.send(`Uh Oh! The channel ${args[0]} connot be found.`);
|
||||||
|
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||||
|
if (guild.server.hasCustomChannels==false) return message.channel.send(`There are no channels to be removed ${message.author}!`);
|
||||||
|
if (!guild.server.allowedChannels.includes(channelid)) return message.channel.send(`The channel ${args[0]} is not added to your roles ${message.author}!`);
|
||||||
|
for (let i = 0; i < guild.server.allowedChannels.length; i++) {
|
||||||
|
if (guild.server.allowedChannels[i]==channelid) {
|
||||||
|
if ((guild.server.allowedChannels.length-1)==0) {
|
||||||
|
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":false}},function(err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
return message.channel.send(`Successfuly removed ${args[0]} from allowed channels ${message.author}! There are no more allowed channels.`);
|
||||||
|
});
|
||||||
|
} else if ((guild.server.allowedChannels.length-1)>0) {
|
||||||
|
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedChannels":channelid}},function(err, res) {
|
||||||
|
if (err) throw err;
|
||||||
|
return message.channel.send(`Successfuly removed ${args[0]} from allowed channels ${message.author}!`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async channels(message) {
|
||||||
|
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||||
|
if (guild.server.hasCustomChannels==false) {
|
||||||
|
return message.channel.send('There are no channels set for the bot.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let channels = "Allowed Channels:";
|
||||||
|
for (let i = 0; i < guild.server.allowedChannels.length; i++) {
|
||||||
|
if (guild.server.allowedChannels[i] == undefined) break;
|
||||||
|
channels += `\n<#${guild.server.allowedChannels[i]}>`;
|
||||||
|
}
|
||||||
|
return message.channel.send(channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGuildPresets(message) {
|
async getGuildPresets(message) {
|
||||||
let prefix;
|
let prefix;
|
||||||
let channelId;
|
let channelId;
|
||||||
let customeRoleStatus;
|
let customRoleStatus;
|
||||||
|
let customChannelStatus;
|
||||||
|
let allowedChannels;
|
||||||
if (message.channel.type!="dm") {
|
if (message.channel.type!="dm") {
|
||||||
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||||
|
|
||||||
@@ -511,26 +542,32 @@ class Bot {
|
|||||||
server: {
|
server: {
|
||||||
serverID: message.guild.id,
|
serverID: message.guild.id,
|
||||||
prefix: this.config.defaultPrefix,
|
prefix: this.config.defaultPrefix,
|
||||||
hasCustomeRoles: false,
|
hasCustomRoles: false,
|
||||||
|
hasCustomChannels: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.dbo.collection("prefixes").insertOne(newGuild, function(err, res) {
|
this.dbo.collection("prefixes").insertOne(newGuild, function(err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
prefix = newGuild.server.prefix;
|
prefix = newGuild.server.prefix;
|
||||||
channelId = newGuild.server.preferredChannelId;
|
customRoleStatus = newGuild.server.hasCustomRoles;
|
||||||
customeRoleStatus = newGuild.server.hasCustomRoles;
|
customChannelStatus = newGuild.server.hasCustomChannels;
|
||||||
|
allowedChannels = null;
|
||||||
} else {
|
} else {
|
||||||
prefix = guild.server.prefix;
|
prefix = guild.server.prefix;
|
||||||
channelId = guild.server.preferredChannelId;
|
customRoleStatus = guild.server.hasCustomRoles;
|
||||||
customeRoleStatus = guild.server.hasCustomRoles;
|
customChannelStatus = guild.server.hasCustomChannels;
|
||||||
|
if (guild.server.allowedChannels!=undefined||guild.server.allowedChannels!=null&&guild.server.allowedChannels.length>0) {
|
||||||
|
allowedChannels = guild.server.allowedChannels;
|
||||||
|
} else allowedChannels = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prefix = this.config.defaultPrefix;
|
prefix = this.config.defaultPrefix;
|
||||||
channelId = null;
|
customRoleStatus = false;
|
||||||
customeRoleStatus = false;
|
customChannelStatus = false;
|
||||||
|
allowedChannels = null;
|
||||||
}
|
}
|
||||||
return {prefix, channelId, customeRoleStatus};
|
return {prefix, channelId, customRoleStatus, customChannelStatus, allowedChannels};
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkRoleStatus(message) {
|
async checkRoleStatus(message) {
|
||||||
@@ -550,11 +587,11 @@ class Bot {
|
|||||||
|
|
||||||
// Basic Commands
|
// Basic Commands
|
||||||
client.on('message', async (message) => {
|
client.on('message', async (message) => {
|
||||||
let { prefix, channelId, customeRoleStatus } = await this.getGuildPresets(message);
|
let { prefix, channelId, customRoleStatus, customChannelStatus, allowedChannels } = await this.getGuildPresets(message);
|
||||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||||
|
|
||||||
if (channelId != null && message.channel.id!=channelId) {
|
if (customChannelStatus==true&&!allowedChannels.includes(message.channel.id)) {
|
||||||
return message.channel.send(`This is not the preferred channel, please use the channel <#${channelId}> ${message.author}!`);
|
return message.channel.send(`This is not the preferred channel, please one of the allowed channels. Use \`${prefix}channels\` to see a list of allowed channels ${message.author}!`);
|
||||||
}
|
}
|
||||||
const args = message.content.slice(prefix.length).trim().split(' ');
|
const args = message.content.slice(prefix.length).trim().split(' ');
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
@@ -607,10 +644,11 @@ class Bot {
|
|||||||
{ name: `**${prefix}joincommunity** <community code>`, value: '\`Joined a community with the given code\`', inline: true },
|
{ name: `**${prefix}joincommunity** <community code>`, value: '\`Joined a community with the given code\`', inline: true },
|
||||||
{ name: `**${prefix}leavecommunity**`, value: '\`Leaves your current active community\`', inline: true },
|
{ name: `**${prefix}leavecommunity**`, value: '\`Leaves your current active community\`', inline: true },
|
||||||
{ name: `**${prefix}community**`, value: '\`Returns the name of the Community your currenty in\`', inline: true },
|
{ name: `**${prefix}community**`, value: '\`Returns the name of the Community your currenty in\`', inline: true },
|
||||||
{ name: `**${prefix}setChannel** <channel>`, value: `\`Sets preferred channel allowed for commands (Admin only command)\``, inline: true },
|
{ name: `**${prefix}setChannel** <channel>`, value: `\`Adds channel to list of allowed channels (Admin only command)\``, inline: true },
|
||||||
{ name: `**${prefix}removeChannel**`, value: `\`Removes preferred channel (Admin only command)\``, inline: true },
|
{ name: `**${prefix}removeChannel** <channel>`, value: `\`Removes channel from list of allowed channels (Admin only command)\``, inline: true },
|
||||||
{ name: `**${prefix}setRole <role>**`, value: `\`Adds role to list of allowed roles (Admin only command)\``, inline: true },
|
{ name: `**${prefix}channels**`, value: `\`Shows a list of allowed channels\``, inline: true },
|
||||||
{ name: `**${prefix}removeRole <role>**`, value: `\`Removes role from list of allowed roles (Admin only command)\``, inline: true },
|
{ name: `**${prefix}setRole** <role>`, value: `\`Adds role to list of allowed roles (Admin only command)\``, inline: true },
|
||||||
|
{ name: `**${prefix}removeRole** <role>`, value: `\`Removes role from list of allowed roles (Admin only command)\``, inline: true },
|
||||||
{ name: `**${prefix}roles**`, value: `\`Shows a list of allowed roles\``, inline: true }
|
{ name: `**${prefix}roles**`, value: `\`Shows a list of allowed roles\``, inline: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -638,7 +676,7 @@ class Bot {
|
|||||||
if (command == 'removechannel') {
|
if (command == 'removechannel') {
|
||||||
if (message.channel.type=="dm") return message.author.send(`You cannot remove a channel in a dm ${message.author}!`);
|
if (message.channel.type=="dm") return message.author.send(`You cannot remove a channel in a dm ${message.author}!`);
|
||||||
if (!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
if (!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
||||||
this.removeChannel(message);
|
this.removeChannel(message, args);
|
||||||
}
|
}
|
||||||
if (command == 'setrole') {
|
if (command == 'setrole') {
|
||||||
if (message.channel.type=="dm") return message.author.send(`You cannot set a role in a dm ${message.author}!`);
|
if (message.channel.type=="dm") return message.author.send(`You cannot set a role in a dm ${message.author}!`);
|
||||||
@@ -654,6 +692,10 @@ class Bot {
|
|||||||
if (message.channel.type=="dm") return message.author.send(`You cannot see allowed roles in a dm ${message.author}!`);
|
if (message.channel.type=="dm") return message.author.send(`You cannot see allowed roles in a dm ${message.author}!`);
|
||||||
this.roles(message);
|
this.roles(message);
|
||||||
}
|
}
|
||||||
|
if (command == 'channels') {
|
||||||
|
if (message.channel.tpye=="dm") return message.channel.send(`You cannot see allowed channels in a dm ${message.author}!`);
|
||||||
|
this.channels(message);
|
||||||
|
}
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
if (command == 'login') {
|
if (command == 'login') {
|
||||||
@@ -663,78 +705,54 @@ class Bot {
|
|||||||
if (command == 'logout') this.remoteLogout(message);
|
if (command == 'logout') this.remoteLogout(message);
|
||||||
if (command == 'validstatus') message.channel.send(validStatus);
|
if (command == 'validstatus') message.channel.send(validStatus);
|
||||||
if (command == 'checkstatus') {
|
if (command == 'checkstatus') {
|
||||||
if (customeRoleStatus) {
|
if (customRoleStatus) {
|
||||||
let hasRole = await this.checkRoleStatus(message);
|
let hasRole = await this.checkRoleStatus(message);
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
this.checkStatus(message, args);
|
this.checkStatus(message, args);
|
||||||
} else {
|
} else return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
||||||
return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
} else this.checkStatus(message, args);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.checkStatus(message, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (command == 'updatestatus') {
|
if (command == 'updatestatus') {
|
||||||
if (customeRoleStatus) {
|
if (customRoleStatus) {
|
||||||
let hasRole = await this.checkRoleStatus(message);
|
let hasRole = await this.checkRoleStatus(message);
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
this.updateStatus(message, args, prefix);
|
this.updateStatus(message, args, prefix);
|
||||||
} else {
|
} else return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
||||||
return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
} else this.updateStatus(message, args, prefix);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.updateStatus(message, args, prefix);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (command == 'account') this.account(message);
|
if (command == 'account') this.account(message);
|
||||||
if (command == 'penalcodes') return message.channel.send('https://www.linespolice-cad.com/penal-code');
|
if (command == 'penalcodes') return message.channel.send('https://www.linespolice-cad.com/penal-code');
|
||||||
if (command == 'namedb') {
|
if (command == 'namedb') {
|
||||||
if (customeRoleStatus) {
|
if (customRoleStatus) {
|
||||||
let hasRole = await this.checkRoleStatus(message);
|
let hasRole = await this.checkRoleStatus(message);
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
this.nameSearch(message, args);
|
this.nameSearch(message, args);
|
||||||
} else {
|
} else return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
||||||
return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
} else this.nameSearch(message, args);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.nameSearch(message, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (command == 'platedb') {
|
if (command == 'platedb') {
|
||||||
if (customeRoleStatus) {
|
if (customRoleStatus) {
|
||||||
let hasRole = await this.checkRoleStatus(message);
|
let hasRole = await this.checkRoleStatus(message);
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
this.plateSearch(message, args);
|
this.plateSearch(message, args);
|
||||||
} else {
|
} else return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
||||||
return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
} else this.plateSearch(message, args);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.plateSearch(message, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (command == 'firearmdb') {
|
if (command == 'firearmdb') {
|
||||||
if (customeRoleStatus) {
|
if (customRoleStatus) {
|
||||||
let hasRole = await this.checkRoleStatus(message);
|
let hasRole = await this.checkRoleStatus(message);
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
this.firearmSearch(message, args);
|
this.firearmSearch(message, args);
|
||||||
} else {
|
} else return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
||||||
return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
} else this.firearmSearch(message, args);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.firearmSearch(message, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (command == 'panic') {
|
if (command == 'panic') {
|
||||||
if (customeRoleStatus) {
|
if (customRoleStatus) {
|
||||||
let hasRole = await this.checkRoleStatus(message);
|
let hasRole = await this.checkRoleStatus(message);
|
||||||
if (hasRole) {
|
if (hasRole) {
|
||||||
this.enablePanic(message);
|
this.enablePanic(message);
|
||||||
} else {
|
} else return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
||||||
return message.channel.send(`You don't permission to use this command ${message.author}!`);
|
} else this.enablePanic(message);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.enablePanic(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (command == 'joincommunity') this.joinCommunity(message, args);
|
if (command == 'joincommunity') this.joinCommunity(message, args);
|
||||||
if (command == 'leavecommunity') this.leaveCommunity(message);
|
if (command == 'leavecommunity') this.leaveCommunity(message);
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"defaultPrefix": "?",
|
"defaultPrefix": "?",
|
||||||
"version": "Beta 1.8.7",
|
"version": "Beta 1.9.0",
|
||||||
"socket": "https://police-cad-dev.herokuapp.com/"
|
"socket": "https://police-cad-dev.herokuapp.com/"
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"defaultPrefix": "?",
|
"defaultPrefix": "?",
|
||||||
"version": "1.8.7",
|
"version": "1.9.0",
|
||||||
"socket": "https://www.linespolice-cad.com/"
|
"socket": "https://www.linespolice-cad.com/"
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user