diff --git a/Commands/Bot/eval.js b/Commands/Bot/eval.js index ea95349..4363e39 100644 --- a/Commands/Bot/eval.js +++ b/Commands/Bot/eval.js @@ -1,11 +1,11 @@ -const Command = require("../../Structure/Command.js"); +const Command = require(`../../Structure/Command.js`); module.exports = class extends Command { constructor(client) { super(client, { - name: "eval", - description: "Eval a js code.", - category: "Bot", + name: `eval`, + description: `Eval a js code.`, + category: `Bot`, enabled: true, aliases: [], cooldown: 3, @@ -14,12 +14,12 @@ module.exports = class extends Command { } async run(message, args, data) { - if (parseInt(message.author.id) !== parseInt(data.config.ownerID)) return message.chat.sendMessage("You do not have the permission to use this command") + if (parseInt(message.author.id) !== parseInt(data.config.ownerID)) return message.chat.sendMessage(`You do not have the permission to use this command.`) let result = new Promise((resolve) => resolve(eval(args.join(` `)))); return result.then((output) => { - if (typeof output !== "string") { - output = require("util").inspect(output, { depth: 0 }); + if (typeof output !== `string`) { + output = require(`util`).inspect(output, { depth: 0 }); } message.chat.sendMessage(output) }).catch((err) => { diff --git a/Commands/Bot/ping.js b/Commands/Bot/ping.js index fd61fc1..627d2c9 100644 --- a/Commands/Bot/ping.js +++ b/Commands/Bot/ping.js @@ -1,20 +1,20 @@ -const Command = require("../../Structure/Command.js"); +const Command = require(`../../Structure/Command.js`); module.exports = class extends Command { constructor(client) { super(client, { - name: "ping", - description: "Return the bot ping.", - category: "Bot", + name: `ping`, + description: `Return the bot ping.`, + category: `Bot`, enabled: true, - aliases: ["latency"], + aliases: [`latency`], cooldown: 3, dmOnly: false, }); } async run(message, args) { - message.chat.sendMessage('Fetching ping...').then(m => { + message.chat.sendMessage(`Fetching ping...`).then(m => { m.delete(); message.chat.sendMessage(`My ping is currently at ${(m.timestamp - message.timestamp) / 1000}ms\nI use ${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)}mb of RAM`) }) diff --git a/Commands/Bot/prefix.js b/Commands/Bot/prefix.js new file mode 100644 index 0000000..4f9f53d --- /dev/null +++ b/Commands/Bot/prefix.js @@ -0,0 +1,36 @@ +const Command = require(`../../Structure/Command.js`); + +module.exports = class extends Command { + constructor(client) { + super(client, { + name: `prefix`, + description: `Configure the bot prefix.`, + category: `Bot`, + enabled: true, + aliases: [], + cooldown: 3, + dmOnly: false, + }); + } + + async run(message, args, data) { + if (message.chat.isGroup && !message.chat.adminUserIDs.includes(parseInt(message.author.id))) return message.chat.sendMessage(`You do not have the permission to use this command.`); + let prefix = args[0]; + if(!prefix){ + return message.chat.sendMessage(`Please specify an argument.`); + } + if(prefix.length > 5){ + return message.chat.sendMessage(`The prefix cannot be longer than 5 characters.`); + } + + if (message.chat.isGroup) { + data.groups.prefix = prefix; + data.groups.save(); + } else { + data.users.prefix = prefix; + data.users.save(); + } + + message.chat.sendMessage(`The prefix is now: ${prefix}`); + } +} \ No newline at end of file diff --git a/Events/messageCreate.js b/Events/messageCreate.js index aa1189e..50627ff 100644 --- a/Events/messageCreate.js +++ b/Events/messageCreate.js @@ -11,17 +11,20 @@ module.exports = class { if (message.authorID === this.client.user.id) return; message.markSeen(); + let prefix; if (message.chat.isGroup) { const groupMembersData = await this.client.findOrCreateGroupMember({ id: message.author.id, groupID: message.chat.id }); data.groupMembers = groupMembersData; const groupsData = await this.client.findOrCreateGroup({ groupID: message.chat.id }); data.groups = groupsData; + prefix = data.groups.prefix; } else { const usersData = await this.client.findOrCreateUser({ id: message.author.id }); data.users = usersData; + prefix = data.users.prefix; } - let prefixes = this.client.config.defaultPrefix; + let prefixes = prefix || this.client.config.defaultPrefix; if (message.content.indexOf(prefixes) !== 0) return; let args = message.content.slice(prefixes.length).trim().split(/ +/g); let command = args.shift().toLowerCase(); diff --git a/Models/Groups.js b/Models/Groups.js index e3e0517..bdeef5e 100644 --- a/Models/Groups.js +++ b/Models/Groups.js @@ -1,5 +1,6 @@ const mongoose = require(`mongoose`), - Schema = mongoose.Schema; + Schema = mongoose.Schema, + config = require(`../config`); module.exports = mongoose.model(`Groups`, new Schema({ groupID: String, @@ -7,4 +8,8 @@ module.exports = mongoose.model(`Groups`, new Schema({ type: Array, default: [] }, + prefix: { + type: String, + default: config.defaultPrefix, + } })); diff --git a/Models/Users.js b/Models/Users.js index d554f58..1e05d9c 100644 --- a/Models/Users.js +++ b/Models/Users.js @@ -1,5 +1,6 @@ const mongoose = require(`mongoose`), - Schema = mongoose.Schema; + Schema = mongoose.Schema, + config = require(`../config`); module.exports = mongoose.model(`Users`, new Schema({ id: String, @@ -7,4 +8,8 @@ module.exports = mongoose.model(`Users`, new Schema({ type: Array, default: [] }, + prefix: { + type: String, + default: config.defaultPrefix, + } })); diff --git a/README.md b/README.md index 6b0e005..86f190a 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ it means that the bot is ready to be used. 🎉 - !ping: Return the bot ping. - !help: Return the bot commands list. - !eval: Eval a JS code. +- !prefix: Change the bot's prefix for groups or private chats. ## Images