Skip to content

Commit

Permalink
0.11.1 Release (#10)
Browse files Browse the repository at this point in the history
* Add `choices` and `help` to Command args

- `choices` will compare the parsed arg value to itself
- `help` will replace any kind of error message produced while parsing the arg or while comparing the arg in `choices`
-> `:error` is replaced with the error message inside of the string
-> `{help: 'Some error occured: :error'}`, `:error` will be replaced with the actual error message (like if it failed to parse to a number)

- Replace `Command.args` with `Command.argParser` and add a setter to set via `Command.args = [arg, arg]`
- Add a bunch of `setX` commands to the Command object

* Add positional arg support and `required` parameter

* Update package.json

* Add link escaping to Markup Tools

* add typings for `once` and `subscribe` on the main client objects

* Fix differences in some objects on update

- Fix `guildMemberUpdate` always having `{roles}` in the differences object
- `guildMemberUpdate` can have a null `differences`, often, because it might be a user update that was announced via `usersUpdate`
- `messageUpdate`, `attachments`, `embeds`, `mentions` should have better checks for being in the differences params
-

* Update `detritus-utils` version

* Fix codestring escaping in the markup tool

* Fix `embed.size` not counting author name

- Fix `Embed.size` not counting author name
- Add `MessageEmbed.size` and `MessageEmbed.length`

* apparently forgot to put `mute` on voice states..

* Fix audit log options not parsing into int

* Add `_new` properties to guild, overwrite, role

* Add `activity` getter to message party invite

- Add ability to set prefixes through a setter on the command object

* cache subsequent `Command.names` calls

* Add some performance fixes to `PRESENCE_UPDATE` handler

- No longer diff the entire presence if only `USERS_UPDATE` is being listened to
- Don't check `hasDifference` based off activity id since it could be `custom` or `spotify:1` which won't make it unique

* Update to version 0.11.1
  • Loading branch information
cakedan authored Aug 20, 2020
1 parent 8dc4d2c commit 6430a9a
Show file tree
Hide file tree
Showing 29 changed files with 1,855 additions and 286 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,9 @@ are provided through [`detritus-client-rest`](https://github.com/detritusjs/clie
Detritus is operated through the Clients classes:

- `ShardClient` provides a base client for connecting to the Discord API and receiving events.
- `CommandClient` wraps over the `ShardClient` to provide support for bot commands.
- `ClusterClient` provides a client that creates `ShardClient` classes inside of it for easier sharding
- `CommandClient` wraps over the `ClusterClient` or `ShardClient` to provide support for bot commands.
- `ClusterManager` provides a manager that'll spawn in multiple `ClusterClient` processes for big shardings

More Examples are provided under the [`examples/`](https://github.com/detritusjs/client/tree/master/examples)
directory.
Expand All @@ -36,7 38,7 @@ const { CommandClient } = require('detritus-client');
//
// Tokens should be considered secrets and stored in a configuration file that is not
// part of your version control system, or an environment variable.
// By default, the CommandClient will use the ShardClient unless you use the ClusterManager to spawn processes
// By default, the CommandClient will use the ClusterClient
// The ShardClient/ClusterClient will be under CommandClient.client as soon as you create the object
const token = '';
const commandClient = new CommandClient(token, {
Expand Down
17 changes: 17 additions & 0 deletions examples/command-classes/basecommand.js
Original file line number Diff line number Diff line change
@@ -0,0 1,17 @@
const { Command } = require('../../lib');


// Use this to have just one class handle all the type errors
class BaseCommand extends Command.Command {
triggerTypingAfter = 1000;

onTypeError(context, args, errors) {
const description = ['ERRORS'];
for (let key in errors) {
description.push(`**${key}**: ${errors[key].message}`);
}
return context.editOrReply(description.join('\n'));
}
}

module.exports.BaseCommand = BaseCommand;
27 changes: 27 additions & 0 deletions examples/command-classes/roll.js
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
const { BaseCommand } = require('./basecommand');

class RollCommand extends BaseCommand {
constructor(client) {
super(client);
this.name = 'roll';

// choices will be [1, 2, ..., 20]
this.choices = Array.from({length: 20}).map((v, key) => key 1);
this.default = 1;
this.help = 'Can only roll 1 to 20 times';
this.label = 'amount';
this.type = Number;
}

run(context, args) {
const { amount } = args;

const rolls = [];
for (let i = 0; i < amount; i ) {
rolls.push(Math.round(Math.random() * 100));
}
return context.editOrReply(`Rolls: ${rolls.join(', ')}`);
}
}

module.exports = RollCommand;
22 changes: 22 additions & 0 deletions examples/command-classes/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 1,22 @@
const { BaseCommand } = require('./basecommand');

class TagCommand extends BaseCommand {
constructor(client) {
super(client);
this.name = 'tag';

// tag <name> <...content>`
// will parse `tag golf cake and eggs` as `{name: 'golf', content: 'cake and eggs'}`
// will parse `tag 'golf cake' and eggs as `{name: 'golf cake', content: 'and eggs'}`
this.type = [
{label: 'name', help: 'A tag name is required', required: true},
{label: 'content', consume: true},
];
}

run(context, args) {
return context.editOrReply(`tag \`${args.name}\` with ${(args.content) ? `content as \`${args.content}\`` : 'no content'}`);
}
}

module.exports = TagCommand;
26 changes: 26 additions & 0 deletions examples/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@ const client = new CommandClient(token, {
prefix,
});

client.addMultipleIn('/command-classes');
client.addMultipleIn('/some-directory');

client.add({
Expand Down Expand Up @@ -115,6 116,31 @@ client.add({
},
});

client.add({
name: 'color',
choices: ['blue', 'red'],
help: 'Choose from `blue` or `red`',
type: (value) => value.toLowerCase(),
run: (context, args) => {
const { color } = args;
switch (color) {
case 'blue': {
return context.editOrReply('I love blue!');
};
case 'red': {
return context.editOrReply('I kinda like red');
};
}
},
onTypeError: (context, args, errors) => {
const description = ['ERRORS'];
for (let key in errors) {
description.push(`**${key}**: ${errors[key]}`);
}
return context.editOrReply(description.join('\n'));
},
});

(async () => {
await client.run();
// Client fetched the gateway url, got the ready payload, and filled the applications cache
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 4,13 @@
"url": "https://github.com/detritusjs/client/issues"
},
"dependencies": {
"detritus-client-rest": "^0.8.0",
"detritus-client-socket": "^0.6.0",
"detritus-utils": "^0.2.6"
"detritus-client-rest": "^0.8.3",
"detritus-client-socket": "^0.6.1",
"detritus-utils": "^0.3.0"
},
"description": "A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.",
"devDependencies": {
"@types/node": "^13.13.14",
"@types/node": "^14.6.0",
"@types/node-fetch": "^2.5.7",
"typedoc": "^0.15.8"
},
Expand Down Expand Up @@ -51,5 51,5 @@
"typedoc": "typedoc ./src"
},
"types": "lib/index.d.ts",
"version": "0.11.0"
"version": "0.11.1"
}
Loading

0 comments on commit 6430a9a

Please sign in to comment.