From 2c1d15cfc4ebb486b43c33db22bb5e3f817e3af2 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 8 Mar 2022 13:27:23 -0800 Subject: [PATCH] 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;