Changed commands

- changed global command syntax to templates
- added ~about and ~bug
pull/36/head
Trivernis 6 years ago
parent 5444089261
commit 43e65e6949

@ -8,6 +8,7 @@ const Discord = require("discord.js"),
args = require('args-parser')(process.argv),
waterfall = require('promise-waterfall'),
sqliteAsync = require('./lib/sqliteAsync'),
globcommands = require('./commands/globalcommands.json'),
authToken = args.token || config.api.botToken,
prefix = args.prefix || config.prefix || '~',
gamepresence = args.game || config.presence;
@ -161,21 +162,21 @@ class Bot {
*/
registerCommands() {
// useless test command
cmd.createGlobalCommand(prefix + 'say', (msg, argv, args) => {
cmd.createGlobalCommand(prefix, globcommands.utils.say, (msg, argv, args) => {
return args.join(' ');
}, [], "Repeats what you say");
});
// adds a presence that will be saved in the presence file and added to the rotation
cmd.createGlobalCommand(prefix + 'addpresence', async (msg, argv, args) => {
cmd.createGlobalCommand(prefix, globcommands.utils.addpresence, async (msg, argv, args) => {
let p = args.join(' ');
this.presences.push(p);
await this.maindb.run('INSERT INTO presences (text) VALUES (?)', [p]);
return `Added Presence \`${p}\``;
}, [], "Adds a presence to the rotation.", 'owner');
});
// shuts down the bot after destroying the client
cmd.createGlobalCommand(prefix + 'shutdown', async (msg) => {
cmd.createGlobalCommand(prefix, globcommands.utils.shutdown, async (msg) => {
try {
await msg.reply('Shutting down...');
logger.debug('Destroying client...');
@ -198,10 +199,10 @@ class Bot {
logger.error(err.message);
logger.debug(err.stack);
}
}, [], "Shuts the bot down.", 'owner');
});
// forces a presence rotation
cmd.createGlobalCommand(prefix + 'rotate', () => {
cmd.createGlobalCommand(prefix, globcommands.utils.rotate, () => {
try {
this.client.clearInterval(this.rotator);
this.rotatePresence();
@ -209,15 +210,15 @@ class Bot {
} catch (error) {
logger.warn(error.message);
}
}, [], 'Force presence rotation', 'owner');
});
// ping command that returns the ping attribute of the client
cmd.createGlobalCommand(prefix + 'ping', () => {
cmd.createGlobalCommand(prefix, globcommands.info.ping, () => {
return `Current average ping: \`${this.client.ping} ms\``;
}, [], 'Returns the current average ping', 'owner');
});
// returns the time the bot is running
cmd.createGlobalCommand(prefix + 'uptime', () => {
cmd.createGlobalCommand(prefix , globcommands.info.uptime, () => {
let uptime = utils.getSplitDuration(this.client.uptime);
return new Discord.RichEmbed().setDescription(`
**${uptime.days}** days
@ -226,14 +227,14 @@ class Bot {
**${uptime.seconds}** seconds
**${uptime.milliseconds}** milliseconds
`).setTitle('Uptime');
}, [], 'Returns the uptime of the bot', 'owner');
});
// returns the numbe of guilds, the bot has joined
cmd.createGlobalCommand(prefix + 'guilds', () => {
cmd.createGlobalCommand(prefix, globcommands.info.guilds, () => {
return `Number of guilds: \`${this.client.guilds.size}\``;
}, [], 'Returns the number of guilds the bot has joined', 'owner');
});
cmd.createGlobalCommand(prefix + 'createUser', (msg, argv) => {
cmd.createGlobalCommand(prefix, globcommands.utils.createUser, (msg, argv) => {
return new Promise((resolve, reject) => {
if (msg.guild) {
resolve("It's not save here! Try again via PM.");
@ -249,7 +250,20 @@ class Bot {
}).catch((err) => reject(err.message));
}
});
}, ['username', 'password', 'scope'], 'Generates a token for a username and returns it.', 'owner');
});
cmd.createGlobalCommand(prefix, globcommands.info.about, () => {
return new Discord.RichEmbed()
.setTitle('About')
.setDescription(globcommands.info.about.response.about_creator)
.addField('Icon', globcommands.info.about.response.about_icon);
});
cmd.createGlobalCommand(prefix, globcommands.utils.bugreport, () => {
return new Discord.RichEmbed()
.setTitle('Where to report a bug?')
.setDescription(globcommands.utils.bugreport.response.bug_report);
});
}
/**

@ -3,11 +3,85 @@
"help": {
"name": "help",
"permission": "all",
"description": "Shows this help command",
"description": "Shows this help command.",
"category": "Utility",
"args": [
"command"
]
},
"say": {
"name": "say",
"permission": "all",
"description": "Says something. ~say [String].",
"category": "Utility"
},
"addpresence": {
"name": "addpresence",
"permission": "owner",
"description": "Adds a presence to presences.",
"category": "Utility"
},
"shutdown": {
"name": "shutdown",
"description": "Shuts the bot down.",
"permission": "owner",
"category": "Utility"
},
"rotate": {
"name": "rotate",
"description": "Forces a presence rotation",
"permission": "owner",
"category": "Utility"
},
"createUser": {
"name": "createUser",
"permission": "owner",
"description": "Creates a new user for the webinterface.",
"category": "Utility",
"args": [
"username",
"password",
"scope"
]
},
"bugreport": {
"name": "bug",
"permission": "all",
"description": "Get info about how to report a bug",
"category": "Utility",
"response": {
"bug_report": "Please report your bugs [here](https://github.com/Trivernis/discordbot.js/issues)"
}
}
},
"info": {
"about": {
"name": "about",
"permission": "all",
"description": "Shows information about this bot.",
"category": "Info",
"response": {
"about_icon": "This icon war created by [blackrose14344](https://www.deviantart.com/blackrose14344). \n [Original](https://www.deviantart.com/blackrose14344/art/2B-Chi-B-685771489)",
"about_creator": "This bot was created by Trivernis. More about this bot [here](https://github.com/Trivernis/discordbot.js)."
}
},
"ping": {
"name": "ping",
"permission": "owner",
"description": "Answers with the current average ping of the bot.",
"category": "Info"
},
"uptime": {
"name": "uptime",
"permission": "owner",
"description": "Answers with the current uptime of the bot.",
"category": "Info"
},
"guilds": {
"name": "guilds",
"permission": "owner",
"description": "Answers with the number of guilds the bot has joined",
"category": "Info"
}
}
}
}

@ -183,21 +183,24 @@ exports.setLogger = function (newLogger) {
/**
* Creates a global command that can be executed in every channel.
* @param command
* @param prefix
* @param template
* @param call
* @param args
* @param description
* @param role
*/
exports.createGlobalCommand = function (command, call, args, description, role) {
globCommands[command] = {
'args': args || [],
'description': description,
exports.createGlobalCommand = function (prefix, template, call) {
if (!template.name) {
logger.debug(`Name of command template is null or undef. Failed to create command.`);
return;
}
globCommands[prefix + template.name] = {
'args': template.args || [],
'description': template.description,
'callback': call,
'role': role,
'name': command
'role': template.permission,
'name': template.name,
'category': template.category || 'Other'
};
logger.debug(`Created global command: ${command}, args: ${args}`);
logger.debug(`Created global command: ${prefix + template.name}, args: ${template.args}`);
};
@ -215,7 +218,7 @@ exports.parseMessage = function (msg) {
*/
exports.init = function (prefix) {
logger.verbose("Created help command");
this.createGlobalCommand(((prefix || config.prefix) + 'help'), (msg, kwargs) => {
this.createGlobalCommand((prefix || config.prefix), gcmdTempl.utils.help, (msg, kwargs) => {
if (kwargs.command) {
let cmd = kwargs.command;
if (cmd.charAt(0) !== prefix)
@ -244,7 +247,7 @@ exports.init = function (prefix) {
helpEmbed.setDescription(description);
return helpEmbed;
}
}, ['command'], "Shows this help.");
});
};
function processCommand(cmd, msg, content, returnFunction) {

Loading…
Cancel
Save