Added prefix command (dm and groups)

main
Killian 4 years ago
parent 4a1eeed31c
commit b38a7a99ed

@ -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) => {

@ -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`)
})

@ -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}`);
}
}

@ -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();

@ -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,
}
}));

@ -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,
}
}));

@ -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

Loading…
Cancel
Save