Skip to content

Commit

Permalink
Finishing Up For v1.0.0
Browse files Browse the repository at this point in the history
- Rewriting help and info to be more compact.
- Add command-list function to list all available commands.
- some final cleaning up and structuring.
  • Loading branch information
G3rrus committed Apr 30, 2021
1 parent 170c760 commit 2ecf81a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ to give you some info on how to use each command etc.

## Features
I'll be using `.` as a prefix here in the following examples. Aliases will be ommitted for ease of reading.
* Command Info: `.args-info .command` Gives you some info about the command you pass to it. Don't forget to use the prefix.
* Command List: `.command-list` Prints out a list of all available commands.
* Coin Flip: `.coin-flip` Flips a coin and tells you if it landed heads or tails.
* Dice Roll: `.dice-roll number` Rolls a n-sides dice depending on the `number` you pass as a parameter.
* Random Selector: `.choice-randomizer choice1, choice2, choiceN` Selects one out of n choices that you pass to it each seperated by a `,`.
* Command Info: `.args-info .command` Gives you some info about the command you pass to it. Don't forget to use the prefix.

## Requirements
- [node.js](https://nodejs.org/en/) v16.0.0 or higher
Expand All @@ -24,3 +25,6 @@ I'll be using `.` as a prefix here in the following examples. Aliases will be om
- [How to set up a basic discord bot](https://discordjs.guide/#before-you-begin)
- [node.js 16.0.0 documentation](https://nodejs.org/dist/latest-v16.x/docs/api/)
- [discord.js documentation](https://discord.js.org/#/docs/main/stable/general/welcome)

## Pull Requests and Issues
Honestly if you want to help out with issues or PR properly structured 'enhancements' to this, feel free to do so.
10 changes: 5 additions & 5 deletions commands/help/args-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
const { prefix } = require('../../config.json');

exports.name = 'args-info';
exports.description = 'Gives you info on how to use a specific command.';
exports.description = 'Gives you info on a specific command.';
exports.aliases = ['help', 'info'];
exports.usage = '[command usage #1]\n[command usage #2]';
exports.usage = `${prefix}args-info ${prefix}command`;
exports.cooldown = 2;

const cmdFnc = function(message, args, commands) {
if (!args) return message.channel.send('No parameter was given!');
if (!args) return message.channel.send(`No parameter was given! See \`${prefix}args-info ${prefix}args-info\` for more information.`);

const commandName = args[0].slice(prefix.length, args[0].length).toLowerCase();
const command = commands.get(commandName) || commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return message.channel.send(`Could not find command: ${args[0]}`);
if (!command) return message.channel.send(`Could not find command: ${args[0]}. Use ${prefix}command-list for a list of available commands.`);

return message.channel.send(`Relevant arguments are: ${prefix}${command.name}, ${command.description}, [${command.aliases}], ${command.usage}`);
return message.channel.send(`__**${prefix}${command.name}:**__\n Description: ${command.description}\n Aliases: [${command.aliases}]\n Usage: ${command.usage}`);
};
exports.cmdFnc = cmdFnc;
16 changes: 16 additions & 0 deletions commands/help/command-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// import of command prefix of YOUR choice
const { prefix } = require('../../config.json');
const fncArgsInfo = require('./args-info.js');

exports.name = 'command-list';
exports.description = 'Returns a list of all commands';
exports.aliases = ['commands', 'list'];
exports.usage = `${prefix}command-list`;
exports.cooldown = 2;

const cmdFnc = function(message, _1, commands) {
for (const command of commands) {
fncArgsInfo.cmdFnc(message, [`${prefix}${command[0]}`], commands);
}
};
exports.cmdFnc = cmdFnc;
1 change: 1 addition & 0 deletions commands/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// helpers
exports.argsInfo = require('./help/args-info.js');
exports.commandList = require('./help/command-list.js');

// randomizations
exports.coinFlip = require('./randomization/coin.js');
Expand Down
4 changes: 3 additions & 1 deletion commands/randomization/coin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// import of command prefix of YOUR choice
const { prefix } = require('../../config.json');
const fncRandom = require('../../functions/getRndInt.js');

exports.name = 'coin-flip';
exports.description = 'Flips a coin and tells you if it landed heads or tails.';
exports.aliases = ['coin', 'flip'];
exports.usage = '[command usage #1]\n[command usage #2]';
exports.usage = `${prefix}coin-flip`;
exports.cooldown = 5;

const coin = ['Heads', 'Tails'];
Expand Down
10 changes: 6 additions & 4 deletions commands/randomization/dice.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// import of command prefix of YOUR choice
const { prefix } = require('../../config.json');
const fncRandom = require('../../functions/getRndInt.js');

exports.name = 'dice-roll';
exports.description = 'Rolls a n-sides dice and tells you what it landed on.';
exports.description = 'Rolls a n-sided dice.';
exports.aliases = ['dice', 'roll'];
exports.usage = '[Command usage #1]\n[Command usage #2]';
exports.usage = `${prefix}dice-roll number`;
exports.cooldown = 5;

const cmdFnc = function(message, args) {
if (!args) return message.channel.send('No parameter was given!');
if (!args) return message.channel.send(`No parameter was given! See \`${prefix}args-info ${prefix}dice-roll\` for more information.`);

const max = parseInt(args[0], 10);
if (isNaN(max) || max < 1 || max > Number.MAX_SAFE_INTEGER) {
return message.channel.send('Sorry that is not a valid parameter for a dice roll!');
return message.channel.send(`Sorry that is not a valid parameter for a dice roll! See \`${prefix}args-info ${prefix}dice-roll\` for more information.`);
}
return message.channel.send(`The dice landed on: ${fncRandom.getRndInteger(1, max)}`);
};
Expand Down
10 changes: 6 additions & 4 deletions commands/randomization/rndChoice.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// import of command prefix of YOUR choice
const { prefix } = require('../../config.json');
const fncRandom = require('../../functions/getRndInt.js');

exports.name = 'choice-randomizer';
exports.description = 'Tell you one random selection out of all entries you give to it.';
exports.description = 'Picks one random selection out of all entries you give to it.';
exports.aliases = ['choice', 'random'];
exports.usage = '[Command usage #1]\n[Command usage #2]';
exports.usage = `${prefix}choice-randomizer choice1, choice2, choiceN`;
exports.cooldown = 5;

const cmdFnc = function(message, args) {
if (!args) return message.channel.send('No parameter was given!');
if (!args) return message.channel.send(`No parameter was given! See \`${prefix}args-info ${prefix}choice-randomizer\` for more information.`);

if (args.length < 2) {
return message.channel.send('Not enough entries to make a random choice!');
return message.channel.send(`Not enough entries to make a random choice! See \`${prefix}args-info ${prefix}choice-randomizer\` for more information.`);
}
return message.channel.send(`The choice is: ${args[fncRandom.getRndInteger(0, args.length - 1)]}`);
};
Expand Down

0 comments on commit 2ecf81a

Please sign in to comment.