From 2c1d15cfc4ebb486b43c33db22bb5e3f817e3af2 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 13:27:23 -0800 Subject: [PATCH 01/29] update/add logs and update prefix --- .gitignore | 3 +- Logs.log | 93 +++++++++++++++++++++++ commands/help.js | 7 +- commands/ping.js | 38 +++++++++ commands/setPrefix.js | 55 ++++++++++++++ commands/stats.js | 11 ++- events/message.js | 15 ++-- LPS.js => structures/LinesPoliceCadBot.js | 33 +++++--- util/RegisterSlashCommands.js | 4 +- 9 files changed, 228 insertions(+), 31 deletions(-) create mode 100644 Logs.log create mode 100644 commands/ping.js create mode 100644 commands/setPrefix.js rename LPS.js => structures/LinesPoliceCadBot.js (96%) diff --git a/.gitignore b/.gitignore index 42118d8..ab4a373 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ dev.js config/dev-config.js # Logs -logs -*.log \ No newline at end of file +logs/* diff --git a/Logs.log b/Logs.log new file mode 100644 index 0000000..e4ba59c --- /dev/null +++ b/Logs.log @@ -0,0 +1,93 @@ +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Client has been logged in"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Client has been logged in"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"21:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Successfully Logged in as LPC-Bot Alpha#5344"} +{"level":"info","message":"22:function getMinutes() { [native code] } - 7:2:2022 | Info: Interaction"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Command Loaded: help"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Command Loaded: stats"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Event Loaded: guildCreate"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Event Loaded: message"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Event Loaded: ready"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Error: ENOENT: no such file or directory, scandir 'C:\\Users\\flami\\Desktop\\Projects\\commands'"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Error: ENOENT: no such file or directory, scandir 'C:\\Users\\flami\\Desktop\\Projects\\events'"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Error: ENOENT: no such file or directory, scandir 'C:\\Users\\flami\\Desktop\\Projects\\commands'"} +{"level":"info","message":"11:function getMinutes() { [native code] } - 8:2:2022 | Info: Error: ENOENT: no such file or directory, scandir 'C:\\Users\\flami\\Desktop\\Projects\\events'"} diff --git a/commands/help.js b/commands/help.js index 60c5692..c469a02 100644 --- a/commands/help.js +++ b/commands/help.js @@ -11,7 +11,7 @@ module.exports = { aliases: ["command", "commands", "cmd"], /** * - * @param {import("../LPS")} client + * @param {require("../structures/LinesPoliceCadBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 @@ -91,13 +91,16 @@ module.exports = { ], /** * - * @param {import("../LPS")} client + * @param {require("../structures/LinesPoliceCadBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } let Commands = client.commands.map( (cmd) => `\`${GuildDB ? GuildDB.prefix : client.config.DefaultPrefix}${ diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..73fe84c --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,38 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "ping", + description: "check the bots responce", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + return message.channel.send('Pong!'); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + interaction.send('Pong!'); + }, + }, +} \ No newline at end of file diff --git a/commands/setPrefix.js b/commands/setPrefix.js new file mode 100644 index 0000000..37a101a --- /dev/null +++ b/commands/setPrefix.js @@ -0,0 +1,55 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "setprefix", + description: "Update prefix for the bot", + usage: "[new Prefix]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + aliases: ["newprefix", "new_prefix", "set_prefix"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args, { GuildDB }) => { + if (args[0]==undefined) return message.channel.send(`You must provide a \`new prefix\` ${message.author}`); + if (args[0].length<1) return message.channel.send('Your new prefix must be \`1\` character!') + client.dbo.collection("prefixes").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.prefix":args[0]}},function(err, res) { + if (err) throw err; + message.channel.send(`The new prefix is now **\`${args[0]}\`**`); + }); + }, + SlashCommand: { + options: [ + { + name: "new-prefix", + description: "Update prefix for the bot", + value: "setprefix", + type: 3, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + if (args[0].length<1) return interaction.send('Your new prefix must be \`1\` character!') + client.dbo.collection("prefixes").updateOne({"server.serverID":GuildDB.serverID},{$set:{"server.prefix":args[0].value}},function(err, res) { + if (err) throw err; + interaction.send(`The new prefix is now **\`${args[0].value}\`**`); + }); + }, + }, +} \ No newline at end of file diff --git a/commands/stats.js b/commands/stats.js index 1e9aa55..f1bab18 100644 --- a/commands/stats.js +++ b/commands/stats.js @@ -12,7 +12,7 @@ module.exports = { aliases: ["stat", "statistics", "info"], /** * - * @param {import("../LPS")} client + * @param {require("../structures/LinesPoliceCadBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 @@ -30,12 +30,15 @@ module.exports = { SlashCommand: { /** * - * @param {import("../LPS")} client + * @param {require("../structures/LinesPoliceCadBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 */ - run: async (client, interaction) => { + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } const { version } = require("discord.js"); const stats = new MessageEmbed() .setColor('#0099ff') @@ -44,7 +47,7 @@ module.exports = { .addField(" \u200B ", "**Channels** : ` " + `${client.channels.cache.size}` + " `") .addField(" \u200B ", "**Servers** : ` " + `${client.guilds.cache.size}` + " `") .addField(" \u200B ", "**Users** : ` " + `${client.users.cache.size}` + " `") - return message.channel.send(stats) + interaction.send(stats) }, }, }; \ No newline at end of file diff --git a/events/message.js b/events/message.js index 9f735f3..44a2b5b 100644 --- a/events/message.js +++ b/events/message.js @@ -1,6 +1,6 @@ /** * - * @param {require("../LPS")} client + * @param {require("../structures/LinesPoliceCadBot")} client * @param {require("discord.js").Message} message * @returns {void} or nothing if you didn't know */ @@ -12,15 +12,6 @@ module.exports = async (client, message) => { let GuildDB = await client.GetGuild(message.guild.id); if (GuildDB && GuildDB.prefix) prefix = GuildDB.prefix; - //Initialize GuildDB - if (!GuildDB) { - await client.database.guild.set(message.guild.id, { - prefix: prefix, - DJ: null, - }); - GuildDB = await client.GetGuild(message.guild.id); - } - //Prefixes also have mention match const prefixMention = new RegExp(`^<@!?${client.user.id}> `); prefix = message.content.match(prefixMention) @@ -29,6 +20,10 @@ module.exports = async (client, message) => { if (message.content.indexOf(prefix) !== 0) return; + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(message.channel.id)) { + return message.channel.send(`You are not allowed to use the bot in this channel.`); + } + const args = message.content.slice(prefix.length).trim().split(/ +/g); //Making the command lowerCase because our file name will be in lowerCase const command = args.shift().toLowerCase(); diff --git a/LPS.js b/structures/LinesPoliceCadBot.js similarity index 96% rename from LPS.js rename to structures/LinesPoliceCadBot.js index 36b4f81..b80ba29 100644 --- a/LPS.js +++ b/structures/LinesPoliceCadBot.js @@ -1,7 +1,8 @@ const { Collection, Client, MessageEmbed } = require('discord.js'); -const CommandHandler = require('./commands').Commands; +const CommandHandler = require('../commands').Commands; const MongoClient = require('mongodb').MongoClient; -const Logger = require("./util/Logger"); +const Logger = require("../util/Logger"); +const path = require("path"); const fs = require('fs'); class LinesPoliceCadBot extends Client { @@ -11,13 +12,15 @@ class LinesPoliceCadBot extends Client { this.config = config; this.commands = new Collection(); - this.logger = new Logger('./Logs.log'); + this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log")); if (this.config.Token === "") return new TypeError( "The botconfig.js is not filled out. Please make sure nothing is blank, otherwise the bot will not work properly." ); + this.db; + this.dbo; this.connectMongo(this.config.mongoURI, this.config.dbo); this.LoadCommands(); this.LoadEvents(); @@ -69,10 +72,11 @@ class LinesPoliceCadBot extends Client { async connectMongo(mongoURI, dbo) { this.db = await MongoClient.connect(mongoURI,{useUnifiedTopology:true}); this.dbo = this.db.db(dbo); + this.log('Successfully connected to mongoDB'); } LoadCommands() { - let CommandsDir = './commands'; + let CommandsDir = path.join(__dirname, '..', 'commands'); fs.readdir(CommandsDir, (err, files) => { if (err) this.log(err); else @@ -91,7 +95,7 @@ class LinesPoliceCadBot extends Client { } LoadEvents() { - let EventsDir = './events'; + let EventsDir = path.join(__dirname, '..', 'events'); fs.readdir(EventsDir, (err, files) => { if (err) this.log(err); else @@ -103,9 +107,17 @@ class LinesPoliceCadBot extends Client { }); } + sendTime(Channel, Error) { + let embed = new MessageEmbed() + .setColor(this.config.EmbedColor) + .setDescription(Error); + + Channel.send(embed); + } + RegisterSlashCommands() { this.guilds.cache.forEach((guild) => { - require("./util/RegisterSlashCommands")(this, guild.id); + require("../util/RegisterSlashCommands")(this, guild.id); }); } @@ -121,7 +133,6 @@ class LinesPoliceCadBot extends Client { async GetGuild(GuildId) { let prefix; - let channelId; let customRoleStatus; let customChannelStatus; let allowedChannels; @@ -154,10 +165,10 @@ class LinesPoliceCadBot extends Client { } let guildData = { prefix: prefix, - channelId: channelId, + allowedChannels: allowedChannels, customRoleStatus: customRoleStatus, - customChannelStatus: allowedChannels, - guildId: GuildId + customChannelStatus: customChannelStatus, + serverID: GuildId } return guildData; } @@ -420,4 +431,4 @@ class LinesPoliceCadBot extends Client { // } } -module.exports = {LinesPoliceCadBot}; +module.exports = LinesPoliceCadBot; \ No newline at end of file diff --git a/util/RegisterSlashCommands.js b/util/RegisterSlashCommands.js index a17c707..087c6e7 100644 --- a/util/RegisterSlashCommands.js +++ b/util/RegisterSlashCommands.js @@ -3,12 +3,12 @@ const path = require("path"); /** * Register slash commands for a guild - * @param {require("../LPS")} client + * @param {require("../structures/LinesPoliceCadBot")} client * @param {string} guild */ module.exports = (client, guild) => { - let commandsDir = path.join(__dirname, "..", "commands");; + let commandsDir = path.join(__dirname, "..", "commands"); fs.readdir(commandsDir, (err, files) => { if (err) throw err; From 55912cb29ed013c63542ac930d1ab52275043849 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 13:31:00 -0800 Subject: [PATCH 02/29] update/add remote login --- commands/login.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 commands/login.js diff --git a/commands/login.js b/commands/login.js new file mode 100644 index 0000000..9b46cc5 --- /dev/null +++ b/commands/login.js @@ -0,0 +1,38 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "login", + description: "Connect your Lines Police CAD account to Discord", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + return message.channel.send('Login from Lines Police CAD account management https://www.linespolice-cad.com/'); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + interaction.send('Login from Lines Police CAD account management https://www.linespolice-cad.com/'); + }, + }, +} \ No newline at end of file From 6e6dbd2c3bfcb86d445bf806adb91c5655e20880 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 13:42:09 -0800 Subject: [PATCH 03/29] update/add logout command --- commands/logout.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 commands/logout.js diff --git a/commands/logout.js b/commands/logout.js new file mode 100644 index 0000000..3f09096 --- /dev/null +++ b/commands/logout.js @@ -0,0 +1,48 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "logout", + description: "Disconnect your Lines Police CAD account from Discord", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You cannot logout if your not logged in.`); + client.dbo.collection("users").updateOne({"user.discord.id":message.author.id},{$unset:{"user.discord":""}, $set:{"user.discordConnected":false}},function(err,res) { + if (err) throw err; + return message.channel.send(`Succesfully disconnected you Discord account.`); + }); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You cannot logout if your not logged in.`); + client.dbo.collection("users").updateOne({"user.discord.id":interaction.member.user.id},{$unset:{"user.discord":""}, $set:{"user.discordConnected":false}},function(err,res) { + if (err) throw err; + return interaction.send(`Succesfully disconnected you Discord account.`); + }); + }, + }, +} \ No newline at end of file From 5a8753357e88ec594fbbafbf174811009f7c5a55 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 13:52:34 -0800 Subject: [PATCH 04/29] update/add account view --- commands/account.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 commands/account.js diff --git a/commands/account.js b/commands/account.js new file mode 100644 index 0000000..ffa8610 --- /dev/null +++ b/commands/account.js @@ -0,0 +1,45 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "account", + description: "View connected Lines Police CAD account", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (user==null) return message.channel.send(`You are not logged in ${message.author}`); + return message.author.send(`${message.author} Logged in as **${user.user.username}** | **${user.user.email}**`); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (user==null) return interaction.send(`You are not logged in.`); + client.users.fetch(interaction.member.user.id) + .then(duser => duser.send(`<@${interaction.member.user.id}> Logged in as **${user.user.username}** | **${user.user.email}**`).catch(err => {client.log(err)})) + .catch(err => {client.log(err)}); + return + }, + }, +} \ No newline at end of file From 6cbd981a00033b4ccc7d0ad15e5c78a8f1a16a46 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 14:06:29 -0800 Subject: [PATCH 05/29] uppdate/add name search --- commands/nameSearch.js | 227 +++++++++++++++++++++++++++++++++++++++++ config/beta-config.js | 2 +- 2 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 commands/nameSearch.js diff --git a/commands/nameSearch.js b/commands/nameSearch.js new file mode 100644 index 0000000..0b3227a --- /dev/null +++ b/commands/nameSearch.js @@ -0,0 +1,227 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + + +module.exports = { + name: "namesearch", + description: "Search a Civilian in your community", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["namedb", "name_search", "name_db"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + let data; + if (args.length==0) return message.channel.send(`You must provide a \`First Name\`, \`Last Name\` and \`DOB\`(yyyy-mm-dd).`); + if (args.length==1) return message.channel.send(`You're missing a \`Last Name\` and \`DOB\`(yyyy-mm-dd).`); + if (args.length==2) return message.channel.send(`You're missing a \`DOB\`(yyyy-mm-dd).`); + + data = { + user: user, + query: { + firstName: args[0], + lastName: args[1], + dateOfBirth: args[2], + activeCommunityID: user.user.activeCommunity + } + } + + const socket = io.connect(client.config.socket); + socket.emit("bot_name_search", data); + socket.on("bot_name_search_results", results => { + + if (results.user._id==user._id) { + if (results.civilians.length == 0) { + return message.channel.send(`Name \`${args[0]} ${args[1]}\` not found ${message.author}`); + } + + for (let i = 0; i < results.civilians.length; i++) { + // Get Drivers Licence Status + let licenceStatus; + if (results.civilians[i].civilian.licenseStatus == 1) licenceStatus = 'Valid'; + if (results.civilians[i].civilian.licenceStatus == 2) licenceStatus = 'Revoked'; + if (results.civilians[i].civilian.licenceStatus == 3) licenceStatus = 'None'; + // Get Firearm Licence Status + let firearmLicence = results.civilians[i].civilian.firearmLicense; + if (firearmLicence == undefined || firearmLicence == null) firearmLicence = 'None'; + if (firearmLicence == '2') firearmLicence = 'Valid'; + if (firearmLicence == '3') firearmLicence = 'Revoked'; + let nameResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setDescription('Name Search Results') + .addFields( + { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, + { name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true }, + { name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true }, + { name: `**Drivers License**`, value: `\`${licenceStatus}\``, inline: true }, + { name: `**Firearm Licence**`, value: `\`${firearmLicence}\``, inline: true }, + { name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true } + ) + // Check Other details + let address = results.civilians[i].civilian.address; + let occupation = results.civilians[i].civilian.occupation; + let height = results.civilians[i].civilian.height; + let weight = results.civilians[i].civilian.weight; + let eyeColor = results.civilians[i].civilian.eyeColor; + let hairColor = results.civilians[i].civilian.hairColor; + if (address != null && address != undefined && address != '') nameResult.addFields({ name: `**Address**`, value: `\`${address}\``, inline: true }); + if (occupation != null && occupation != undefined && occupation != '') nameResult.addFields({ name: `**Occupation**`, value: `\`${occupation}\``, inline: true }); + if (height!=null&&height!=undefined&&height!="NaN"&&height!='') { + if (results.civilians[i].civilian.heightClassification=='imperial') { + let ft = Math.floor(height/12); + let inch = height%12; + nameResult.addFields({ name: '**Height**', value: `\`${ft}'${inch}"\``, inline: true }); + } else { + nameResult.addFields({ name: '**Height**', value: `\`${height}cm\``, inline: true }); + } + } + if (weight!=null&&weight!=undefined&&weight!='') { + if (results.civilians[i].civilian.weightClassification=='imperial') { + nameResult.addFields({ name: '**Weight**', value: `\`${weight}lbs.\``, inline: true }); + } else { + nameResult.addFields({ name: '**Weight**', value: `\`${weight}kgs.\``, inline: true }); + } + } + if (eyeColor!=null&&eyeColor!=undefined&&eyeColor!='') nameResult.addFields({name:'**Eye Color**',value:`\`${eyeColor}\``,inline:true}); + if (hairColor!=null&&hairColor!=undefined&&hairColor!='') nameResult.addFields({name:'**Hair Color**',value:`\`${hairColor}\``,inline:true}); + nameResult.addFields({name:'**Organ Donor**',value:`\`${results.civilians[i].civilian.organDonor}\``,inline:true}); + nameResult.addFields({name:'**Veteran**',value:`\`${results.civilians[i].civilian.veteran}\``,inline:true}); + message.channel.send(nameResult); + } + } + socket.disconnect(); + }); + }, + SlashCommand: { + options: [ + { + name: "firstname", + description: "Civilian's First Name", + value: "firstname", + type: 3, + required: true, + }, + { + name: "lastname", + description: "Civilian's Last Name", + value: "lastname", + type: 3, + required: true, + }, + { + name: "dob", + description: "Civilian's DOB (yyyy-mm-dd)", + value: "dob", + type: 3, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + let data; + + data = { + user: user, + query: { + firstName: args[0].value, + lastName: args[1].value, + dateOfBirth: args[2].value, + activeCommunityID: user.user.activeCommunity + } + } + + const socket = io.connect(client.config.socket); + socket.emit("bot_name_search", data); + socket.on("bot_name_search_results", results => { + + if (results.user._id==user._id) { + if (results.civilians.length == 0) { + return interaction.send(`Name \`${args[0].value} ${args[1].value}\` not found.`); + } + + for (let i = 0; i < results.civilians.length; i++) { + // Get Drivers Licence Status + let licenceStatus; + if (results.civilians[i].civilian.licenseStatus == 1) licenceStatus = 'Valid'; + if (results.civilians[i].civilian.licenceStatus == 2) licenceStatus = 'Revoked'; + if (results.civilians[i].civilian.licenceStatus == 3) licenceStatus = 'None'; + // Get Firearm Licence Status + let firearmLicence = results.civilians[i].civilian.firearmLicense; + if (firearmLicence == undefined || firearmLicence == null) firearmLicence = 'None'; + if (firearmLicence == '2') firearmLicence = 'Valid'; + if (firearmLicence == '3') firearmLicence = 'Revoked'; + let nameResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setDescription('Name Search Results') + .addFields( + { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, + { name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true }, + { name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true }, + { name: `**Drivers License**`, value: `\`${licenceStatus}\``, inline: true }, + { name: `**Firearm Licence**`, value: `\`${firearmLicence}\``, inline: true }, + { name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true } + ) + // Check Other details + let address = results.civilians[i].civilian.address; + let occupation = results.civilians[i].civilian.occupation; + let height = results.civilians[i].civilian.height; + let weight = results.civilians[i].civilian.weight; + let eyeColor = results.civilians[i].civilian.eyeColor; + let hairColor = results.civilians[i].civilian.hairColor; + if (address != null && address != undefined && address != '') nameResult.addFields({ name: `**Address**`, value: `\`${address}\``, inline: true }); + if (occupation != null && occupation != undefined && occupation != '') nameResult.addFields({ name: `**Occupation**`, value: `\`${occupation}\``, inline: true }); + if (height!=null&&height!=undefined&&height!="NaN"&&height!='') { + if (results.civilians[i].civilian.heightClassification=='imperial') { + let ft = Math.floor(height/12); + let inch = height%12; + nameResult.addFields({ name: '**Height**', value: `\`${ft}'${inch}"\``, inline: true }); + } else { + nameResult.addFields({ name: '**Height**', value: `\`${height}cm\``, inline: true }); + } + } + if (weight!=null&&weight!=undefined&&weight!='') { + if (results.civilians[i].civilian.weightClassification=='imperial') { + nameResult.addFields({ name: '**Weight**', value: `\`${weight}lbs.\``, inline: true }); + } else { + nameResult.addFields({ name: '**Weight**', value: `\`${weight}kgs.\``, inline: true }); + } + } + if (eyeColor!=null&&eyeColor!=undefined&&eyeColor!='') nameResult.addFields({name:'**Eye Color**',value:`\`${eyeColor}\``,inline:true}); + if (hairColor!=null&&hairColor!=undefined&&hairColor!='') nameResult.addFields({name:'**Hair Color**',value:`\`${hairColor}\``,inline:true}); + nameResult.addFields({name:'**Organ Donor**',value:`\`${results.civilians[i].civilian.organDonor}\``,inline:true}); + nameResult.addFields({name:'**Veteran**',value:`\`${results.civilians[i].civilian.veteran}\``,inline:true}); + interaction.send(nameResult); + } + } + socket.disconnect(); + }); + }, + }, +} \ No newline at end of file diff --git a/config/beta-config.js b/config/beta-config.js index 03d986a..e11b280 100644 --- a/config/beta-config.js +++ b/config/beta-config.js @@ -3,7 +3,7 @@ module.exports = { Version: "2.0.0 Beta", Admins: ["userID", "userID"], // Admins of the bot defaultPrefix: "?", - socket: "https://www.linespolice-cad.com/", + socket: "https://police-cad-dev.herokuapp.com/", SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link Token: process.env.TOKEN || "", //Discord Bot Token Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes From 68120d1e60d70579a1f3b70baffc6ab7c40c54eb Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 19:58:56 -0800 Subject: [PATCH 06/29] update/add nameSearch and debug control --- commands/debug.js | 133 ++++++++++++++++++++++++++++++++ commands/help.js | 14 ++-- commands/nameSearch.js | 9 ++- config/beta-config.js | 2 +- config/config.js | 2 +- structures/LinesPoliceCadBot.js | 11 ++- 6 files changed, 156 insertions(+), 15 deletions(-) create mode 100644 commands/debug.js diff --git a/commands/debug.js b/commands/debug.js new file mode 100644 index 0000000..52c81da --- /dev/null +++ b/commands/debug.js @@ -0,0 +1,133 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "debug", + description: "Debug for bot admin", + usage: "command", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args, { GuildDB }) => { + if (!client.config.Admins.includes(message.author.id)) return; + + if (args.length==0) return message.channel.send('Debug Error: Provide a debug command'); + if (!client.exists(args[0])) return message.channel.send('Debug Error: Provide a valid debug command'); + + let debugConsole = false + if (client.exists(args[1])&&args[1]=='true') debugConsole = true + + let command = args[0].toLowerCase(); + + if (command == 'server' || command == 'guild') { + if (debugConsole) { + client.log("Debug: Guild >> "); + console.debug(GuildDB); + } + return message.channel.send("Debug: guild >> read log output") + + } else if (command == "interaction") { + return message.channel.send(`Use slash command to debug \`interaction\``); + + } else if (command == "message") { + if (debugConsole) { + client.log("Debug: message >> "); + console.debug(message); + } + return message.channel.send("Debug: message >> read log output"); + + } else if (command == "pingserver") { + const socket = io.connect(client.config.socket); + socket.emit('botping', {message:'hello there'}); + socket.on('botpong', (data) => { + if (debugConsole) client.log('Debug: Socket responded') + return message.channel.send(`Debug: Socket responded`) + socket.disconnect(); + }); + + } else if (command == "apicheck") { + // TODO: Make axios call to api and get api health + return message.channel.send('Debug Notice: \`apicheck\` is currently unavailable'); + + } else { + return message.channel.send('Debug Error: Provide a valid debug command'); + + } + }, + SlashCommand: { + options: [ + { + name: "command", + description: "The debug command to execute", + value: "command", + type: 3, + required: true, + }, + { + name: "consoleoutput", + description: "Output debug messages to console (deault=false)", + value: "consoleoutput", + type: 5, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (!client.config.Admins.includes(interaction.member.user.id)) return; + + if (args.length==0) return message.channel.send('Debug Error: Provide a debug command'); + if (!client.exists(args[0].value)) return interaction.send('Debug Error: Provide a valid debug command'); + + let debugConsole = args[1].value; + + let command = args[0].value.toLowerCase(); + + if (command == 'server' || args[0] == 'guild') { + if (debugConsole) client.log("Debug: Guild >> ");console.debug(GuildDB); + return interaction.send("Debug: guild >> read log output") + + } else if (command == "interaction") { + if (debugConsole) { + client.log("Debug: interaction >> "); + console.debug(interaction); + } + return interaction.send("Debug: interaction >> read log output"); + + } else if (command == "message") { + return interaction.send(`Use command with prefix to debug \`message\``); + + } else if (command == "pingserver") { + const socket = io.connect(client.config.socket); + socket.emit('botping', {message:'hello there'}); + socket.on('botpong', (data) => { + if (debugConsole) client.log('Debug: Socket responded') + return interaction.send(`Debug: Socket responded`) + socket.disconnect(); + }); + + } else if (command == "apicheck") { + // TODO: Make axios call to api and get api health + return interaction.send('Debug Notice: \`apicheck\` is currently unavailable'); + + } else { + return interaction.send('Debug Error: Provide a valid debug command'); + + } + }, + }, +} diff --git a/commands/help.js b/commands/help.js index c469a02..3c057f5 100644 --- a/commands/help.js +++ b/commands/help.js @@ -17,11 +17,10 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args, { GuildDB }) => { - let Commands = client.commands.map( - (cmd) => - `\`${GuildDB ? GuildDB.prefix : client.config.DefaultPrefix}${ + let Commands = client.commands.map((cmd) => + cmd.name != 'debug' ? `\`${GuildDB ? GuildDB.prefix : client.config.DefaultPrefix}${ cmd.name - }${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}` + }${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}` : null ); let Embed = new MessageEmbed() @@ -101,11 +100,10 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } - let Commands = client.commands.map( - (cmd) => - `\`${GuildDB ? GuildDB.prefix : client.config.DefaultPrefix}${ + let Commands = client.commands.map((cmd) => + cmd.name != 'debug' ? `\`${GuildDB ? GuildDB.prefix : client.config.DefaultPrefix}${ cmd.name - }${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}` + }${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}` : null ); let Embed = new MessageEmbed() diff --git a/commands/nameSearch.js b/commands/nameSearch.js index 0b3227a..81514e8 100644 --- a/commands/nameSearch.js +++ b/commands/nameSearch.js @@ -1,7 +1,6 @@ const { MessageEmbed } = require('discord.js'); const io = require('socket.io-client'); - module.exports = { name: "namesearch", description: "Search a Civilian in your community", @@ -18,7 +17,13 @@ module.exports = { * @param {string[]} args * @param {*} param3 */ - run: async (client, message, args) => { + run: async (client, message, args, { GuildDB }) => { + if (GuildDB.customRoleStatus) { + let userRoles = []; // TODO: get user roles + let hasRole = await client.hasRole(userRoles, GuildDB.serverID); + if (!hasRole) return message.channel.send(`You don't have permission to use this command.`); + } + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); let data; diff --git a/config/beta-config.js b/config/beta-config.js index e11b280..2761ab8 100644 --- a/config/beta-config.js +++ b/config/beta-config.js @@ -1,7 +1,7 @@ module.exports = { Dev: "DEVELOPMENT", Version: "2.0.0 Beta", - Admins: ["userID", "userID"], // Admins of the bot + Admins: ["362791661274660874"], // Admins of the bot defaultPrefix: "?", socket: "https://police-cad-dev.herokuapp.com/", SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link diff --git a/config/config.js b/config/config.js index f3a86e4..4f2389e 100644 --- a/config/config.js +++ b/config/config.js @@ -1,7 +1,7 @@ module.exports = { Dev: "PRODUCTION", Version: "2.0.0", - Admins: ["userID", "userID"], // Admins of the bot + Admins: ["362791661274660874"], // Admins of the bot defaultPrefix: "?", socket: "https://www.linespolice-cad.com/", SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link diff --git a/structures/LinesPoliceCadBot.js b/structures/LinesPoliceCadBot.js index b80ba29..a8fe82d 100644 --- a/structures/LinesPoliceCadBot.js +++ b/structures/LinesPoliceCadBot.js @@ -75,6 +75,8 @@ class LinesPoliceCadBot extends Client { this.log('Successfully connected to mongoDB'); } + exists(n){return null!=n&&null!=n&&""!=n} + LoadCommands() { let CommandsDir = path.join(__dirname, '..', 'commands'); fs.readdir(CommandsDir, (err, files) => { @@ -121,12 +123,15 @@ class LinesPoliceCadBot extends Client { }); } - async checkRoleStatus(message) { + async checkRoleStatus(roles, serverID) { let hasRole = false; - 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":serverID}).then(guild => guild); // 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++) { - if (message.member.roles.cache.some(role => role.id == guild.server.allowedRoles[i])) hasRole = true; + if (roles.includes(guild.server.allowedRoles[i])) { + hasRole = true + break + } } return hasRole; } From 3e2fe386c3d8c5f580972d46ead11b240976f36f Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 20:20:12 -0800 Subject: [PATCH 07/29] update/add plateSearch --- commands/nameSearch.js | 4 +- commands/plateSearch.js | 141 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 commands/plateSearch.js diff --git a/commands/nameSearch.js b/commands/nameSearch.js index 81514e8..21dc2f8 100644 --- a/commands/nameSearch.js +++ b/commands/nameSearch.js @@ -3,8 +3,8 @@ const io = require('socket.io-client'); module.exports = { name: "namesearch", - description: "Search a Civilian in your community", - usage: "", + description: "Search a civilian", + usage: "[First Name] [Last Name] [yyyy-mm-dd]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/plateSearch.js b/commands/plateSearch.js new file mode 100644 index 0000000..f1ca76b --- /dev/null +++ b/commands/plateSearch.js @@ -0,0 +1,141 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "platesearch", + description: "Search for a registered Vehicle", + usage: "[Plate #]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["plate_search", "platedb", "plate_db"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (args.length==0) return message.channel.send(`You are missing a \`Plate #\`.`); + let data = { + user: user, + query: { + plateNumber: args[0], + activeCommunityID: user.user.activeCommunity + } + } + const socket = io.connect(client.config.socket); + socket.emit('bot_plate_search', data); + socket.on('bot_plate_search_results', results => { + + if (results.user._id==user._id) { + if (results.vehicles.length == 0) { + return message.channel.send(`Plate Number \`${args[0]}\` not found.`); + } + + for (let i = 0; i < results.vehicles.length; i++) { + let plateResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setDescription('Plate Search Results') + .addFields( + { name: `**Plate #**`, value: `\`${results.vehicles[i].vehicle.plate}\``, inline: true }, + { name: `**Vin #**`, value: `\`${results.vehicles[i].vehicle.vin}\``, inline: true }, + { name: `**Model**`, value: `\`${results.vehicles[i].vehicle.model}\``, inline: true }, + { name: `**Color**`, value: `\`${results.vehicles[i].vehicle.color}\``, inline: true }, + { name: `**Owner**`, value: `\`${results.vehicles[i].vehicle.registeredOwner}\``, inline: true }, + ) + // Other details + let validRegistration = results.vehicles[i].vehicle.validRegistration; + let validInsurance = results.vehicles[i].vehicle.validInsurance; + let stolen = results.vehicles[i].vehicle.isStolen; + if (validRegistration=='1') plateResult.addFields({ name: `**Registration**`, value: `\`Valid\``, inline: true }); + if (validRegistration=='2') plateResult.addFields({ name: `**Registration**`, value: `\`InValid\``, inline: true }); + if (validInsurance=='1') plateResult.addFields({ name: `**Insurance**`, value: `\`Valid\``, inline: true }); + if (validInsurance=='2') plateResult.addFields({ name: `**Insurance**`, value: `\`InValid\``, inline: true }); + if (stolen=='1') plateResult.addFields({ name: `**Stolen**`, value: `\`No\``, inline: true }); + if (stolen=='2') plateResult.addFields({ name: `**Stolen**`, value: `\`Yes\``, inline: true }); + message.channel.send(plateResult); + } + } + socket.disconnect(); + }); + }, + SlashCommand: { + options: [ + { + name: "platenumber", + description: "Vehicle's license plate number", + value: "platenumber", + type: 3, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + let data = { + user: user, + query: { + plateNumber: args[0].value, + activeCommunityID: user.user.activeCommunity + } + } + const socket = io.connect(client.config.socket); + socket.emit('bot_plate_search', data); + socket.on('bot_plate_search_results', results => { + + if (results.user._id==user._id) { + if (results.vehicles.length == 0) { + return interaction.send(`Plate Number \`${args[0].value}\` not found.`); + } + + for (let i = 0; i < results.vehicles.length; i++) { + let plateResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setDescription('Plate Search Results') + .addFields( + { name: `**Plate #**`, value: `\`${results.vehicles[i].vehicle.plate}\``, inline: true }, + { name: `**Vin #**`, value: `\`${results.vehicles[i].vehicle.vin}\``, inline: true }, + { name: `**Model**`, value: `\`${results.vehicles[i].vehicle.model}\``, inline: true }, + { name: `**Color**`, value: `\`${results.vehicles[i].vehicle.color}\``, inline: true }, + { name: `**Owner**`, value: `\`${results.vehicles[i].vehicle.registeredOwner}\``, inline: true }, + ) + // Other details + let validRegistration = results.vehicles[i].vehicle.validRegistration; + let validInsurance = results.vehicles[i].vehicle.validInsurance; + let stolen = results.vehicles[i].vehicle.isStolen; + if (validRegistration=='1') plateResult.addFields({ name: `**Registration**`, value: `\`Valid\``, inline: true }); + if (validRegistration=='2') plateResult.addFields({ name: `**Registration**`, value: `\`InValid\``, inline: true }); + if (validInsurance=='1') plateResult.addFields({ name: `**Insurance**`, value: `\`Valid\``, inline: true }); + if (validInsurance=='2') plateResult.addFields({ name: `**Insurance**`, value: `\`InValid\``, inline: true }); + if (stolen=='1') plateResult.addFields({ name: `**Stolen**`, value: `\`No\``, inline: true }); + if (stolen=='2') plateResult.addFields({ name: `**Stolen**`, value: `\`Yes\``, inline: true }); + return interaction.send(plateResult); + } + } + socket.disconnect(); + }); + }, + }, +} \ No newline at end of file From d116ea9c8c60b3accf0bd15f7a1bb762d1eb87a7 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 20:29:12 -0800 Subject: [PATCH 08/29] update/add firearm search and use config.IconUrl --- commands/firearmSearch.js | 123 ++++++++++++++++++++++++++++++++++++++ commands/nameSearch.js | 4 +- commands/plateSearch.js | 4 +- 3 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 commands/firearmSearch.js diff --git a/commands/firearmSearch.js b/commands/firearmSearch.js new file mode 100644 index 0000000..99e68b7 --- /dev/null +++ b/commands/firearmSearch.js @@ -0,0 +1,123 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "firearmsearch", + description: "Search registered firearms", + usage: "[Serial #]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["firearm_search", "firearmdb", "firearm_db"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (args.length==0) return message.channel.send(`You are missing a \`Serial Number\`.`); + let data = { + user: user, + query: { + serialNumber: args[0], + activeCommunityID: user.user.activeCommunity + } + } + const socket = io.connect(client.config.socket); + socket.emit('bot_firearm_search', data); + socket.on('bot_firearm_search_results', results => { + if (results.user._id==user._id) { + if (results.firearms.length==0) { + return message.channel.send(`No Firearms found ${message.author}`); + } + + for (let i = 0; i < results.firearms.length; i++) { + let firearmResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.firearms[i].firearm.serialNumber} | ${results.firearms[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + .setDescription('Firearm Search Results') + .addFields( + { name: `**Serial Number**`, value: `\`${results.firearms[i].firearm.serialNumber}\``, inline: true }, + { name: `**Type**`, value: `\`${results.firearms[i].firearm.weaponType}\``, inline: true }, + { name: `**Owner**`, value: `\`${results.firearms[i].firearm.registeredOwner}\``, inline: true }, + ) + // Other details + let isStolen = results.firearms[i].firearm.isStolen; + if (isStolen=="false"||isStolen==false) firearmResult.addFields({name:`**Stolen**`,value:'\`No\`',inline: true}); + if (isStolen=="true"||isStolen==true) firearmResult.addFields({name:`**Stolen**`,value:'\`Yes\`',inline: true}); + message.channel.send(firearmResult); + } + } + socket.disconnect(); + }); + }, + SlashCommand: { + options: [ + { + name: "serialnumber", + description: "Firearms's serial number", + value: "serialnumber", + type: 3, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + let data = { + user: user, + query: { + serialNumber: args[0].value, + activeCommunityID: user.user.activeCommunity + } + } + const socket = io.connect(client.config.socket); + socket.emit('bot_firearm_search', data); + socket.on('bot_firearm_search_results', results => { + if (results.user._id==user._id) { + if (results.firearms.length==0) { + return interaction.send(`No Firearms found ${message.author}`); + } + + for (let i = 0; i < results.firearms.length; i++) { + let firearmResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.firearms[i].firearm.serialNumber} | ${results.firearms[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + .setDescription('Firearm Search Results') + .addFields( + { name: `**Serial Number**`, value: `\`${results.firearms[i].firearm.serialNumber}\``, inline: true }, + { name: `**Type**`, value: `\`${results.firearms[i].firearm.weaponType}\``, inline: true }, + { name: `**Owner**`, value: `\`${results.firearms[i].firearm.registeredOwner}\``, inline: true }, + ) + // Other details + let isStolen = results.firearms[i].firearm.isStolen; + if (isStolen=="false"||isStolen==false) firearmResult.addFields({name:`**Stolen**`,value:'\`No\`',inline: true}); + if (isStolen=="true"||isStolen==true) firearmResult.addFields({name:`**Stolen**`,value:'\`Yes\`',inline: true}); + interaction.send(firearmResult); + } + } + socket.disconnect(); + }); + }, + }, +} \ No newline at end of file diff --git a/commands/nameSearch.js b/commands/nameSearch.js index 21dc2f8..4762ae7 100644 --- a/commands/nameSearch.js +++ b/commands/nameSearch.js @@ -65,7 +65,7 @@ module.exports = { .setColor('#0099ff') .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') .setDescription('Name Search Results') .addFields( { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, @@ -183,7 +183,7 @@ module.exports = { .setColor('#0099ff') .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') .setDescription('Name Search Results') .addFields( { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, diff --git a/commands/plateSearch.js b/commands/plateSearch.js index f1ca76b..067391a 100644 --- a/commands/plateSearch.js +++ b/commands/plateSearch.js @@ -42,7 +42,7 @@ module.exports = { .setColor('#0099ff') .setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`) .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') .setDescription('Plate Search Results') .addFields( { name: `**Plate #**`, value: `\`${results.vehicles[i].vehicle.plate}\``, inline: true }, @@ -112,7 +112,7 @@ module.exports = { .setColor('#0099ff') .setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`) .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') .setDescription('Plate Search Results') .addFields( { name: `**Plate #**`, value: `\`${results.vehicles[i].vehicle.plate}\``, inline: true }, From cb22a8fe801b06d53821fb2cdd770fe45a6fc9bc Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 21:04:45 -0800 Subject: [PATCH 09/29] update/check status --- commands/checkStatus.js | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 commands/checkStatus.js diff --git a/commands/checkStatus.js b/commands/checkStatus.js new file mode 100644 index 0000000..68dc1a6 --- /dev/null +++ b/commands/checkStatus.js @@ -0,0 +1,79 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "checkstatus", + description: "Check your own or another officer status", + usage: "[user]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (user.user.activeCommunity == null) return message.channel.send(`You must join a community to use this command.`); + if (args.length == 0) { + return message.channel.send(`${message.author}'s status: \`${user.user.dispatchStatus}\` | Set by: \`${user.user.dispatchStatusSetBy}\``); + } else { + let targetUserID = args[0].replace('<@!', '').replace('>', ''); + let targetUser = await client.dbo.collection("users").findOne({"user.discord.id":targetUserID}).then(user => user); + // This lame line of code to get username without ping on discord + const User = client.users.cache.get(targetUserID); + console.log(targetUserID, targetUser); + if (!targetUser) return message.channel.send(`Cannot find **${args[0].value}** ${message.author}`); + if (targetUser.user.activeCommunity!=user.user.activeCommunity) { + return message.channel.send(`You are not in the same community as \`${User.tag}\` ${message.author}`); + } + return message.channel.send(`${message.author}, \`${User.tag}'s\` status: \`${targetUser.user.dispatchStatus}\` | Set by: \`${targetUser.user.dispatchStatusSetBy}\``); + } + }, + SlashCommand: { + options: [ + { + name: "user", + description: "Discord Username", + value: "user", + type: 6, + required: false, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + if (user.user.activeCommunity == null) return interaction.send(`You must join a community to use this command.`); + if (!client.exists(args)) { + return interaction.send(`<@${interaction.member.user.id}>'s status: \`${user.user.dispatchStatus}\` | Set by: \`${user.user.dispatchStatusSetBy}\``); + } else { + let targetUserID = args[0].value.replace('<@!', '').replace('>', ''); + let targetUser = await client.dbo.collection("users").findOne({"user.discord.id":targetUserID}).then(user => user); + // This lame line of code to get username without ping on discord + const User = client.users.cache.get(targetUserID); + console.debug(targetUserID, targetUser, User); + if (!targetUser) return message.channel.send(`Cannot find **${args[0].value}** <@${interaction.member.user.id}>`); + if (targetUser.user.activeCommunity!=user.user.activeCommunity) { + return interaction.send(`You are not in the same community as \`${User.tag}\` <@${interaction.member.user.id}>`); + } + return interaction.send(`<@${interaction.member.user.id}>, \`${User.tag}'s\` status: \`${targetUser.user.dispatchStatus}\` | Set by: \`${targetUser.user.dispatchStatusSetBy}\``); + } + }, + }, +} \ No newline at end of file From 76467288f5b5f64203f9b8814ca58e3641f64a76 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 9 Mar 2022 13:04:39 -0800 Subject: [PATCH 10/29] update/add update status --- commands/updateStatus.js | 113 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 commands/updateStatus.js diff --git a/commands/updateStatus.js b/commands/updateStatus.js new file mode 100644 index 0000000..0fd49e4 --- /dev/null +++ b/commands/updateStatus.js @@ -0,0 +1,113 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "updatestatus", + description: "Change User status", + usage: "[status]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["update_status"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', 'Panic', '10-41', '10-42']; + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in ${message.author}`); + if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); + if (args.length==0) return message.channel.send(`You must provide a new status.`); + if (!validStatus.includes(args[0])) return message.channel.send(`\`${args[0]}\` is a Invalid Status.`); + let onDuty=null; + let updateDuty=false; + let status = args[0] + if (args[0]=='10-41') { + onDuty=true; + updateDuty=true; + status='Online'; + } + if (args[0]=='10-42') { + onDuty=false; + updateDuty=true; + status='Offline'; + } + let req={ + userID: user._id, + status: status, + setBy: 'Self', + onDuty: onDuty, + updateDuty: updateDuty + }; + const socket = io.connect(client.config.socket); + socket.emit('bot_update_status', req); + socket.on('bot_updated_status', (res) => { + message.channel.send(`Succesfully updated status to \`${args[0]}\` ${message.author}`); + socket.disconnect(); + }); + }, + SlashCommand: { + options: [ + { + name: "status", + description: "New Status Value", + value: "status", + type: 3, + required: true, + choices: [ + { name: '10-8 (In Service)', value: '10-8', }, { name: '10-7 (Out of Service)', value: '10-7', }, { name: '10-6 (Busy)', value: '10-6', }, + { name: '10-11 (Traffic Stop)', value: '10-11', }, { name: '10-23 (Arrive on Scene', value: '10-23', }, { name: '10-97 (In Route)', value: '10-97' }, + { name: '10-15 (Subject in Custody)', value: '10-15', }, { name: '10-70 (Foot Pursuit)', value: '10-70', }, { name: '10-80 (Vehicle Pursuit)', value: '10-80' }, + { name: 'Panic', value: 'Panic', }, { name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' }, + ], + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in ${message.author}`); + if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); + let onDuty=null; + let updateDuty=false; + let status = args[0].value; + if (args[0].value=='10-41') { + onDuty=true; + updateDuty=true; + status='Online'; + } + if (args[0].value=='10-42') { + onDuty=false; + updateDuty=true; + status='Offline'; + } + let req={ + userID: user._id, + status: status, + setBy: 'Self', + onDuty: onDuty, + updateDuty: updateDuty + }; + const socket = io.connect(client.config.socket); + socket.emit('bot_update_status', req); + socket.on('bot_updated_status', (res) => { + interaction.send(`Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\``); + socket.disconnect(); + }); + }, + }, +} \ No newline at end of file From 441bb0672c23ad9ca562b57de8b9ab5aea2fe03c Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 9 Mar 2022 16:45:14 -0800 Subject: [PATCH 11/29] update/add panic control --- commands/panic.js | 118 ++++++++++++++++++++++++++++++++ commands/updateStatus.js | 4 +- events/message.js | 2 +- structures/LinesPoliceCadBot.js | 36 ++++++++++ 4 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 commands/panic.js diff --git a/commands/panic.js b/commands/panic.js new file mode 100644 index 0000000..a269811 --- /dev/null +++ b/commands/panic.js @@ -0,0 +1,118 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "panic", + description: "Enables users panic button", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["enablepanic"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); + const socket = io.connect(client.config.socket); + // If panic is enabled, disable panic + if (user.user.dispatchStatus=='Panic') { + let myReq = { + userID: user._id, + communityID: user.user.activeCommunity + }; + socket.emit('clear_panic', myReq); + + let myUpdateReq = { + userID: user._id, + status: '10-8', + setBy: 'System', + onDuty: null, + updateDuty: false + }; + socket.emit('bot_update_status', myUpdateReq); + socket.on('bot_updated_status', (res) => { + message.channel.send(`Disabled Panic ${message.author} and set status to \`10-8\`.`); + socket.disconnect(); + }); + return; + + // If panic is disabled, enable panic + } else { + client.forceUpdateStatus(message.channel, message.author.id, 'Panic'); + + let req = { + userID: user._id, + userUsername: user.user.username, + activeCommunity: user.user.activeCommunity + } + socket.emit('panic_button_update', req); + socket.disconnect(); + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); + if (guild.server.pingOnPanic) return message.channel.send(`Attention <@&${guild.server.pingRole}>! \`${user.user.username}\` has activated panic`); + return; + } + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + if (user.user.activeCommunity==null) return interaction.send(`You must join a community to use this command.`); + const socket = io.connect(client.config.socket); + // If panic is enabled, disable panic + if (user.user.dispatchStatus=='Panic') { + let myReq = { + userID: user._id, + communityID: user.user.activeCommunity + }; + socket.emit('clear_panic', myReq); + + let myUpdateReq = { + userID: user._id, + status: '10-8', + setBy: 'System', + onDuty: null, + updateDuty: false + }; + socket.emit('bot_update_status', myUpdateReq); + socket.on('bot_updated_status', (res) => { + interaction.send(`Disabled Panic <@${interaction.member.user.id}> and set status to \`10-8\`.`); + socket.disconnect(); + }); + return; + // If panic is disabled, enable panic + } else { + client.forceUpdateStatus(interaction, interaction.member.user.id, 'Panic'); + + let req = { + userID: user._id, + userUsername: user.user.username, + activeCommunity: user.user.activeCommunity + } + socket.emit('panic_button_update', req); + socket.disconnect(); + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":GuildDB.serverID}).then(guild => guild); + if (guild.server.pingOnPanic) return message.channel.send(`Attention <@&${guild.server.pingRole}>! \`${user.user.username}\` has activated panic`); + return; + } + }, + }, +} \ No newline at end of file diff --git a/commands/updateStatus.js b/commands/updateStatus.js index 0fd49e4..0b0f253 100644 --- a/commands/updateStatus.js +++ b/commands/updateStatus.js @@ -18,7 +18,7 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args) => { - let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', 'Panic', '10-41', '10-42']; + let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', '10-41', '10-42']; let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in ${message.author}`); if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); @@ -63,7 +63,7 @@ module.exports = { { name: '10-8 (In Service)', value: '10-8', }, { name: '10-7 (Out of Service)', value: '10-7', }, { name: '10-6 (Busy)', value: '10-6', }, { name: '10-11 (Traffic Stop)', value: '10-11', }, { name: '10-23 (Arrive on Scene', value: '10-23', }, { name: '10-97 (In Route)', value: '10-97' }, { name: '10-15 (Subject in Custody)', value: '10-15', }, { name: '10-70 (Foot Pursuit)', value: '10-70', }, { name: '10-80 (Vehicle Pursuit)', value: '10-80' }, - { name: 'Panic', value: 'Panic', }, { name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' }, + { name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' }, ], }, ], diff --git a/events/message.js b/events/message.js index 44a2b5b..5cc91af 100644 --- a/events/message.js +++ b/events/message.js @@ -56,7 +56,7 @@ module.exports = async (client, message) => { return client.sendError( message.channel, "Missing Permissions!" + GuildDB.DJ - ? " You need the `DJ` role to access this command." + ? " You need the correct role to access this command." : "" ); cmd.run(client, message, args, { GuildDB }); diff --git a/structures/LinesPoliceCadBot.js b/structures/LinesPoliceCadBot.js index a8fe82d..77da8ca 100644 --- a/structures/LinesPoliceCadBot.js +++ b/structures/LinesPoliceCadBot.js @@ -2,6 +2,7 @@ const { Collection, Client, MessageEmbed } = require('discord.js'); const CommandHandler = require('../commands').Commands; const MongoClient = require('mongodb').MongoClient; const Logger = require("../util/Logger"); +const io = require('socket.io-client'); const path = require("path"); const fs = require('fs'); @@ -75,6 +76,41 @@ class LinesPoliceCadBot extends Client { this.log('Successfully connected to mongoDB'); } + // This is for the 'panic' command when enabling panic + // May be used by other interaction + async forceUpdateStatus(sendObject, userID, status) { + let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', '10-41', '10-42', 'Panic']; + let user = await this.dbo.collection("users").findOne({"user.discord.id":userID}).then(user => user); + if (!user) return returnMessage(`You are not logged in <@${userID}>`); + if (user.user.activeCommunity==null) return returnMessage(`You must join a community to use this command.`); + if (!validStatus.includes(status)) return returnMessage(`\`${status}\` is a Invalid Status.`); + let onDuty=null; + let updateDuty=false; + if (status=='10-41') { + onDuty=true; + updateDuty=true; + status='Online'; + } + if (status=='10-42') { + onDuty=false; + updateDuty=true; + status='Offline'; + } + let req={ + userID: user._id, + status: status, + setBy: 'Self', + onDuty: onDuty, + updateDuty: updateDuty + }; + const socket = io.connect(this.config.socket); + socket.emit('bot_update_status', req); + socket.on('bot_updated_status', (res) => { + sendObject.send(`Succesfully updated status to \`${status}\` <@${userID}>`); + socket.disconnect(); + }); + } + exists(n){return null!=n&&null!=n&&""!=n} LoadCommands() { From 495c4755ae646ce2e83eb4fbadd2a3e85f586ee8 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 17:58:54 -0700 Subject: [PATCH 12/29] update/update license --- commands/firearmSearch.js | 2 +- commands/help.js | 7 +- commands/nameSearch.js | 5 +- commands/plateSearch.js | 2 +- commands/stats.js | 6 +- commands/updateLicense.js | 237 +++++++++++++++ config/beta-config.js | 2 +- config/config.js | 2 +- events/{message.js => messageCreate.js} | 10 +- package-lock.json | 381 +++++++++++++++++------- package.json | 2 +- structures/LinesPoliceCadBot.js | 19 +- 12 files changed, 532 insertions(+), 143 deletions(-) create mode 100644 commands/updateLicense.js rename events/{message.js => messageCreate.js} (86%) diff --git a/commands/firearmSearch.js b/commands/firearmSearch.js index 99e68b7..df5a5bf 100644 --- a/commands/firearmSearch.js +++ b/commands/firearmSearch.js @@ -52,7 +52,7 @@ module.exports = { let isStolen = results.firearms[i].firearm.isStolen; if (isStolen=="false"||isStolen==false) firearmResult.addFields({name:`**Stolen**`,value:'\`No\`',inline: true}); if (isStolen=="true"||isStolen==true) firearmResult.addFields({name:`**Stolen**`,value:'\`Yes\`',inline: true}); - message.channel.send(firearmResult); + message.channel.send({ embeds: [firearmResult] }); } } socket.disconnect(); diff --git a/commands/help.js b/commands/help.js index 3c057f5..e56afda 100644 --- a/commands/help.js +++ b/commands/help.js @@ -22,7 +22,6 @@ module.exports = { cmd.name }${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}` : null ); - let Embed = new MessageEmbed() .setAuthor( `Commands of ${client.user.username}`, @@ -36,7 +35,9 @@ module.exports = { ).setDescription(`${Commands.join("\n")} Lines Police CAD Bot Version: v${client.config.Version}`); - if (!args[0]) message.channel.send(Embed); + if (!args[0]) { + message.channel.send({ embeds: [Embed] }); + } else { let cmd = client.commands.get(args[0]) || @@ -74,7 +75,7 @@ module.exports = { }` ); - message.channel.send(embed); + message.channel.send({ embeds: [embed] }); } }, diff --git a/commands/nameSearch.js b/commands/nameSearch.js index 4762ae7..565950b 100644 --- a/commands/nameSearch.js +++ b/commands/nameSearch.js @@ -26,12 +26,11 @@ module.exports = { let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); - let data; if (args.length==0) return message.channel.send(`You must provide a \`First Name\`, \`Last Name\` and \`DOB\`(yyyy-mm-dd).`); if (args.length==1) return message.channel.send(`You're missing a \`Last Name\` and \`DOB\`(yyyy-mm-dd).`); if (args.length==2) return message.channel.send(`You're missing a \`DOB\`(yyyy-mm-dd).`); - data = { + let data = { user: user, query: { firstName: args[0], @@ -104,7 +103,7 @@ module.exports = { if (hairColor!=null&&hairColor!=undefined&&hairColor!='') nameResult.addFields({name:'**Hair Color**',value:`\`${hairColor}\``,inline:true}); nameResult.addFields({name:'**Organ Donor**',value:`\`${results.civilians[i].civilian.organDonor}\``,inline:true}); nameResult.addFields({name:'**Veteran**',value:`\`${results.civilians[i].civilian.veteran}\``,inline:true}); - message.channel.send(nameResult); + message.channel.send({ embeds: [nameResult] }); } } socket.disconnect(); diff --git a/commands/plateSearch.js b/commands/plateSearch.js index 067391a..129f478 100644 --- a/commands/plateSearch.js +++ b/commands/plateSearch.js @@ -61,7 +61,7 @@ module.exports = { if (validInsurance=='2') plateResult.addFields({ name: `**Insurance**`, value: `\`InValid\``, inline: true }); if (stolen=='1') plateResult.addFields({ name: `**Stolen**`, value: `\`No\``, inline: true }); if (stolen=='2') plateResult.addFields({ name: `**Stolen**`, value: `\`Yes\``, inline: true }); - message.channel.send(plateResult); + message.channel.send({ embeds: [plateResult] }); } } socket.disconnect(); diff --git a/commands/stats.js b/commands/stats.js index f1bab18..0ba4031 100644 --- a/commands/stats.js +++ b/commands/stats.js @@ -21,11 +21,11 @@ module.exports = { const stats = new MessageEmbed() .setColor('#0099ff') .setTitle("Current LPC-Bot Statistics") - .setURL('https://discord.gg/w2g2FFmHbF') + .setURL(client.config.SupportServer) .addField(" \u200B ", "**Channels** : ` " + `${client.channels.cache.size}` + " `") .addField(" \u200B ", "**Servers** : ` " + `${client.guilds.cache.size}` + " `") .addField(" \u200B ", "**Users** : ` " + `${client.users.cache.size}` + " `") - return message.channel.send(stats) + return message.channel.send({ embeds: [stats] }); }, SlashCommand: { /** @@ -43,7 +43,7 @@ module.exports = { const stats = new MessageEmbed() .setColor('#0099ff') .setTitle("Current LPC-Bot Statistics") - .setURL('https://discord.gg/w2g2FFmHbF') + .setURL(client.config.SupportServer) .addField(" \u200B ", "**Channels** : ` " + `${client.channels.cache.size}` + " `") .addField(" \u200B ", "**Servers** : ` " + `${client.guilds.cache.size}` + " `") .addField(" \u200B ", "**Users** : ` " + `${client.users.cache.size}` + " `") diff --git a/commands/updateLicense.js b/commands/updateLicense.js new file mode 100644 index 0000000..7bc683b --- /dev/null +++ b/commands/updateLicense.js @@ -0,0 +1,237 @@ +const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "updatelicense", + description: "Update Drivers License Status", + usage: "[firstName] [lastName] [DOB]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (args.length==0) return message.channel.send(`You must provide a \`First Name\`, \`Last Name\`, \`DOB\`(yyyy-mm-dd).`); + if (args.length==1) return message.channel.send(`You're missing a \`Last Name\` and \`DOB\`(yyyy-mm-dd).`); + if (args.length==2) return message.channel.send(`You're missing a \`DOB\`(yyyy-mm-dd).`); + + let data = { + user: user, + query: { + firstName: args[0], + lastName: args[1], + dateOfBirth: args[2], + activeCommunityID: user.user.activeCommunity + } + } + + const socket = io.connect(client.config.socket); + socket.emit("bot_name_search", data); + socket.on("bot_name_search_results", (results) => { + if (results.user._id==user._id) { + if (results.civilians.length == 0) { + return message.channel.send(`Name \`${args[0]} ${args[1]}\` not found.`); + } + } + + let nameResult; + let row; + for (let i = 0; i < results.civilians.length; i++) { + // Get Drivers Licence Status + let licenseStatus; + if (results.civilians[i].civilian.licenseStatus == 1) licenseStatus = 'Valid'; + if (results.civilians[i].civilian.licenseStatus == 2) licenseStatus = 'Revoked'; + if (results.civilians[i].civilian.licenseStatus == 3) licenseStatus = 'None'; + nameResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + .setDescription('Name Search Results') + .addFields( + { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, + { name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true }, + { name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true }, + { name: `**Drivers License**`, value: `\`${licenseStatus}\``, inline: true }, + { name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true } + ) + row = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`license-revoke-${results.civilians[i]._id}`) + .setLabel("Revoke") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`license-reinstate-${results.civilians[i]._id}`) + .setLabel("Reinstate") + .setStyle("SUCCESS") + ) + } + + message.channel.send({ embeds: [nameResult], components: [row] }); + + const filter = i => { + return i.user.id == message.author.id; + } + + const collector = message.channel.createMessageComponentCollector({ + filter, + max: 1, + time: 20000 + }); + + collector.on('collect', async ButtonInteraction => { + const socket = io.connect(client.config.socket); + + let queryString = ButtonInteraction.customId; + let query = { + _id: "", + status: null, + bot_request: true + }; + if (queryString.substr(8, 6)=='revoke') { + query.status = 2; + query._id = queryString.substr(15, 24); + } else if (queryString.substr(8, 9)=='reinstate') { + query.status = 1; + query._id = queryString.substr(18, 24); + } + socket.emit("update_drivers_license_status", query); + socket.on("bot_updated_drivers_license_status", (res) => { + if (!res.success) ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] }); + socket.disconnect(); + }); + return ButtonInteraction.update({ content: 'Successfully updated license.', embeds: [], components: [] }); + }); + }); + }, + SlashCommand: { + options: [ + { + name: "firstname", + description: "Civilian's First Name", + value: "firstname", + type: 3, + required: true, + }, + { + name: "lastname", + description: "Civilian's Last Name", + value: "lastname", + type: 3, + required: true, + }, + { + name: "dob", + description: "Civilian's DOB (yyyy-mm-dd)", + value: "dob", + type: 3, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + + let data = { + user: user, + query: { + firstName: args[0].value, + lastName: args[1].value, + dateOfBirth: args[2].value, + activeCommunityID: user.user.activeCommunity + } + } + + const socket = io.connect(client.config.socket); + socket.emit("bot_name_search", data); + socket.on("bot_name_search_results", (results) => { + if (results.user._id==user._id) { + if (results.civilians.length == 0) { + return interaction.send(`Name \`${args[0].value} ${args[1].value}\` not found.`); + } + } + + let nameResult; + let row; + for (let i = 0; i < results.civilians.length; i++) { + // Get Drivers Licence Status + let licenseStatus; + if (results.civilians[i].civilian.licenseStatus == 1) licenseStatus = 'Valid'; + if (results.civilians[i].civilian.licenseStatus == 2) licenseStatus = 'Revoked'; + if (results.civilians[i].civilian.licenseStatus == 3) licenseStatus = 'None'; + nameResult = new MessageEmbed() + .setColor('#0099ff') + .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) + .setURL('https://discord.gg/jgUW656v2t') + .setAuthor('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + .setDescription('Name Search Results') + .addFields( + { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, + { name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true }, + { name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true }, + { name: `**Drivers License**`, value: `\`${licenseStatus}\``, inline: true }, + { name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true } + ) + row = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`license-revoke-${results.civilians[i]._id}`) + .setLabel("Revoke") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`license-reinstate-${results.civilians[i]._id}`) + .setLabel("Reinstate") + .setStyle("SUCCESS") + ) + } + + interaction.send({ embeds: [nameResult], components: [row] }); + + client.on("interactionCreate", ButtonInteraction => { + const socket = io.connect(client.config.socket); + + let queryString = ButtonInteraction.customId; + let query = { + _id: "", + status: null, + bot_request: true + }; + if (queryString.substr(8, 6)=='revoke') { + query.status = 2; + query._id = queryString.substr(15, 24); + } else if (queryString.substr(8, 9)=='reinstate') { + query.status = 1; + query._id = queryString.substr(18, 24); + } + socket.emit("update_drivers_license_status", query); + socket.on("bot_updated_drivers_license_status", (res) => { + if (!res.success) ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] }); + socket.disconnect(); + }); + return ButtonInteraction.update({ content: 'Successfully updated license.', embeds: [], components: [] }); + }); + }); + }, + }, +} \ No newline at end of file diff --git a/config/beta-config.js b/config/beta-config.js index 2761ab8..736fb5c 100644 --- a/config/beta-config.js +++ b/config/beta-config.js @@ -4,7 +4,7 @@ module.exports = { Admins: ["362791661274660874"], // Admins of the bot defaultPrefix: "?", socket: "https://police-cad-dev.herokuapp.com/", - SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link + SupportServer: client.config.SupportServer, //Support Server Link Token: process.env.TOKEN || "", //Discord Bot Token Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png", diff --git a/config/config.js b/config/config.js index 4f2389e..aba7568 100644 --- a/config/config.js +++ b/config/config.js @@ -4,7 +4,7 @@ module.exports = { Admins: ["362791661274660874"], // Admins of the bot defaultPrefix: "?", socket: "https://www.linespolice-cad.com/", - SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link + SupportServer: client.config.SupportServer, //Support Server Link Token: process.env.TOKEN || "", //Discord Bot Token Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png", diff --git a/events/message.js b/events/messageCreate.js similarity index 86% rename from events/message.js rename to events/messageCreate.js index 5cc91af..0023858 100644 --- a/events/message.js +++ b/events/messageCreate.js @@ -1,7 +1,7 @@ /** * * @param {require("../structures/LinesPoliceCadBot")} client - * @param {require("discord.js").Message} message + * @param {require("discord.js").message} message * @returns {void} or nothing if you didn't know */ @@ -45,13 +45,7 @@ module.exports = async (client, message) => { cmd.permissions.member && !message.channel .permissionsFor(message.member) - .has(cmd.permissions.member)) || - (cmd.permissions && - GuildDB.DJ && - !message.channel - .permissionsFor(message.member) - .has(["ADMINISTRATOR"]) && - !message.member.roles.cache.has(GuildDB.DJ)) + .has(cmd.permissions.member)) ) return client.sendError( message.channel, diff --git a/package-lock.json b/package-lock.json index cabbbe4..78d8644 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "colors": "^1.4.0", - "discord.js": "^12.5.3", + "discord.js": "^13.1.0", "express": "^4.17.1", "moment-duration-format": "^2.3.2", "mongodb": "^3.6.8", @@ -38,10 +38,41 @@ "kuler": "^2.0.0" } }, + "node_modules/@discordjs/builders": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.5.0.tgz", + "integrity": "sha512-HP5y4Rqw68o61Qv4qM5tVmDbWi4mdTFftqIOGRo33SNPpLJ1Ga3KEIR2ibKofkmsoQhEpLmopD1AZDs3cKpHuw==", + "dependencies": { + "@sindresorhus/is": "^4.0.1", + "discord-api-types": "^0.22.0", + "ow": "^0.27.0", + "ts-mixer": "^6.0.0", + "tslib": "^2.3.0" + }, + "engines": { + "node": ">=14.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@discordjs/builders/node_modules/@sindresorhus/is": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", + "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, "node_modules/@discordjs/collection": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz", - "integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==" + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.2.4.tgz", + "integrity": "sha512-PVrEJH+V6Ob0OwfagYQ/57kwt/HNEJxt5jqY4P+S3st9y29t9iokdnGMQoJXG5VEMAQIPbzu9Snw1F6yE8PdLA==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } }, "node_modules/@discordjs/form-data": { "version": "3.0.1", @@ -56,6 +87,15 @@ "node": ">= 6" } }, + "node_modules/@sapphire/async-queue": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.0.tgz", + "integrity": "sha512-z+CDw5X4UgIEpZL8KM+ThVx1i8V60HBg0l/oFewTNbQQeRDJHdVxHyJykv+SF1H+Rc8EkMS81VTWo95jVYgO/g==", + "engines": { + "node": ">=v14.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -80,22 +120,24 @@ "resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.10.tgz", "integrity": "sha512-bsjleuRKWmGqajMerkzox19aGbscQX5rmmvvXl3wlIp5gMG1HgkiwPxsN5p070fBDKTNSPgojVbuY1+HWMbFhg==" }, + "node_modules/@types/node": { + "version": "17.0.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", + "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" + }, + "node_modules/@types/ws": { + "version": "7.4.7", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", + "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, "node_modules/accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -337,6 +379,14 @@ "node": ">=8" } }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/camelcase": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", @@ -630,23 +680,32 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "node_modules/discord-api-types": { + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.22.0.tgz", + "integrity": "sha512-l8yD/2zRbZItUQpy7ZxBJwaLX/Bs2TGaCthRppk8Sw24LOIWg12t9JEreezPoYD0SQcC2htNNo27kYEpYW/Srg==", + "deprecated": "No longer supported. Install the latest release!", + "engines": { + "node": ">=12" + } + }, "node_modules/discord.js": { - "version": "12.5.3", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz", - "integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==", - "deprecated": "no longer supported", + "version": "13.1.0", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.1.0.tgz", + "integrity": "sha512-gxO4CXKdHpqA+WKG+f5RNnd3srTDj5uFJHgOathksDE90YNq/Qijkd2WlMgTTMS6AJoEnHxI7G9eDQHCuZ+xDA==", "dependencies": { - "@discordjs/collection": "^0.1.6", + "@discordjs/builders": "^0.5.0", + "@discordjs/collection": "^0.2.1", "@discordjs/form-data": "^3.0.1", - "abort-controller": "^3.0.0", + "@sapphire/async-queue": "^1.1.4", + "@types/ws": "^7.4.7", + "discord-api-types": "^0.22.0", "node-fetch": "^2.6.1", - "prism-media": "^1.2.9", - "setimmediate": "^1.0.5", - "tweetnacl": "^1.0.3", - "ws": "^7.4.4" + "ws": "^7.5.1" }, "engines": { - "node": ">=12.0.0" + "node": ">=16.6.0", + "npm": ">=7.0.0" } }, "node_modules/dot-prop": { @@ -785,14 +844,6 @@ "node": ">= 0.6" } }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "engines": { - "node": ">=6" - } - }, "node_modules/express": { "version": "4.17.1", "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", @@ -1259,6 +1310,11 @@ "node": ">=8" } }, + "node_modules/lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + }, "node_modules/logform": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/logform/-/logform-2.4.0.tgz", @@ -1561,6 +1617,61 @@ "node": ">=4" } }, + "node_modules/ow": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/ow/-/ow-0.27.0.tgz", + "integrity": "sha512-SGnrGUbhn4VaUGdU0EJLMwZWSupPmF46hnTRII7aCLCrqixTAC5eKo8kI4/XXf1eaaI8YEVT+3FeGNJI9himAQ==", + "dependencies": { + "@sindresorhus/is": "^4.0.1", + "callsites": "^3.1.0", + "dot-prop": "^6.0.1", + "lodash.isequal": "^4.5.0", + "type-fest": "^1.2.1", + "vali-date": "^1.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ow/node_modules/@sindresorhus/is": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", + "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, + "node_modules/ow/node_modules/dot-prop": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", + "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "dependencies": { + "is-obj": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ow/node_modules/type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-cancelable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", @@ -1633,31 +1744,6 @@ "node": ">=4" } }, - "node_modules/prism-media": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.1.tgz", - "integrity": "sha512-nyYAa3KB4qteJIqdguKmwxTJgy55xxUtkJ3uRnOvO5jO+frci+9zpRXw6QZVcfDeva3S654fU9+26P2OSTzjHw==", - "peerDependencies": { - "@discordjs/opus": "^0.5.0", - "ffmpeg-static": "^4.2.7 || ^3.0.0 || ^2.4.0", - "node-opus": "^0.3.3", - "opusscript": "^0.0.8" - }, - "peerDependenciesMeta": { - "@discordjs/opus": { - "optional": true - }, - "ffmpeg-static": { - "optional": true - }, - "node-opus": { - "optional": true - }, - "opusscript": { - "optional": true - } - } - }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -1955,11 +2041,6 @@ "node": ">= 0.8.0" } }, - "node_modules/setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" - }, "node_modules/setprototypeof": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", @@ -2184,10 +2265,15 @@ "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, - "node_modules/tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "node_modules/ts-mixer": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.0.tgz", + "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" + }, + "node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" }, "node_modules/type-fest": { "version": "0.20.2", @@ -2309,6 +2395,14 @@ "node": ">= 0.4.0" } }, + "node_modules/vali-date": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz", + "integrity": "sha1-G5BKWWCfsyjvB4E4Qgk09rhnCaY=", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -2488,10 +2582,29 @@ "kuler": "^2.0.0" } }, + "@discordjs/builders": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.5.0.tgz", + "integrity": "sha512-HP5y4Rqw68o61Qv4qM5tVmDbWi4mdTFftqIOGRo33SNPpLJ1Ga3KEIR2ibKofkmsoQhEpLmopD1AZDs3cKpHuw==", + "requires": { + "@sindresorhus/is": "^4.0.1", + "discord-api-types": "^0.22.0", + "ow": "^0.27.0", + "ts-mixer": "^6.0.0", + "tslib": "^2.3.0" + }, + "dependencies": { + "@sindresorhus/is": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", + "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==" + } + } + }, "@discordjs/collection": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz", - "integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==" + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.2.4.tgz", + "integrity": "sha512-PVrEJH+V6Ob0OwfagYQ/57kwt/HNEJxt5jqY4P+S3st9y29t9iokdnGMQoJXG5VEMAQIPbzu9Snw1F6yE8PdLA==" }, "@discordjs/form-data": { "version": "3.0.1", @@ -2503,6 +2616,11 @@ "mime-types": "^2.1.12" } }, + "@sapphire/async-queue": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.3.0.tgz", + "integrity": "sha512-z+CDw5X4UgIEpZL8KM+ThVx1i8V60HBg0l/oFewTNbQQeRDJHdVxHyJykv+SF1H+Rc8EkMS81VTWo95jVYgO/g==" + }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -2521,19 +2639,24 @@ "resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.10.tgz", "integrity": "sha512-bsjleuRKWmGqajMerkzox19aGbscQX5rmmvvXl3wlIp5gMG1HgkiwPxsN5p070fBDKTNSPgojVbuY1+HWMbFhg==" }, + "@types/node": { + "version": "17.0.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", + "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" + }, + "@types/ws": { + "version": "7.4.7", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", + "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", + "requires": { + "@types/node": "*" + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, - "abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "requires": { - "event-target-shim": "^5.0.0" - } - }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -2725,6 +2848,11 @@ } } }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" + }, "camelcase": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", @@ -2959,19 +3087,24 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "discord-api-types": { + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.22.0.tgz", + "integrity": "sha512-l8yD/2zRbZItUQpy7ZxBJwaLX/Bs2TGaCthRppk8Sw24LOIWg12t9JEreezPoYD0SQcC2htNNo27kYEpYW/Srg==" + }, "discord.js": { - "version": "12.5.3", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz", - "integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==", + "version": "13.1.0", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.1.0.tgz", + "integrity": "sha512-gxO4CXKdHpqA+WKG+f5RNnd3srTDj5uFJHgOathksDE90YNq/Qijkd2WlMgTTMS6AJoEnHxI7G9eDQHCuZ+xDA==", "requires": { - "@discordjs/collection": "^0.1.6", + "@discordjs/builders": "^0.5.0", + "@discordjs/collection": "^0.2.1", "@discordjs/form-data": "^3.0.1", - "abort-controller": "^3.0.0", + "@sapphire/async-queue": "^1.1.4", + "@types/ws": "^7.4.7", + "discord-api-types": "^0.22.0", "node-fetch": "^2.6.1", - "prism-media": "^1.2.9", - "setimmediate": "^1.0.5", - "tweetnacl": "^1.0.3", - "ws": "^7.4.4" + "ws": "^7.5.1" } }, "dot-prop": { @@ -3075,11 +3208,6 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, - "event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" - }, "express": { "version": "4.17.1", "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", @@ -3443,6 +3571,11 @@ "package-json": "^6.3.0" } }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + }, "logform": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/logform/-/logform-2.4.0.tgz", @@ -3640,6 +3773,39 @@ "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.0.3.tgz", "integrity": "sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==" }, + "ow": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/ow/-/ow-0.27.0.tgz", + "integrity": "sha512-SGnrGUbhn4VaUGdU0EJLMwZWSupPmF46hnTRII7aCLCrqixTAC5eKo8kI4/XXf1eaaI8YEVT+3FeGNJI9himAQ==", + "requires": { + "@sindresorhus/is": "^4.0.1", + "callsites": "^3.1.0", + "dot-prop": "^6.0.1", + "lodash.isequal": "^4.5.0", + "type-fest": "^1.2.1", + "vali-date": "^1.0.0" + }, + "dependencies": { + "@sindresorhus/is": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", + "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==" + }, + "dot-prop": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", + "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "requires": { + "is-obj": "^2.0.0" + } + }, + "type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==" + } + } + }, "p-cancelable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", @@ -3693,12 +3859,6 @@ "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=" }, - "prism-media": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.1.tgz", - "integrity": "sha512-nyYAa3KB4qteJIqdguKmwxTJgy55xxUtkJ3uRnOvO5jO+frci+9zpRXw6QZVcfDeva3S654fU9+26P2OSTzjHw==", - "requires": {} - }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -3938,11 +4098,6 @@ "send": "0.17.1" } }, - "setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" - }, "setprototypeof": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", @@ -4121,10 +4276,15 @@ "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, - "tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "ts-mixer": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.0.tgz", + "integrity": "sha512-nXIb1fvdY5CBSrDIblLn73NW0qRDk5yJ0Sk1qPBF560OdJfQp9jhl+0tzcY09OZ9U+6GpeoI9RjwoIKFIoB9MQ==" + }, + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" }, "type-fest": { "version": "0.20.2", @@ -4215,6 +4375,11 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, + "vali-date": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz", + "integrity": "sha1-G5BKWWCfsyjvB4E4Qgk09rhnCaY=" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index ad2f4af..07b3be5 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "license": "ISC", "dependencies": { "colors": "^1.4.0", - "discord.js": "^12.5.3", + "discord.js": "^13.1.0", "express": "^4.17.1", "moment-duration-format": "^2.3.2", "mongodb": "^3.6.8", diff --git a/structures/LinesPoliceCadBot.js b/structures/LinesPoliceCadBot.js index 77da8ca..b365d6f 100644 --- a/structures/LinesPoliceCadBot.js +++ b/structures/LinesPoliceCadBot.js @@ -8,8 +8,8 @@ const fs = require('fs'); class LinesPoliceCadBot extends Client { - constructor(config) { - super() + constructor(options, config) { + super(options) this.config = config; this.commands = new Collection(); @@ -32,14 +32,8 @@ class LinesPoliceCadBot extends Client { client.log("Interaction") let GuildDB = await this.GetGuild(interaction.guild_id); - //Initialize GuildDB - if (!GuildDB) { - await this.database.guild.set(interaction.guild_id, { - prefix: this.config.DefaultPrefix, - DJ: null, - }); - GuildDB = await this.GetGuild(interaction.guild_id); - } + if (interaction.type==3) return; + const command = interaction.data.name.toLowerCase(); const args = interaction.data.options; @@ -61,7 +55,6 @@ class LinesPoliceCadBot extends Client { }, }); }; - let cmd = client.commands.get(command); if (cmd.SlashCommand && cmd.SlashCommand.run) cmd.SlashCommand.run(this, interaction, args, { GuildDB }); @@ -277,7 +270,7 @@ class LinesPoliceCadBot extends Client { // const help = new MessageEmbed() // .setColor('#0099ff') // .setTitle('**Commands:**') - // .setURL('https://discord.gg/w2g2FFmHbF') + // .setURL(client.config.SupportServer) // .setAuthor('LPS Website & Bot Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') // .setDescription('Lines Police CAD Bot Commands') // .addFields({ @@ -334,7 +327,7 @@ class LinesPoliceCadBot extends Client { // const stats = new MessageEmbed() // .setColor('#0099ff') // .setTitle("Current LPC-Bot Statistics") - // .setURL('https://discord.gg/w2g2FFmHbF') + // .setURL(client.config.SupportServer) // .addField(" \u200B ", "**Channels** : ` " + `${client.channels.cache.size}` + " `") // .addField(" \u200B ", "**Servers** : ` " + `${client.guilds.cache.size}` + " `") // .addField(" \u200B ", "**Users** : ` " + `${client.users.cache.size}` + " `") From 5242344db388282d7479a885becf33445e6bc0be Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 18:19:50 -0700 Subject: [PATCH 13/29] update/join community --- commands/joinCommunity.js | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 commands/joinCommunity.js diff --git a/commands/joinCommunity.js b/commands/joinCommunity.js new file mode 100644 index 0000000..5100ac7 --- /dev/null +++ b/commands/joinCommunity.js @@ -0,0 +1,77 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "joincommunity", + description: "Join a community", + usage: "[code]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["join"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (args.length==0) return message.channel.send(`You must provide a \`Community Code\`.`); + let myReq = { + userID: user._id, + communityCode: args[0] + }; + const socket = io.connect(client.config.socket); + socket.emit('bot_join_community', myReq); + socket.on('bot_joined_community', (data) => { + socket.disconnect() + if (data.error) { + return message.channel.send(`${data.error}`); + } + return message.channel.send(`Successfully joined the community \` ${data.commName} \``) + }); + }, + SlashCommand: { + options: [ + { + name: "code", + description: "Join community with community code", + value: "code", + type: 3, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + let myReq = { + userID: user._id, + communityCode: args[0].value + }; + const socket = io.connect(client.config.socket); + socket.emit('bot_join_community', myReq); + socket.on('bot_joined_community', (data) => { + socket.disconnect() + if (data.error) { + return interaction.send(`${data.error}`); + } + return interaction.send(`Successfully joined the community \` ${data.commName} \``) + }); + }, + }, +} \ No newline at end of file From a8f4785478bbe431fe7f904ea0c749d272e4d8b1 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 18:24:08 -0700 Subject: [PATCH 14/29] update/leave community --- commands/leaveCommunity.js | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 commands/leaveCommunity.js diff --git a/commands/leaveCommunity.js b/commands/leaveCommunity.js new file mode 100644 index 0000000..17bfd14 --- /dev/null +++ b/commands/leaveCommunity.js @@ -0,0 +1,66 @@ +const { MessageEmbed } = require('discord.js'); +const io = require('socket.io-client'); + +module.exports = { + name: "leavecommunity", + description: "Leave your active community", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: ["leave"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + let myReq = { + userID: user._id + }; + const socket = io.connect(client.config.socket); + socket.emit('bot_leave_community', myReq); + socket.on('bot_left_community', (data) => { + socket.disconnect() + if (data.error) { + return message.channel.send(`${data.error}`); + } + return message.channel.send(`${data.message}`); + }); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + let myReq = { + userID: user._id + }; + const socket = io.connect(client.config.socket); + socket.emit('bot_leave_community', myReq); + socket.on('bot_left_community', (data) => { + socket.disconnect() + if (data.error) { + return interaction.send(`${data.error}`); + } + return interaction.send(`${data.message}`); + }); + }, + }, +} \ No newline at end of file From ee23d59a440434fbecd27c3ee43a5397925fa9fe Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 18:27:16 -0700 Subject: [PATCH 15/29] update/community --- commands/community.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 commands/community.js diff --git a/commands/community.js b/commands/community.js new file mode 100644 index 0000000..a2c2456 --- /dev/null +++ b/commands/community.js @@ -0,0 +1,49 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "community", + description: "Check active community", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); + if (!user) return message.channel.send(`You are not logged in.`); + if (user.user.activeCommunity==null) return message.channel.send(`You are not in a community.`); + let community = await client.dbo.collection("communities").findOne({_id:ObjectId(user.user.activeCommunity)}).then(community => community); + if (!community) return message.channel.send(`Community not found.`); + return message.channel.send(`You are in the community \`${community.community.name}\``); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user); + if (!user) return interaction.send(`You are not logged in.`); + if (user.user.activeCommunity==null) return message.channel.send(`You are not in a community.`); + let community = await client.dbo.collection("communities").findOne({_id:ObjectId(user.user.activeCommunity)}).then(community => community); + if (!community) return interaction.send(`Community not found.`); + return interaction.send(`You are in the community \`${community.community.name}\``); + }, + }, +} \ No newline at end of file From dcbaf23828f17e9a08cfba8112ef0d461a9ea68d Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 19:07:46 -0700 Subject: [PATCH 16/29] update/set role --- commands/setRole.js | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 commands/setRole.js diff --git a/commands/setRole.js b/commands/setRole.js new file mode 100644 index 0000000..53602ba --- /dev/null +++ b/commands/setRole.js @@ -0,0 +1,70 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "setrole", + description: "Add a role allowed to use the bot", + usage: "[role]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + aliases: ["set_role", "addrole", "add_role"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + if (args.length==0) return message.channel.send(`You must provide a role.`); + let roleid = args[0].replace('<@&', '').replace('>', ''); + let role = message.guild.roles.cache.find(x => x.id == roleid); + if (role == undefined) { + return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`); + } else { + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); + if (guild.server.allowedRole!=undefined&&guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} has already been added.`); + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully added ${args[0]} to allowed roles.`); + }); + } + }, + SlashCommand: { + options: [ + { + name: "role", + description: "Role to add to allowed roles", + value: "role", + type: 8, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let roleid = args[0].value; + let role = interaction.guild.roles.cache.find(x => x.id == roleid); + if (role == undefined) { + return interaction.send(`Uh Oh! The role <@&${args[0].value}> connot be found.`); + } else { + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (guild.server.allowedRole!=undefined&&guild.server.allowedRoles.includes(roleid)) return interaction.send(`The role <@&${args[0].value}> has already been added.`); + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully added <@&${args[0].value}> to allowed roles.`); + }); + } + }, + }, +} \ No newline at end of file From 0bd83dad8772c417a04003bd1e74695c46950071 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 20:15:50 -0700 Subject: [PATCH 17/29] update/remove role and exists func --- commands/removeRole.js | 94 ++++++++++++++++++++++++++++++++++++++++++ commands/setRole.js | 5 ++- util/Exists.js | 4 ++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 commands/removeRole.js create mode 100644 util/Exists.js diff --git a/commands/removeRole.js b/commands/removeRole.js new file mode 100644 index 0000000..0555196 --- /dev/null +++ b/commands/removeRole.js @@ -0,0 +1,94 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "removerole", + description: "Remove a role allowed to use the bot", + usage: "[role]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + aliases: ["remove_role"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + if (args.length==0) return message.channel.send(`You must provide a role.`); + let roleid = args[0].replace('<@&', '').replace('>', ''); + let role = message.guild.roles.cache.find(x => x.id == roleid); + if (role == undefined) { + return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`); + } else { + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); + if (guild.server.hasCustomRoles==false) return message.channel.send(`There are no roles to be removed.`); + if (!guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} is not added to your roles.`); + for (let i = 0; i < guild.server.allowedRoles.length; i++) { + if (guild.server.allowedRoles[i]==roleid) { + if ((guild.server.allowedRoles.length-1)==0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":false}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully removed ${args[0]} from allowed roles! There are no more allowed roles.`); + }); + } else if ((guild.server.allowedRoles.length-1)>0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedRoles":roleid}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully removed ${args[0]} from allowed roles.`); + }); + } + } + } + } + }, + SlashCommand: { + options: [ + { + name: "role", + description: "Role to remove from allowed roles", + value: "role", + type: 8, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let roleid = args[0].value; + let role = interaction.guild.roles.cache.find(x => x.id == roleid); + if (role == undefined) { + return interaction.send(`Uh Oh! The role <@&${args[0].value}> connot be found.`); + } else { + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (guild.server.hasCustomRoles==false) return interaction.send(`There are no roles to be removed.`); + if (!guild.server.allowedRoles.includes(roleid)) return interaction.send(`The role <@&${args[0].value}> is not added to your roles.`); + for (let i = 0; i < guild.server.allowedRoles.length; i++) { + if (guild.server.allowedRoles[i]==roleid) { + if ((guild.server.allowedRoles.length-1)==0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":false}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully removed <@&${args[0].value}> from allowed roles! There are no more allowed roles.`); + }); + } else if ((guild.server.allowedRoles.length-1)>0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedRoles":roleid}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully removed <@&${args[0].value}> from allowed roles.`); + }); + } + } + } + } + }, + }, +} \ No newline at end of file diff --git a/commands/setRole.js b/commands/setRole.js index 53602ba..cef54dd 100644 --- a/commands/setRole.js +++ b/commands/setRole.js @@ -1,4 +1,5 @@ const { MessageEmbed } = require('discord.js'); +const exists = require('../util/Exists') module.exports = { name: "setrole", @@ -24,7 +25,7 @@ module.exports = { return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`); } else { let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - if (guild.server.allowedRole!=undefined&&guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} has already been added.`); + if (exists(guild.server.allowedRoles)&&guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} has already been added.`); client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) { if (err) throw err; return message.channel.send(`Successfully added ${args[0]} to allowed roles.`); @@ -59,7 +60,7 @@ module.exports = { return interaction.send(`Uh Oh! The role <@&${args[0].value}> connot be found.`); } else { let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); - if (guild.server.allowedRole!=undefined&&guild.server.allowedRoles.includes(roleid)) return interaction.send(`The role <@&${args[0].value}> has already been added.`); + if (exists(guild.server.allowedRoles)&&guild.server.allowedRoles.includes(roleid)) return interaction.send(`The role <@&${args[0].value}> has already been added.`); client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) { if (err) throw err; return interaction.send(`Successfully added <@&${args[0].value}> to allowed roles.`); diff --git a/util/Exists.js b/util/Exists.js new file mode 100644 index 0000000..3cdeea0 --- /dev/null +++ b/util/Exists.js @@ -0,0 +1,4 @@ +module.exports = n => { + if (n == null || n == undefined || n == "") return false; + return true; +} \ No newline at end of file From d9855048c65119e9862d1ac6e8063599c6f96539 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 20:53:51 -0700 Subject: [PATCH 18/29] update/roles --- commands/roles.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 commands/roles.js diff --git a/commands/roles.js b/commands/roles.js new file mode 100644 index 0000000..ae2cbfd --- /dev/null +++ b/commands/roles.js @@ -0,0 +1,77 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "roles", + description: "View allowed roles", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); + if (guild.server.hasCustomRoles==false) { + return message.channel.send('There are no roles set for the bot.'); + } + + let roles = ``; + for (let i = 0; i < guild.server.allowedRoles.length; i++) { + if (guild.server.allowedRoles[i] == undefined) break; + let role = message.guild.roles.cache.find(r => r.id == guild.server.allowedRoles[i]); + if (roles.length==0) roles += `@${role.name}`; + else roles += `\n@${role.name}`; + } + let rolesEmbed = new MessageEmbed() + .setColor('#0099ff') + .setDescription('**Allowed Roles to use the Bot**') + .addFields( + { name: `There are currently ${guild.server.allowedRoles.length} allowed roles.`, value: `\`${roles}\``, inline: true }, + ) + .setFooter('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + return message.channel.send({ embeds: [rolesEmbed] }); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (guild.server.hasCustomRoles==false) { + return interaction.send('There are no roles set for the bot.'); + } + + let roles = ``; + for (let i = 0; i < guild.server.allowedRoles.length; i++) { + if (guild.server.allowedRoles[i] == undefined) break; + let role = interaction.guild.roles.cache.find(r => r.id == guild.server.allowedRoles[i]); + if (roles.length==0) roles += `@${role.name}`; + else roles += `\n@${role.name}`; + } + let rolesEmbed = new MessageEmbed() + .setColor('#0099ff') + .setDescription('|**Allowed Roles to use the Bot**') + .addFields( + { name: `There are currently **${guild.server.allowedRoles.length}** allowed roles.`, value: `\`${roles}\``, inline: true }, + ) + .setFooter('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + return interaction.send({ embeds: [rolesEmbed] }); + }, + }, +} \ No newline at end of file From 4caccd74d4b591e8ba0c2a52d7ad83f7d1d5ef1f Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 21:00:41 -0700 Subject: [PATCH 19/29] update/set channel --- commands/setChannel.js | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 commands/setChannel.js diff --git a/commands/setChannel.js b/commands/setChannel.js new file mode 100644 index 0000000..7f4f608 --- /dev/null +++ b/commands/setChannel.js @@ -0,0 +1,69 @@ +const { MessageEmbed } = require('discord.js'); +const exists = require('../util/Exists'); + +module.exports = { + name: "setchannel", + description: "Add channel to allowed channels", + usage: "[channel]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + aliases: ["set_channel", "addchannel", "add_channel"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + if (args.length==0) return message.channel.send(`You must provide a channel.`); + let channelid = args[0].replace('<#', '').replace('>', ''); + let channel = client.channels.cache.get(channelid); + if (!channel) return message.channel.send(`Cannot find that channel.`); + if (channel.type=="voice") return message.channel.send(`Connot set voice channel to preferred channel.`); + if (channel.deleted) return message.channel.send(`Connot set deleted channel to preferred channel.`); + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); + if (exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return message.channel.send(`The channel ${args[0]} has already been added.`); + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":true}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully added ${args[0]} to allowed channels.`); + }); + }, + SlashCommand: { + options: [ + { + name: "channel", + description: "Channel to add to allowed channles", + value: "channel", + type: 7, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let channelid = args[0].value; + let channel = client.channels.cache.get(channelid); + if (!channel) return message.channel.send(`Cannot find that channel.`); + if (channel.type=="voice") return interaction.send(`Connot set voice channel to preferred channel.`); + if (channel.deleted) return interaction.send(`Connot set deleted channel to preferred channel.`); + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return interaction.send(`The channel ${args[0]} has already been added.`); + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$push:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":true}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully added ${args[0]} to allowed channels.`); + }); + }, + }, +} \ No newline at end of file From 03ee4214320327e1e2b781fe0cdbcaa1b9960f67 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 21:07:32 -0700 Subject: [PATCH 20/29] update/remove channel --- commands/removeChannel.js | 89 +++++++++++++++++++++++++++++++++++++++ commands/setChannel.js | 4 +- 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 commands/removeChannel.js diff --git a/commands/removeChannel.js b/commands/removeChannel.js new file mode 100644 index 0000000..81f37d7 --- /dev/null +++ b/commands/removeChannel.js @@ -0,0 +1,89 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "removechannel", + description: "Remove channel from allowed channels", + usage: "[channel]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["remove_role"], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + if (args.length==0) return message.channel.send(`You must provide a channel.`); + let channelid = args[0].replace('<#', '').replace('>', ''); + 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 client.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.`); + if (!guild.server.allowedChannels.includes(channelid)) return message.channel.send(`The channel ${args[0]} is not added to your roles.`); + for (let i = 0; i < guild.server.allowedChannels.length; i++) { + if (guild.server.allowedChannels[i]==channelid) { + if ((guild.server.allowedChannels.length-1)==0) { + client.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(`Successfully removed ${args[0]} from allowed channels ${message.author}! There are no more allowed channels.`); + }); + } else if ((guild.server.allowedChannels.length-1)>0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedChannels":channelid}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully removed ${args[0]} from allowed channels.`); + }); + } + } + } + }, + SlashCommand: { + options: [ + { + name: "channel", + description: "Channel to remove from allowed channles", + value: "channel", + type: 7, + required: true, + }, + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + if (args.length==0) return interaction.send(`You must provide a channel.`); + let channelid = args[0].value; + let channel = client.channels.cache.get(channelid); + if (!channel) return interaction.send(`Uh Oh! The channel <#${args[0].value}> connot be found.`); + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (guild.server.hasCustomChannels==false) return interaction.send(`There are no channels to be removed.`); + if (!guild.server.allowedChannels.includes(channelid)) return interaction.send(`The channel <#${args[0].value}> is not added to your roles.`); + for (let i = 0; i < guild.server.allowedChannels.length; i++) { + if (guild.server.allowedChannels[i]==channelid) { + if ((guild.server.allowedChannels.length-1)==0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":false}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully removed <#${args[0].value}> from allowed channels! There are no more allowed channels.`); + }); + } else if ((guild.server.allowedChannels.length-1)>0) { + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedChannels":channelid}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully removed <#${args[0].value}> from allowed channels.`); + }); + } + } + } + }, + }, +} \ No newline at end of file diff --git a/commands/setChannel.js b/commands/setChannel.js index 7f4f608..bc42d81 100644 --- a/commands/setChannel.js +++ b/commands/setChannel.js @@ -59,10 +59,10 @@ module.exports = { if (channel.type=="voice") return interaction.send(`Connot set voice channel to preferred channel.`); if (channel.deleted) return interaction.send(`Connot set deleted channel to preferred channel.`); let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); - if (exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return interaction.send(`The channel ${args[0]} has already been added.`); + if (exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return interaction.send(`The channel <#${args[0].value}> has already been added.`); client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$push:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":true}},function(err, res) { if (err) throw err; - return interaction.send(`Successfully added ${args[0]} to allowed channels.`); + return interaction.send(`Successfully added <#${args[0].value}> to allowed channels.`); }); }, }, From 21b17797d73919dceac4e0241d4691f8eacba067 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 21:17:36 -0700 Subject: [PATCH 21/29] update/channels --- commands/channels.js | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 commands/channels.js diff --git a/commands/channels.js b/commands/channels.js new file mode 100644 index 0000000..e1c6a8f --- /dev/null +++ b/commands/channels.js @@ -0,0 +1,75 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "channels", + description: "View a list of allowed channels", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let guild = await client.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 = ``; + for (let i = 0; i < guild.server.allowedChannels.length; i++) { + if (guild.server.allowedChannels[i] == undefined) break; + if (channels.length==0) channels += `<#${guild.server.allowedChannels[i]}>`; + else channels += `\n<#${guild.server.allowedChannels[i]}>`; + } + let channelsEmbed = new MessageEmbed() + .setColor('#0099ff') + .setDescription('**Allowed Channels to use the Bot**') + .addFields( + { name: `There are currently ${guild.server.allowedChannels.length} allowed channels.`, value: `${channels}`, inline: true }, + ) + .setFooter('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + return message.channel.send({ embeds: [channelsEmbed] }); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (guild.server.hasCustomChannels==false) { + return interaction.send('There are no channels set for the bot.'); + } + + let channels = ``; + for (let i = 0; i < guild.server.allowedChannels.length; i++) { + if (guild.server.allowedChannels[i] == undefined) break; + if (channels.length==0) channels += `<#${guild.server.allowedChannels[i]}>`; + else channels += `\n<#${guild.server.allowedChannels[i]}>`; + } + let channelsEmbed = new MessageEmbed() + .setColor('#0099ff') + .setDescription('**Allowed Channels to use the Bot**') + .addFields( + { name: `There are currently ${guild.server.allowedChannels.length} allowed channels.`, value: `${channels}`, inline: true }, + ) + .setFooter('LPS Website Support', client.config.IconURL, 'https://discord.gg/jgUW656v2t') + return interaction.send({ embeds: [channelsEmbed] }); + }, + }, +} \ No newline at end of file From 698f04195aaf4b1ff1fcd147924454fdc723af75 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 21:31:00 -0700 Subject: [PATCH 22/29] update/toggle ping on panic --- commands/togglePingOnPanic.js | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 commands/togglePingOnPanic.js diff --git a/commands/togglePingOnPanic.js b/commands/togglePingOnPanic.js new file mode 100644 index 0000000..93bdadc --- /dev/null +++ b/commands/togglePingOnPanic.js @@ -0,0 +1,90 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "togglepingonpanic", + description: "Enable or Disable ping on panic", + usage: "[true/false] [role]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message, args) => { + if (args.length==0) return message.channel.send(`You must provide a \`Ping On Role Status\` and a \`role\` to ping.`); + if (args[0]=="false") { + // disable ping on panic and remove ping role + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.pingOnPanic":false,"server.pingRole":null}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully disabled ping role on panic.`); + }); + } else if (args[0]=="true") { + if (!args[1]) return message.channel.send(`You must provide a \`role\` to ping .`); + let roleid = args[1].replace('<@&', '').replace('>', ''); + let role = message.guild.roles.cache.find(x => x.id == roleid); + if (role == undefined) { + return message.channel.send(`Uh Oh! The role ${args[1]} connot be found.`); + } else { + client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.pingRole":roleid,"server.pingOnPanic":true}},function(err, res) { + if (err) throw err; + return message.channel.send(`Successfully set ${args[1]} to be pinged on panic.`); + }); + } + } else return message.channel.send(`\`${args[0]}\` is an invalid status, use \`true\` or \`false\``); + }, + SlashCommand: { + options: [ + { + name: "toggle", + description: "Toggle ping on panic", + value: "toggle", + type: 5, + required: true, + }, + { + name: "role", + description: "Role to ping on panic", + value: "role", + type: 8, + required: true, + } + ], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + if (!args[0].value) { + // disable ping on panic and remove ping role + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.pingOnPanic":false,"server.pingRole":null}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully disabled ping role on panic.`); + }); + } else if (args[0].value) { + let roleid = args[1].value; + let role = interaction.guild.roles.cache.find(x => x.id == roleid); + if (role == undefined) { + return interaction.send(`Uh Oh! The role <@&${args[1].value}> connot be found.`); + } else { + client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.pingRole":roleid,"server.pingOnPanic":true}},function(err, res) { + if (err) throw err; + return interaction.send(`Successfully set <@&${args[1].value}> to be pinged on panic.`); + }); + } + } + }, + }, +} \ No newline at end of file From 3df8bc70e8e0557c61a6aa15bb7dad651138f753 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 16 Mar 2022 21:33:48 -0700 Subject: [PATCH 23/29] update/ping on panic status --- commands/getPingOnPanicStatus.js | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 commands/getPingOnPanicStatus.js diff --git a/commands/getPingOnPanicStatus.js b/commands/getPingOnPanicStatus.js new file mode 100644 index 0000000..800fe27 --- /dev/null +++ b/commands/getPingOnPanicStatus.js @@ -0,0 +1,41 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "", + description: "", + usage: "", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + aliases: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, message) => { + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); + return message.channel.send(`Current Ping on Panic Status: ${guild.server.pingOnPanic}`); + }, + SlashCommand: { + options: [], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + return interaction.send(`Current Ping on Panic Status: ${guild.server.pingOnPanic}`); + }, + }, +} \ No newline at end of file From 1cbe4356bc486a8bf9efc034ebfc8d8985a14a90 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Mar 2022 12:06:55 -0700 Subject: [PATCH 24/29] update/fix pingonpanic --- commands/{getPingOnPanicStatus.js => pingOnPanic.js} | 8 ++++---- commands/togglePingOnPanic.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename commands/{getPingOnPanicStatus.js => pingOnPanic.js} (85%) diff --git a/commands/getPingOnPanicStatus.js b/commands/pingOnPanic.js similarity index 85% rename from commands/getPingOnPanicStatus.js rename to commands/pingOnPanic.js index 800fe27..8c6d779 100644 --- a/commands/getPingOnPanicStatus.js +++ b/commands/pingOnPanic.js @@ -1,14 +1,14 @@ const { MessageEmbed } = require('discord.js'); module.exports = { - name: "", - description: "", + name: "pingonpanic", + description: "Get ping on panic status", usage: "", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, - aliases: [], + aliases: ["pingonpanicstatus"], /** * * @param {require("../structures/LinesPoliceCadBot")} client @@ -35,7 +35,7 @@ module.exports = { } let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); - return interaction.send(`Current Ping on Panic Status: ${guild.server.pingOnPanic}`); + return interaction.send(`Current Ping on Panic Status: \` ${guild.server.pingOnPanic.toString().toUpperCase()} \``); }, }, } \ No newline at end of file diff --git a/commands/togglePingOnPanic.js b/commands/togglePingOnPanic.js index 93bdadc..0268657 100644 --- a/commands/togglePingOnPanic.js +++ b/commands/togglePingOnPanic.js @@ -53,7 +53,7 @@ module.exports = { value: "role", type: 8, required: true, - } + }, ], /** * From 9edb6b98d7fd39e81a1a61d55ae9158ff9e71a8b Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Mar 2022 12:16:52 -0700 Subject: [PATCH 25/29] use client.exists --- commands/setChannel.js | 2 +- commands/setRole.js | 3 +-- events/ready.js | 10 +++++----- util/Exists.js | 4 ---- 4 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 util/Exists.js diff --git a/commands/setChannel.js b/commands/setChannel.js index bc42d81..f2b9f10 100644 --- a/commands/setChannel.js +++ b/commands/setChannel.js @@ -25,7 +25,7 @@ module.exports = { if (channel.type=="voice") return message.channel.send(`Connot set voice channel to preferred channel.`); if (channel.deleted) return message.channel.send(`Connot set deleted channel to preferred channel.`); let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - if (exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return message.channel.send(`The channel ${args[0]} has already been added.`); + if (client.exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return message.channel.send(`The channel ${args[0]} has already been added.`); client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":true}},function(err, res) { if (err) throw err; return message.channel.send(`Successfully added ${args[0]} to allowed channels.`); diff --git a/commands/setRole.js b/commands/setRole.js index cef54dd..e31fda4 100644 --- a/commands/setRole.js +++ b/commands/setRole.js @@ -1,5 +1,4 @@ const { MessageEmbed } = require('discord.js'); -const exists = require('../util/Exists') module.exports = { name: "setrole", @@ -25,7 +24,7 @@ module.exports = { return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`); } else { let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - if (exists(guild.server.allowedRoles)&&guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} has already been added.`); + if (client.exists(guild.server.allowedRoles)&&guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} has already been added.`); client.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) { if (err) throw err; return message.channel.send(`Successfully added ${args[0]} to allowed roles.`); diff --git a/events/ready.js b/events/ready.js index 2a8a892..8e37bb3 100644 --- a/events/ready.js +++ b/events/ready.js @@ -2,11 +2,11 @@ module.exports = async (client) => { (client.Ready = true), client.user.setPresence({ status: client.config.Presence.status, // You can show online, idle, and dnd - activity: { - name: client.config.Presence.name, - type: client.config.Presence.type, - }, -}); + activity: { + name: client.config.Presence.name, + type: client.config.Presence.type, + }, + }); client.log("Successfully Logged in as " + client.user.tag); // You can change the text if you want, but DO NOT REMOVE "client.user.tag" client.RegisterSlashCommands(); }; \ No newline at end of file diff --git a/util/Exists.js b/util/Exists.js deleted file mode 100644 index 3cdeea0..0000000 --- a/util/Exists.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = n => { - if (n == null || n == undefined || n == "") return false; - return true; -} \ No newline at end of file From e1c599d3c600dddc9de574c12526fefc458f0bbc Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Mar 2022 12:48:02 -0700 Subject: [PATCH 26/29] update presence --- commands/setChannel.js | 1 - events/ready.js | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/commands/setChannel.js b/commands/setChannel.js index f2b9f10..96da365 100644 --- a/commands/setChannel.js +++ b/commands/setChannel.js @@ -1,5 +1,4 @@ const { MessageEmbed } = require('discord.js'); -const exists = require('../util/Exists'); module.exports = { name: "setchannel", diff --git a/events/ready.js b/events/ready.js index 8e37bb3..36a5f0e 100644 --- a/events/ready.js +++ b/events/ready.js @@ -1,12 +1,12 @@ module.exports = async (client) => { (client.Ready = true), - client.user.setPresence({ - status: client.config.Presence.status, // You can show online, idle, and dnd - activity: { - name: client.config.Presence.name, + client.user.setActivity(client.config.Presence.name, { type: client.config.Presence.type, - }, - }); - client.log("Successfully Logged in as " + client.user.tag); // You can change the text if you want, but DO NOT REMOVE "client.user.tag" + }) + client.user.setPresence({ + status: client.config.Presence.status, // You can show online, idle, and dnd + }); + client.log(`Successfully Logged in as ${client.user.tag}`); // You can change the text if you want, but DO NOT REMOVE "client.user.tag" + client.log(`Ready to serve in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`) client.RegisterSlashCommands(); }; \ No newline at end of file From 8d5584d0973974deaf2b3b271a891578df31dfc4 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Mar 2022 15:30:49 -0700 Subject: [PATCH 27/29] update/verify user has role --- .gitignore | 7 +- commands.js | 603 -------------------------------- commands/checkStatus.js | 8 +- commands/firearmSearch.js | 6 + commands/nameSearch.js | 7 + commands/panic.js | 6 + commands/plateSearch.js | 6 + commands/updateLicense.js | 6 + commands/updateStatus.js | 6 + structures/LinesPoliceCadBot.js | 268 ++------------ 10 files changed, 74 insertions(+), 849 deletions(-) delete mode 100644 commands.js diff --git a/.gitignore b/.gitignore index ab4a373..617e27c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,12 @@ node_modules/* # test file +default.js test.js -# Dev Launch -dev.js - -# Dev config +# Dev config/dev-config.js +dev.js # Logs logs/* diff --git a/commands.js b/commands.js deleted file mode 100644 index 9e5d2de..0000000 --- a/commands.js +++ /dev/null @@ -1,603 +0,0 @@ -/* -HEY YOU! YEAH YOU! -If you are looking at this file, -that means I am not done, and this is -all the old code for commands that I need -to refactor to be up to date with modern -discord.js bot structure utilizing the -slash command support. So just ignore this -file for now, its just all the old command -logic. -*/ - - -const MongoClient = require('mongodb').MongoClient; -const { MessageEmbed } = require("discord.js"); -const ObjectId = require('mongodb').ObjectID -const randomstring = require('randomstring'); -const io = require('socket.io-client'); - -class Commands { - - constructor(config, mongoURI, dbo) { - this.config = config; - this.connectMongo(mongoURI, dbo); - } - - async connectMongo(mongoURI, dbo) { - this.db = await MongoClient.connect(mongoURI,{useUnifiedTopology:true}); - this.dbo = this.db.db(dbo); - } - - // Updates Prefix - async newPrefix(message, n) { - if (n[0]==undefined) return message.channel.send(`You must provide a \`new prefix\` ${message.author}`); - if (n[0].length<1) return message.channel.send('Your new prefix must be \`1\` character!') - this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.prefix":n[0]}},function(err, res) { - if (err) throw err; - message.channel.send(`The new prefix is now **\`${n}\`**`); - }); - } - - // Remote Login - async remoteLogin(message, args) { - return message.channel.send('Login from Lines Police CAD account management https://www.linespolice-cad.com/'); - } - - async remoteLogout(message) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You cannot logout if your not logged in ${message.author}`); - this.dbo.collection("users").updateOne({"user.discord.id":message.author.id},{$unset:{"user.discord":""}, $set:{"user.discordConnected":false}},function(err,res) { - if (err) throw err; - message.channel.send(`Succesfully disconnected you Discord account ${message.author}`); - }); - } - - async account(message) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (user==null) return message.channel.send(`You are not logged in ${message.author}`); - message.author.send(`${message.author} Logged in as **${user.user.username}** | **${user.user.email}**`); - } - - async nameSearch(message, args) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - let data; - if (user.user.activeCommunity=='' || user.user.activeCommunity==null) { - if (args.length==0) return message.channel.send(`You must provide a \`First Name\`, \`Last Name\` and \`DOB\`(yyyy-mm-dd) ${message.author}`); - if (args.length==1) return message.channel.send(`You're missing a \`Last Name\` and \`DOB\`(yyyy-mm-dd) ${message.author}`); - if (args.length==2) return message.channel.send(`You're missing a \`DOB\`(yyyy-mm-dd) ${message.author}`); - } - if (args.length==0) return message.channel.send(`You must provide a \`First Name\` and \`Last Name\` ${message.author}`); - if (args.length==1) return message.channel.send(`You're missing a \`Last Name\` ${message.author}`); - - if (user.user.activeCommunity=='' || user.user.activeCommunity==null) { - data = { - user: user, - query: { - firstName: args[0], - lastName: args[1], - dateOfBirth: args[2], - activeCommunityID: user.user.activeCommunity - } - } - } else { - data = { - user: user, - query: { - firstName: args[0], - lastName: args[1], - activeCommunityID: user.user.activeCommunity - } - } - } - - const socket = io.connect(this.config.socket); - socket.emit("bot_name_search", data); - socket.on("bot_name_search_results", results => { - - if (results.user._id==user._id) { - if (results.civilians.length == 0) { - return message.channel.send(`Name \`${args[0]} ${args[1]}\` not found ${message.author}`); - } - - for (let i = 0; i < results.civilians.length; i++) { - // Get Drivers Licence Status - let licenceStatus; - if (results.civilians[i].civilian.licenseStatus == 1) licenceStatus = 'Valid'; - if (results.civilians[i].civilian.licenceStatus == 2) licenceStatus = 'Revoked'; - if (results.civilians[i].civilian.licenceStatus == 3) licenceStatus = 'None'; - // Get Firearm Licence Status - let firearmLicence = results.civilians[i].civilian.firearmLicense; - if (firearmLicence == undefined || firearmLicence == null) firearmLicence = 'None'; - if (firearmLicence == '2') firearmLicence = 'Valid'; - if (firearmLicence == '3') firearmLicence = 'Revoked'; - let nameResult = new MessageEmbed() - .setColor('#0099ff') - .setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`) - .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') - .setDescription('Name Search Results') - .addFields( - { name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true }, - { name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true }, - { name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true }, - { name: `**Drivers License**`, value: `\`${licenceStatus}\``, inline: true }, - { name: `**Firearm Licence**`, value: `\`${firearmLicence}\``, inline: true }, - { name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true } - ) - // Check Other details - let address = results.civilians[i].civilian.address; - let occupation = results.civilians[i].civilian.occupation; - let height = results.civilians[i].civilian.height; - let weight = results.civilians[i].civilian.weight; - let eyeColor = results.civilians[i].civilian.eyeColor; - let hairColor = results.civilians[i].civilian.hairColor; - if (address != null && address != undefined && address != '') nameResult.addFields({ name: `**Address**`, value: `\`${address}\``, inline: true }); - if (occupation != null && occupation != undefined && occupation != '') nameResult.addFields({ name: `**Occupation**`, value: `\`${occupation}\``, inline: true }); - if (height!=null&&height!=undefined&&height!="NaN"&&height!='') { - if (results.civilians[i].civilian.heightClassification=='imperial') { - let ft = Math.floor(height/12); - let inch = height%12; - nameResult.addFields({ name: '**Height**', value: `\`${ft}'${inch}"\``, inline: true }); - } else { - nameResult.addFields({ name: '**Height**', value: `\`${height}cm\``, inline: true }); - } - } - if (weight!=null&&weight!=undefined&&weight!='') { - if (results.civilians[i].civilian.weightClassification=='imperial') { - nameResult.addFields({ name: '**Weight**', value: `\`${weight}lbs.\``, inline: true }); - } else { - nameResult.addFields({ name: '**Weight**', value: `\`${weight}kgs.\``, inline: true }); - } - } - if (eyeColor!=null&&eyeColor!=undefined&&eyeColor!='') nameResult.addFields({name:'**Eye Color**',value:`\`${eyeColor}\``,inline:true}); - if (hairColor!=null&&hairColor!=undefined&&hairColor!='') nameResult.addFields({name:'**Hair Color**',value:`\`${hairColor}\``,inline:true}); - nameResult.addFields({name:'**Organ Donor**',value:`\`${results.civilians[i].civilian.organDonor}\``,inline:true}); - nameResult.addFields({name:'**Veteran**',value:`\`${results.civilians[i].civilian.veteran}\``,inline:true}); - message.channel.send(nameResult); - } - } - socket.disconnect(); - }); - } - - async plateSearch(message, args) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (args.length==0) return message.channel.send(`You are missing a \`Plate #\` ${message.author}`); - let data = { - user: user, - query: { - plateNumber: args[0], - activeCommunityID: user.user.activeCommunity - } - } - const socket = io.connect(this.config.socket); - socket.emit('bot_plate_search', data); - socket.on('bot_plate_search_results', results => { - - if (results.user._id==user._id) { - if (results.vehicles.length == 0) { - return message.channel.send(`Plate Number \`${args[0]}\` not found ${message.author}`); - } - - for (let i = 0; i < results.vehicles.length; i++) { - let plateResult = new MessageEmbed() - .setColor('#0099ff') - .setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`) - .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') - .setDescription('Plate Search Results') - .addFields( - { name: `**Plate #**`, value: `\`${results.vehicles[i].vehicle.plate}\``, inline: true }, - { name: `**Vin #**`, value: `\`${results.vehicles[i].vehicle.vin}\``, inline: true }, - { name: `**Model**`, value: `\`${results.vehicles[i].vehicle.model}\``, inline: true }, - { name: `**Color**`, value: `\`${results.vehicles[i].vehicle.color}\``, inline: true }, - { name: `**Owner**`, value: `\`${results.vehicles[i].vehicle.registeredOwner}\``, inline: true }, - ) - // Other details - let validRegistration = results.vehicles[i].vehicle.validRegistration; - let validInsurance = results.vehicles[i].vehicle.validInsurance; - let stolen = results.vehicles[i].vehicle.isStolen; - if (validRegistration=='1') plateResult.addFields({ name: `**Registration**`, value: `\`Valid\``, inline: true }); - if (validRegistration=='2') plateResult.addFields({ name: `**Registration**`, value: `\`InValid\``, inline: true }); - if (validInsurance=='1') plateResult.addFields({ name: `**Insurance**`, value: `\`Valid\``, inline: true }); - if (validInsurance=='2') plateResult.addFields({ name: `**Insurance**`, value: `\`InValid\``, inline: true }); - if (stolen=='1') plateResult.addFields({ name: `**Stolen**`, value: `\`No\``, inline: true }); - if (stolen=='2') plateResult.addFields({ name: `**Stolen**`, value: `\`Yes\``, inline: true }); - message.channel.send(plateResult); - } - } - socket.disconnect(); - }); - } - - async firearmSearch(message, args) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (args.length==0) return message.channel.send(`You are missing a \`Serial Number\` ${message.author}`); - let data = { - user: user, - query: { - serialNumber: args[0], - activeCommunityID: user.user.activeCommunity - } - } - const socket = io.connect(this.config.socket); - socket.emit('bot_firearm_search', data); - socket.on('bot_firearm_search_results', results => { - if (results.user._id==user._id) { - if (results.firearms.length==0) { - return message.channel.send(`No Firearms found ${message.author}`); - } - - for (let i = 0; i < results.firearms.length; i++) { - let firearmResult = new MessageEmbed() - .setColor('#0099ff') - .setTitle(`**${results.firearms[i].firearm.serialNumber} | ${results.firearms[i]._id}**`) - .setURL('https://discord.gg/jgUW656v2t') - .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') - .setDescription('Firearm Search Results') - .addFields( - { name: `**Serial Number**`, value: `\`${results.firearms[i].firearm.serialNumber}\``, inline: true }, - { name: `**Type**`, value: `\`${results.firearms[i].firearm.weaponType}\``, inline: true }, - { name: `**Owner**`, value: `\`${results.firearms[i].firearm.registeredOwner}\``, inline: true }, - ) - // Other details - let isStolen = results.firearms[i].firearm.isStolen; - if (isStolen=="false"||isStolen==false) firearmResult.addFields({name:`**Stolen**`,value:'\`No\`',inline: true}); - if (isStolen=="true"||isStolen==true) firearmResult.addFields({name:`**Stolen**`,value:'\`Yes\`',inline: true}); - message.channel.send(firearmResult); - } - } - socket.disconnect(); - }); - } - - async checkStatus(message, args) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (user.user.activeCommunity == null) return message.channel.send(`You must join a community to use this command ${message.author}`); - if (args.length == 0) { - message.channel.send(`${message.author}'s status: \`${user.user.dispatchStatus}\` | Set by: \`${user.user.dispatchStatusSetBy}\``); - } else { - let targetUserID = args[0].replace('<@!', '').replace('>', ''); - let targetUser = await this.dbo.collection("users").findOne({"user.discord.id":targetUserID}).then(user => user); - // This lame line of code to get username without ping on discord - const User = client.users.cache.get(args[0].replace('<@!', '').replace('>', '')); - if (!targetUser) return message.channel.send(`Cannot find **${args[0]}** ${message.author}`); - if (targetUser.user.activeCommunity!=user.user.activeCommunity) { - return message.channel.send(`You are not in the same community as \`${User.tag}\` ${message.author}`); - } - return message.channel.send(`${message.author}, \`${User.tag}'s\` status: \`${targetUser.user.dispatchStatus}\` | Set by: \`${targetUser.user.dispatchStatusSetBy}\``); - } - } - - async updateStatus(message, args, prefix) { - let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', 'Panic', '10-41', '10-42']; - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command ${message.author}`); - if (args.length==0) return message.channel.send(`You must provide a new status ${message.author} | To see a list of valid statuses, use command \`${prefix}validStatus\`.`); - if (!validStatus.includes(args[0])) return message.channel.send(`\`${args[0]}\` is a Invalid Status ${message.author}! To see a list of valid statuses, use command \`${prefix}validStatus\`.`); - let onDuty=null; - let updateDuty=false; - let status = args[0] - if (args[0]=='10-41') { - onDuty=true; - updateDuty=true; - status='Online'; - } - if (args[0]=='10-42') { - onDuty=false; - updateDuty=true; - status='Offline'; - } - let req={ - userID: user._id, - status: status, - setBy: 'Self', - onDuty: onDuty, - updateDuty: updateDuty - }; - const socket = io.connect(this.config.socket); - socket.emit('bot_update_status', req); - socket.on('bot_updated_status', (res) => { - message.channel.send(`Succesfully updated status to \`${args[0]}\` ${message.author}`); - socket.disconnect(); - }); - } - - async enablePanic(message) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command ${message.author}`); - const socket = io.connect(this.config.socket); - // If panic is enabled, disable panic - if (user.user.dispatchStatus=='Panic') { - let myReq = { - userID: user._id, - communityID: user.user.activeCommunity - }; - socket.emit('clear_panic', myReq); - - let myUpdateReq = { - userID: user._id, - status: '10-8', - setBy: 'System', - onDuty: null, - updateDuty: false - }; - socket.emit('bot_update_status', myUpdateReq); - socket.on('bot_updated_status', (res) => { - message.channel.send(`Disabled Panic ${message.author} and set status to \`10-8\`.`); - socket.disconnect(); - }); - return; - // If panic is disabled, enable panic - } else { - this.updateStatus(message, ['Panic'], null); - let myReq = { - userID: user._id, - userUsername: user.user.username, - activeCommunity: user.user.activeCommunity - } - socket.emit('panic_button_update', myReq); - socket.disconnect(); - let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - if (guild.server.pingOnPanic) return message.channel.send(`Attention <@&${guild.server.pingRole}>! \`${user.user.username}\` has activated panic`); - return; - } - } - - async updateLicense(message, args) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - let data; - if (user.user.activeCommunity=='' || user.user.activeCommunity==null) { - if (args.length==0) return message.channel.send(`You must provide a \`License Status\`, \`First Name\`, \`Last Name\`, \`DOB\`(yyyy-mm-dd) ${message.author}`); - if (args.length==1) return message.channel.send(`You're missing a \`First Name\`, \`Last Name\` and \`DOB\`(yyyy-mm-dd) ${message.author}`); - if (args.length==2) return message.channel.send(`You're missing a \`Last Name\` and \`DOB\`(yyyy-mm-dd) ${message.author}`); - if (args.length==3) return message.channel.send(`You're missing a \`DOB\`(yyyy-mm-dd) ${message.author}`); - if (args[0].toLowerCase()!='revoke'&&args[0].toLowerCase()!='reinstate') return message.channel.send(`Invalid License Status, choose \`revoke\` or \`reinstate\` ${message.author}`); - } - if (args.length==0) return message.channel.send(`You must provide a \`License Status\`, \`First Name\` and \`Last Name\` ${message.author}`); - if (args.length==1) return message.channel.send(`You're missing a \`First Name\` and \`Last Name\` ${message.author}`); - if (args.length==2) return message.channel.send(`You're missing a \`Last Name\` ${message.author}`); - if (args[0].toLowerCase()!='revoke'&&args[0].toLowerCase()!='reinstate') return message.channel.send(`Invalid License Status, choose \`revoke\` or \`reinstate\` ${message.author}`); - - if (user.user.activeCommunity=='' || user.user.activeCommunity==null) { - data = { - user: user, - query: { - firstName: args[1], - lastName: args[2], - dateOfBirth: args[3], - activeCommunityID: user.user.activeCommunity - } - } - } else { - data = { - user: user, - query: { - firstName: args[1], - lastName: args[2], - activeCommunityID: user.user.activeCommunity - } - } - } - - const socket = io.connect(this.config.socket); - socket.emit("bot_name_search", data); - socket.on("bot_name_search_results", (results) => { - if (results.user._id==user._id) { - if (results.civilians.length == 0) { - return message.channel.send(`Name \`${args[1]} ${args[2]}\` not found ${message.author}`); - } - } - - let query = { - _id: results.civilians[0]._id, - status: null, - bot_request: true - }; - if (args[0]=='revoke') query.status = 2; - if (args[0]=='reinstate') query.status = 1; - socket.emit("update_drivers_license_status", query); - socket.on("bot_updated_drivers_license_status", (res) => { - if (!res.success) return message.channel.send(`Failed to update license of \`${args[1]} ${args[2]}\` ${message.author}`); - message.channel.send(`Successfully updated license of \`${args[1]} ${args[2]}\` ${message.author}`); - socket.disconnect(); - return; - }); - }); - } - - async joinCommunity(message, args) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (args.length==0) return message.channel.send(`You must provide a \`Community Code\` ${message.author}`); - let myReq = { - userID: user._id, - communityCode: args[0] - }; - const socket = io.connect(this.config.socket); - socket.emit('bot_join_community', myReq); - socket.on('bot_joined_community', (data) => { - socket.disconnect() - if (data.error) { - return message.channel.send(`${data.error} ${message.author}`); - } - return message.channel.send(`Successfully joined the community \` ${data.commName} \` ${message.author}`) - }); - } - - async leaveCommunity(message) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - let myReq = { - userID: user._id - }; - const socket = io.connect(this.config.socket); - socket.emit('bot_leave_community', myReq); - socket.on('bot_left_community', (data) => { - socket.disconnect() - if (data.error) { - return message.channel.send(`${data.error} ${message.author}`); - } - return message.channel.send(`${data.message} ${message.author}`) - }); - } - - async community(message) { - let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); - if (!user) return message.channel.send(`You are not logged in ${message.author}`); - if (user.user.activeCommunity==null) return message.channel.send(`You are not in a community ${message.author}`); - let community = await this.dbo.collection("communities").findOne({_id:ObjectId(user.user.activeCommunity)}).then(community => community); - if (!community) return message.channel.send(`Community not found ${message.author}`); - return message.channel.send(`You are in the community \`${community.community.name}\` ${message.author}`); - } - - async setRole(message, args) { - if (args.length==0) return message.channel.send(`You must provide a role ${message.author}`); - let roleid = args[0].replace('<@&', '').replace('>', ''); - let role = message.guild.roles.cache.find(x => x.id == roleid); - if (role == undefined) { - return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`); - } else { - let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - if (guild.server.allowedRole!=undefined&&guild.server.allowedRoles.includes(roleid)) return message.channel.send(`The role ${args[0]} has already been added ${message.author}`); - this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) { - if (err) throw err; - return message.channel.send(`Successfully added ${args[0]} to allowed roles ${message.author}`); - }); - } - } - - async removeRole(message, args) { - if (args.length==0) return message.channel.send(`You must provide a role ${message.author}`); - let roleid = args[0].replace('<@&', '').replace('>', ''); - let role = message.guild.roles.cache.find(x => x.id == roleid); - if (role == undefined) { - return message.channel.send(`Uh Oh! The role ${args[0]} connot be found.`); - } else { - let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - 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}`); - for (let i = 0; i < guild.server.allowedRoles.length; i++) { - if (guild.server.allowedRoles[i]==roleid) { - if ((guild.server.allowedRoles.length-1)==0) { - this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":false}},function(err, res) { - if (err) throw err; - return message.channel.send(`Successfully removed ${args[0]} from allowed roles ${message.author}! There are no more allowed roles.`); - }); - } else if ((guild.server.allowedRoles.length-1)>0) { - this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$pull:{"server.allowedRoles":roleid}},function(err, res) { - if (err) throw err; - return message.channel.send(`Successfully removed ${args[0]} from allowed roles ${message.author}`); - }); - } - } - } - } - } - - async roles(message) { - let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - if (guild.server.hasCustomRoles==false) { - return message.channel.send('There are no roles set for the bot.'); - } - - let roles = "Allowed Roles:"; - for (let i = 0; i < guild.server.allowedRoles.length; i++) { - if (guild.server.allowedRoles[i] == undefined) break; - roles += `\n<@&${guild.server.allowedRoles[i]}>`; - } - return message.channel.send(roles); - } - - async setChannel(message, args) { - if (args.length==0) return message.channel.send(`You must provide a channel ${message.author}`); - 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.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}`); - 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; - return message.channel.send(`Successfully added ${args[0]} to allowed channels ${message.author}`); - }); - } - - async removeChannel(message, args) { - if (args.length==0) return message.channel.send(`You must provide a channel ${message.author}`); - let channelid = args[0].replace('<#', '').replace('>', ''); - 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(`Successfully 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(`Successfully 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 togglePingOnPanic(message, args) { - if (args.length==0) return message.channel.send(`You must provide a \`Ping On Role Status\` and a \`role\` to ping ${message.author}`); - if (args[0]=="false") { - // disable ping on panic and remove ping role - this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.pingOnPanic":false,"server.pingRole":null}},function(err, res) { - if (err) throw err; - return message.channel.send(`Successfully disabled ping role on panic ${message.author}`); - }); - } else if (args[0]=="true") { - if (!args[1]) return message.channel.send(`You must provide a \`role\` to ping ${message.author}`); - let roleid = args[1].replace('<@&', '').replace('>', ''); - let role = message.guild.roles.cache.find(x => x.id == roleid); - if (role == undefined) { - return message.channel.send(`Uh Oh! The role ${args[1]} connot be found.`); - } else { - this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.pingRole":roleid,"server.pingOnPanic":true}},function(err, res) { - if (err) throw err; - return message.channel.send(`Successfully set ${args[1]} to be pinged on panic ${message.author}`); - }); - } - } else return message.channel.send(`\`${args[0]}\` is an invalid status, use \`true\` or \`false\` ${message.author}`); - } - - async getPingOnPanicStatus(message) { - let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild); - return message.channel.send(`Current Ping on Panic Status: ${guild.server.pingOnPanic} ${message.author}`); - } -} - -module.exports = {Commands}; \ No newline at end of file diff --git a/commands/checkStatus.js b/commands/checkStatus.js index 68dc1a6..d4a81e2 100644 --- a/commands/checkStatus.js +++ b/commands/checkStatus.js @@ -16,7 +16,10 @@ module.exports = { * @param {string[]} args * @param {*} param3 */ - run: async (client, message, args) => { + run: async (client, message, args, { GuildDB }) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); if (user.user.activeCommunity == null) return message.channel.send(`You must join a community to use this command.`); @@ -56,6 +59,9 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } + + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in.`); diff --git a/commands/firearmSearch.js b/commands/firearmSearch.js index df5a5bf..c763eee 100644 --- a/commands/firearmSearch.js +++ b/commands/firearmSearch.js @@ -18,6 +18,9 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); if (args.length==0) return message.channel.send(`You are missing a \`Serial Number\`.`); @@ -80,6 +83,9 @@ module.exports = { return interaction.send(`You are not allowed to use the bot in this channel.`); } + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in.`); let data = { diff --git a/commands/nameSearch.js b/commands/nameSearch.js index 565950b..f897ed0 100644 --- a/commands/nameSearch.js +++ b/commands/nameSearch.js @@ -18,6 +18,9 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args, { GuildDB }) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + if (GuildDB.customRoleStatus) { let userRoles = []; // TODO: get user roles let hasRole = await client.hasRole(userRoles, GuildDB.serverID); @@ -144,6 +147,10 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } + + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in.`); let data; diff --git a/commands/panic.js b/commands/panic.js index a269811..142cfa9 100644 --- a/commands/panic.js +++ b/commands/panic.js @@ -17,6 +17,9 @@ module.exports = { * @param {*} param3 */ run: async (client, message) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); @@ -72,6 +75,9 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } + + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in.`); diff --git a/commands/plateSearch.js b/commands/plateSearch.js index 129f478..f7dcfb4 100644 --- a/commands/plateSearch.js +++ b/commands/plateSearch.js @@ -18,6 +18,9 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); if (args.length==0) return message.channel.send(`You are missing a \`Plate #\`.`); @@ -88,6 +91,9 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } + + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in.`); diff --git a/commands/updateLicense.js b/commands/updateLicense.js index 7bc683b..2a7d251 100644 --- a/commands/updateLicense.js +++ b/commands/updateLicense.js @@ -18,6 +18,9 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in.`); if (args.length==0) return message.channel.send(`You must provide a \`First Name\`, \`Last Name\`, \`DOB\`(yyyy-mm-dd).`); @@ -149,6 +152,9 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } + + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in.`); diff --git a/commands/updateStatus.js b/commands/updateStatus.js index 0b0f253..47ce51b 100644 --- a/commands/updateStatus.js +++ b/commands/updateStatus.js @@ -18,6 +18,9 @@ module.exports = { * @param {*} param3 */ run: async (client, message, args) => { + let useCommand = await client.verifyUseCommand(GuildDB.serverID, message.member.roles.cache, false); + if (!useCommand) return message.channel.send("You don't have permission to use this command"); + let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', '10-41', '10-42']; let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); if (!user) return message.channel.send(`You are not logged in ${message.author}`); @@ -79,6 +82,9 @@ module.exports = { return interaction.send(`You are not allowed to use the bot in this channel.`); } + let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles, true); + if (!useCommand) return interaction.send("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); if (!user) return interaction.send(`You are not logged in ${message.author}`); if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); diff --git a/structures/LinesPoliceCadBot.js b/structures/LinesPoliceCadBot.js index b365d6f..42a1307 100644 --- a/structures/LinesPoliceCadBot.js +++ b/structures/LinesPoliceCadBot.js @@ -1,5 +1,4 @@ const { Collection, Client, MessageEmbed } = require('discord.js'); -const CommandHandler = require('../commands').Commands; const MongoClient = require('mongodb').MongoClient; const Logger = require("../util/Logger"); const io = require('socket.io-client'); @@ -152,14 +151,21 @@ class LinesPoliceCadBot extends Client { }); } - async checkRoleStatus(roles, serverID) { + async checkRoleStatus(rolesCache, serverID, isList) { let hasRole = false; let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":serverID}).then(guild => guild); // 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++) { - if (roles.includes(guild.server.allowedRoles[i])) { - hasRole = true - break + if (!isList) { + 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; @@ -207,6 +213,22 @@ class LinesPoliceCadBot extends Client { return guildData; } + /* + This command is to verify a user + has the correct role to use a + command ie. has cop role to use + name-search + */ + async verifyUseCommand(serverID, rolesCache, isList) { + let { customRoleStatus } = await this.GetGuild(serverID) + if (customRoleStatus) { + let hasRole = await this.checkRoleStatus(rolesCache, serverID, isList); + if (hasRole) { + return true // User has role, can use command + } else return false // User does not have role, can't use command + } else return true // There is no role limits + } + log(Text) { this.logger.log(Text); } @@ -227,242 +249,6 @@ class LinesPoliceCadBot extends Client { build() { this.login(this.config.Token); } - - // main() { - // client.on('ready', () => { - // console.log(`Logged in as ${client.user.tag}`); - // }); - - // // Basic Commands - // client.on('message', async (message) => { - // let { prefix, channelId, customRoleStatus, customChannelStatus, allowedChannels } = await this.getGuildPresets(message); - // if (!message.content.startsWith(prefix) || message.author.bot) return; - - // if (customChannelStatus==true&&!allowedChannels.includes(message.channel.id)) { - // 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 command = args.shift().toLowerCase(); - - // // Valid Statuses Embed - // const validStatus = new MessageEmbed() - // .setColor('#0099ff') - // .setTitle('Lines Police CAD') - // .setURL('https://www.linespolice-cad.com/') - // .setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') - // .setDescription('Valid Statuses') - // .addFields( - // { name: 'Statuses:', value: ` - // 10-8 | \`On Duty\` - // 10-7 | \`Off Duty\` - // 10-6 | \`Busy\` - // 10-11 | \`Traffic Stop\` - // 10-23 | \`Arrive on Scene\` - // 10-97 | \`In Route\` - // 10-15 | \`Subject in Custody\` - // 10-70 | \`Foot Pursuit\` - // 10-80 | \`Vehicle Pursiut\` - // ` - // } - // ) - - // // Help Embed - // const help = new MessageEmbed() - // .setColor('#0099ff') - // .setTitle('**Commands:**') - // .setURL(client.config.SupportServer) - // .setAuthor('LPS Website & Bot Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t') - // .setDescription('Lines Police CAD Bot Commands') - // .addFields({ - // name: `**__Bot Commands:__**`, - // value: ` - // **${prefix}help** - \`Displays this help page\` - // **${prefix}stats** - \`Displays current Bot statistics\` - // **${prefix}ping** - \`Responds with Pong to check Bot responce\` - // `, - // inline: false - // }, - // { - // name: `**__LPC Commands (1/2):__**`, - // value: ` - // **${prefix}login** - \`Redirects you to connect your discord to LPC(DM only)\` - // **${prefix}logout** - \`Logs out of your current logged in account\` - // **${prefix}validStatus** - \`Shows list of valid statuses to updade to\` - // **${prefix}checkStatus** - \`Check your own or other status\` - // **${prefix}updateStatus** - \`Updates your status\` - // **${prefix}account** - \`returns logged in account\` - // **${prefix}penalCodes** - \`Provides Link to penal codes\` - // **${prefix}namedb** - \`Searches for Civilian by Name\` - // **${prefix}platedb** - \`Searches for Vehicle by Licence Plate #\` - // **${prefix}firearmdb** - \`Searches for Firearms by Serial #\` - // **${prefix}panic** - \`Enables/Disables your panic button\` - // **${prefix}license** - \`Revoke/Reinstate License\` - // `, - // inline: true - // }, - // { - // name: `**__LPC Command (2/2):__**`, - // value: ` - // **${prefix}roles** - \`Shows a list of allowed roles\` - // **${prefix}channels** - \`Shows a list of allowed channels\` - // **${prefix}joincommunity** - \`Joins a community with the given code\` - // **${prefix}leavecommunity** - \`Leaves your current active community\` - // **${prefix}community** - \`Returns the name of the Community your currenty in\` - // `, - // inline: false - // }, - // { - // name: `**__Admin Commands:__**`, - // value: ` - // **${prefix}setPrefix** - \`Sets new prefix\` - // **${prefix}setChannel** - \`Adds channel to list of allowed channels\` - // **${prefix}removeChannel** - \`Removes channel from list of allowed channels\` - // **${prefix}setRole** - \`Adds role to list of allowed roles\` - // **${prefix}removeRole** - \`Removes role from list of allowed roles\` - // **${prefix}togglePingOnPanic** - \`Enable/disable ping role on panic\` - // `, - // inline: false - // }) - - // const stats = new MessageEmbed() - // .setColor('#0099ff') - // .setTitle("Current LPC-Bot Statistics") - // .setURL(client.config.SupportServer) - // .addField(" \u200B ", "**Channels** : ` " + `${client.channels.cache.size}` + " `") - // .addField(" \u200B ", "**Servers** : ` " + `${client.guilds.cache.size}` + " `") - // .addField(" \u200B ", "**Users** : ` " + `${client.users.cache.size}` + " `") - - // if (command == 'ping') return message.channel.send('Pong!'); - // if (command == 'help') return message.channel.send(help); - // if (command == 'stats') return message.channel.send(stats); - // if (command == 'setprefix') { - // if (message.channel.type=="dm") return message.author.send(`You cannot set a prefix 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}`); - // this.commandHandler.newPrefix(message, args); - // } - // if (command == 'setchannel') { - // if (message.channel.type=="dm") return message.author.send(`You cannot set 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}`); - // this.commandHandler.setChannel(message, args); - // } - // if (command == 'removechannel') { - // 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}`); - // this.commandHandler.removeChannel(message, args); - // } - // if (command == 'setrole') { - // if (message.channel.type=="dm") return message.author.send(`You cannot set a role 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}`); - // this.commandHandler.setRole(message, args); - // } - // if (command == 'removerole') { - // if (message.channel.type=="dm") return message.author.send(`You cannot remove a role 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}`); - // this.commandHandler.removeRole(message, args); - // } - // if (command == 'togglepingonpanic') { - // if (message.channel.type=="dm") return message.author.send(`You cannot remove a role 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}`); - // this.commandHandler.togglePingOnPanic(message, args); - // } - // if (command == 'roles') { - // if (message.channel.type=="dm") return message.author.send(`You cannot see allowed roles in a dm ${message.author}`); - // this.commandHandler.roles(message); - // } - // if (command == 'channels') { - // if (message.channel.type=="dm") return message.channel.send(`You cannot see allowed channels in a dm ${message.author}`); - // this.commandHandler.channels(message); - // } - // if (command == 'pingonpanic') { - // if (message.channel.type=="dm") return message.channel.send(`You cannot see allowed channels in a dm ${message.author}`); - // this.commandHandler.getPingOnPanicStatus(message); - // } - - // // Login - // if (command == 'login') { - // if (message.channel.type=="text") return message.channel.send(`You must direct message me to use this command ${message.author}`); - // this.commandHandler.remoteLogin(message, args); - // } - // if (command == 'logout') this.commandHandler.remoteLogout(message); - // if (command == 'validstatus') return message.channel.send(validStatus); - // if (command == 'checkstatus') { - // if (customRoleStatus) { - // let hasRole = await this.commandHandler.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.checkStatus(message, args); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}`); - // } else this.commandHandler.checkStatus(message, args); - // } - // if (command == 'updatestatus') { - // if (customRoleStatus) { - // let hasRole = await this.commandHandler.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.updateStatus(message, args, prefix); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}`); - // } else this.commandHandler.updateStatus(message, args, prefix); - // } - // if (command == 'account') this.commandHandler.account(message); - // if (command == 'penalcodes') return message.channel.send('https://www.linespolice-cad.com/penal-code'); - // if (command == 'namedb') { - // if (customRoleStatus) { - // let hasRole = await this.commandHandler.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.nameSearch(message, args); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}`); - // } else this.commandHandler.nameSearch(message, args); - // } - // if (command == 'platedb') { - // if (customRoleStatus) { - // let hasRole = await this.commandHandler.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.plateSearch(message, args); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}`); - // } else this.commandHandler.plateSearch(message, args); - // } - // if (command == 'firearmdb') { - // if (customRoleStatus) { - // let hasRole = await this.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.firearmSearch(message, args); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}`); - // } else this.commandHandler.firearmSearch(message, args); - // } - // if (command == 'panic') { - // if (customRoleStatus) { - // let hasRole = await this.commandHandler.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.enablePanic(message); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}`); - // } else this.commandHandler.enablePanic(message); - // } - // if (command == 'license') { - // if (customRoleStatus) { - // let hasRole = await this.commandHandler.checkRoleStatus(message); - // if (hasRole) { - // this.commandHandler.updateLicense(message, args); - // } else return message.channel.send(`You don't have permission to use this command ${message.author}! `); - // } else this.commandHandler.updateLicense(message, args); - // } - // if (command == 'joincommunity') this.commandHandler.joinCommunity(message, args); - // if (command == 'leavecommunity') this.commandHandler.leaveCommunity(message); - // if (command == 'community') this.commandHandler.community(message); - - // // Dev Commands (not visible in help) && easter egg commands - // if (command == 'version') message.channel.send(`**LPS-BOT Version : ${this.dev}-${this.config.version}**`) - // if (command == 'whatisthemeaningoflife') message.channel.send('42'); - // if (command == 'whatareyou' || command == 'whoareyou') message.channel.send('Im your friendly neighborhood Lines Police CAD Bot'); - // if (command == 'whocreatedyou') message.channel.send('Lines Police CAD Developer McDazzzled | https://github.com/SowinskiBraeden'); - // if (command == 'pingserver') { - // const socket = io.connect(this.config.socket); - // socket.emit('botping', {message:'hello there'}); - // socket.on('botpong', (data) => { - // console.log(data); - // message.channel.send(`Debug: Server responded`) - // socket.disconnect(); - // }); - // } - // }); - // } } module.exports = LinesPoliceCadBot; \ No newline at end of file From 63667c30b89b97a89fa2d41edb162698627f66f1 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Mar 2022 15:33:40 -0700 Subject: [PATCH 28/29] update configs --- config/beta-config.js | 8 ++++---- config/config.js | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/beta-config.js b/config/beta-config.js index 736fb5c..dc756bc 100644 --- a/config/beta-config.js +++ b/config/beta-config.js @@ -1,13 +1,13 @@ module.exports = { Dev: "DEVELOPMENT", - Version: "2.0.0 Beta", + Version: "3.0.0 Beta", Admins: ["362791661274660874"], // Admins of the bot defaultPrefix: "?", socket: "https://police-cad-dev.herokuapp.com/", - SupportServer: client.config.SupportServer, //Support Server Link + SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link Token: process.env.TOKEN || "", //Discord Bot Token Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes - IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png", + IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-cad.png", EmbedColor: "#0099ff", Permissions: 2205281600, Website: "https://linespolice-cad.com", @@ -19,6 +19,6 @@ module.exports = { Presence: { status: "online", // You can show online, idle, and dnd name: "GTA V", // The message shown - type: "Playing", // PLAYING, WATCHING, LISTENING, STREAMING + type: "PLAYING", // PLAYING, WATCHING, LISTENING, STREAMING }, } diff --git a/config/config.js b/config/config.js index aba7568..a4fdd92 100644 --- a/config/config.js +++ b/config/config.js @@ -1,13 +1,13 @@ module.exports = { Dev: "PRODUCTION", - Version: "2.0.0", + Version: "3.0.0", Admins: ["362791661274660874"], // Admins of the bot defaultPrefix: "?", - socket: "https://www.linespolice-cad.com/", - SupportServer: client.config.SupportServer, //Support Server Link + socket: "https://linespolice-cad.com/", + SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link Token: process.env.TOKEN || "", //Discord Bot Token Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes - IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png", + IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-cad.png", EmbedColor: "#0099ff", Permissions: 2205281600, Website: "https://linespolice-cad.com", @@ -19,6 +19,6 @@ module.exports = { Presence: { status: "online", // You can show online, idle, and dnd name: "GTA V", // The message shown - type: "Playing", // PLAYING, WATCHING, LISTENING, STREAMING + type: "PLAYING", // PLAYING, WATCHING, LISTENING, STREAMING }, } From 47fec8ccb03098b2b9c5bd97a480341ed7ab7cac Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Thu, 17 Mar 2022 15:34:40 -0700 Subject: [PATCH 29/29] update initializers --- beta.js | 10 +++++----- index.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/beta.js b/beta.js index 1f6a26a..2b8f5e8 100644 --- a/beta.js +++ b/beta.js @@ -1,6 +1,6 @@ -const LinesPoliceCadBot = require('./LPS'); -const client = new LinesPoliceCadBot(require('./config/beta-config')); +const LinesPoliceCadBot = require('./structures/LinesPoliceCadBot'); +const config = require('./config/beta-config'); +const { Intents } = require('discord.js'); -client.build(); - -module.exports = client; +let client = new LinesPoliceCadBot({ intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]}, config); +client.build() diff --git a/index.js b/index.js index 112bfc2..a8f44d5 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ -const LinesPoliceCadBot = require('./LPS'); -const client = new LinesPoliceCadBot(require('./config/config')); +const LinesPoliceCadBot = require('./structures/LinesPoliceCadBot'); +const config = require('./config/config'); +const { Intents } = require('discord.js'); -client.build(); - -module.exports = client; +let client = new LinesPoliceCadBot({ intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]}, config); +client.build()