Skip to content

Commit

Permalink
Adding documentation and deprecating other classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrumsey committed Oct 31, 2018
1 parent e1d2ac2 commit 003eaaa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
84 changes: 46 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Greenkeeper badge](https://badges.greenkeeper.io/maxrumsey/hookcord.svg)](https://greenkeeper.io/)
[![install size](https://packagephobia.now.sh/badge?p=hookcord@1.2.1)](https://packagephobia.now.sh/result?p=hookcord@1.2.1)
<br><br>
[![npm](https://nodei.co/npm/hookcord.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/hookcord/)
[![npm](https://nodei.co/npm/hookcord.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/hookcord/)
<br><br>
# Hookcord
A user-friendly, sleek and fast client used to create and send Discord Webhooks.
Expand All @@ -26,34 +26,42 @@ $ npm i hookcord
## Initialisation
```javascript
var hookcord = require('hookcord');
var Base = hookcord.Base;
var hook = new Base("HOOK_ID/HOOK_SECRET");
var Hook = new hookcord.Hook()
.login('ID', 'SECRET')
.setPayload(payload)
.fire()
.then(function(response) {})
.catch(function(e) {})
```
Or:
```javascript
var hookcord = require('hookcord');
var Base = hookcord.Base;
var hook = new Base("", {'link':'https://custom.link/to/webhook'});
var Hook = new hookcord.Hook()
.setLink('https://abc.com/webhook')
.setPayload(payload)
.fire()
.then(function(response) {})
.catch(function(e) {})
```
## Messages
```javascript
var hookcord = require('hookcord');
var Base = hookcord.Base;

var hook = new Base("HOOK_ID/HOOK_SECRET", {}, {'content':"Hello World!"});
hook.send().then(function(request) {
console.log(request);
});
var Hook = new hookcord.Hook()
.login('ID', 'SECRET')
.setPayload({
'content': 'This displays like a normal message.'
})
.fire()
.then(function(response) {})
.catch(function(e) {})
```
More information is available at the [documentation](https://maxrumsey.xyz/hookcord/?api).
## Embeds
```javascript
var hookcord = require('hookcord');

var Base = hookcord.Base;

var hook = new Base("HOOK_ID/HOOK_SECRET", {}, {
'embeds': [{
var Hook = new hookcord.Hook()
.login('ID', 'SECRET')
.setPayload({'embeds': [{ // .setPayload(hookcord.DiscordJS(embed))
'title': 'Hookcord',
'description': '',
'fields': [{
Expand All @@ -62,28 +70,29 @@ var hook = new Base("HOOK_ID/HOOK_SECRET", {}, {
'inline': true
}],
'timestamp': new Date();
}]
});
hook.send().then(function(request) {
console.log(request);
});
}]})
.fire()
.then(function(response) {})
.catch(function(e) {})
```
Embed documentation is available at [Discord's Documentation](https://discordapp.com/developers/docs/resources/channel#embed-object).
More information is available at the [Hookcord documentation](https://maxrumsey.xyz/hookcord/?api).

## Ratelimits
By default, Hookcord will throw an error if it encounters a ratelimit. You can override this by setting a handler function like this:
```javascript
var Base = require('hookcord').Base;
var hook = new Base("HOOK_ID/HOOK_SECRET", {
handler: function(err) {
console.log('Ratelimit Request Limit: ' + err.limit);
console.log('Remaining Requests: ' + err.remaining);
console.log('Time until Reset: ' + err.reset)
}
}, {
content: 'Hello World!'
})
var hookcord = require('hookcord');
var Hook = new hookcord.Hook()
.login('ID', 'SECRET')
.setOptions({
handler: function(err) {
console.log('Ratelimit Request Limit: ' + err.limit);
console.log('Remaining Requests: ' + err.remaining);
console.log('Time until Reset: ' + err.reset)
}
})
.setPayload({ contents: ':)' })
.fire()
```
It provides the remaining requests allowed (0), the total requests permitted (usually 5) and the time until the Ratelimit resets.

Expand All @@ -93,13 +102,12 @@ More information is available at the [Hookcord documentation](https://maxrumsey.
Hookcord has the ability to parse embeds created via [Discord.JS's RichEmbed](https://discord.js.org/#/docs/main/stable/class/RichEmbed). These parsed embeds can be sent via Hookcord as a Webhook.
```javascript
var hookcord = require('hookcord');
var discord = require('discord.js')

var embed = new discord.RichEmbed();
embed.setTitle('Hi!');
var parsed = hookcord.DiscordJS(embed);

await hookcord.Fire("HOOK_ID/HOOK_SECRET", {}, parsed);
var Hook = new hookcord.Hook()
.login('ID', 'SECRET')
.setPayload(hookcord.DiscordJS(embed))
.fire()
.then(function(response) {})
.catch(function(e) {})
```
If you attempt to parse a file, the file will be removed and the incident will be logged to console.

Expand Down
1 change: 1 addition & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const util = require('./util');
*/
/**
* The base Webhook class.
* @deprecated since version 2.0.0
* @example
* var Base = require('hookcord').Base
*/
Expand Down
7 changes: 5 additions & 2 deletions src/external/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* @returns {WebhookJSON}
* @param {Object} DiscordJSEmbed The {@link https://discord.js.org/#/docs/main/stable/class/RichEmbed|Discord.JS Embed} to pass into the parser.
* @example
* var embed = new Discord.RichEmbed();
* var embed = new require('discord.js').RichEmbed();
* embed.setTitle('Hello!')
* hookcord.Fire("HOOK ID/HOOK SECRET", {}, hookcord.DiscordJS(embed))
* let hook = new hookcord.Hook();
* hook.login('ID', 'SECRET')
* .setPayload(hookcord.DiscordJS(embed));
* .fire()
*/
function DiscordJS(embed) {
if (embed.file) {
Expand Down
1 change: 1 addition & 0 deletions src/fire.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const util = require('./util');
* @param {WebhookOptions} [Options] - Custom options.
* @param {WebhookJSON} Payload - The payload that will be fired to the link.
* @returns {Response}
* @deprecated since version 2.0.0
*/
async function Fire(link, opts = {}, payload) {
if (!payload) {
Expand Down

0 comments on commit 003eaaa

Please sign in to comment.