Skip to content

Commit

Permalink
v1.1.0 release
Browse files Browse the repository at this point in the history
Reade CHANGELOG.md for a detailed Changelog.
  • Loading branch information
SCDerox authored Oct 5, 2021
1 parent 7437b6c commit 16b1af7
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog
## v1.1.0 (October 5, 2021)
* Added support for [`PATCH /webhooks/{webhook.id}/{webhook.token}` Discord-API-Call](https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token): You can now modify the username or avatar of your webhook user
* Added support for [`DELETE /webhooks/{webhook.id}/{webhook.token}` Discord-API-Call](https://discord.com/developers/docs/resources/webhook#delete-webhook-with-token): You can now delete your webhook
* Added support for [`GET https://discord.com/developers/docs/resources/webhook#edit-webhook-message` Discord-API-Call](https://discord.com/developers/docs/resources/webhook#get-webhook-message): You can now fetch an already sent webhook message (including content)
* Added support for [Message-Component-Object](https://discord.com/developers/docs/interactions/message-components#component-object). ⚠ This will only work, if your webhook is owned by an application.

## v1.0.1 (March 13, 2021))
* Fixed bug: The module should *actually* work now.

## v1.0.0 (March 13, 2021)
* 🚀 Initial commit
5 changes: 3 additions & 2 deletions Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class Message {
return true;
}

async edit(content, embeds = [], allowedMentions = {}) {
async edit(content, embeds = [], allowedMentions = {}, components = []) {
const res = await centra(this.webhookUrl + `/messages/${this.id}`, 'PATCH').body({
content: content,
embeds: embeds,
allowed_mentions: allowedMentions
allowed_mentions: allowedMentions,
components
})
.header('Content-Type', 'application/json')
.send('form');
Expand Down
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
* Send webhook messages
* Edit webhook messages
* Delete webhook messages
* Support for custom avatarUrl and username
* Fetch webhook messages
* Delete and edit webhooks
* Support for custom avatarUrl and username per message
* Support for [Embed-Objects](https://discord.com/developers/docs/resources/channel#embed-object)
* Support for [Allowed-Mentions-Object](https://discord.com/developers/docs/resources/channel#allowed-mentions-object)
* Support for [Message-Component-Object](https://discord.com/developers/docs/interactions/message-components#component-object). ⚠ This will only work, if your webhook is owned by an application.

# Install from [NPM](https://www.npmjs.com/package/simple-discord-webhooks)

`$ npm i simple-discord-webhooks --save`

## Changelog
You can find the changelog [here](CHANGELOG.md).

# Example Usage

```js
Expand Down Expand Up @@ -47,13 +53,25 @@ message.edit('Hello there!').then(() => console.log('Edited message'))
* allowedMentions (object, optional):
A [Allowed-Mentions-Object](https://discord.com/developers/docs/resources/channel#allowed-mentions-object)
* tts (boolean, optional): Set to `true` to enable TTS.
* components (array, optional): Array
of [message components](https://discord.com/developers/docs/interactions/message-components#component-object).
⚠ This will only work, if your webhook is owned by an application.
* Returns `Promise<Message>` (with all the values
from [here](https://discord.com/developers/docs/resources/channel#message-object))
* function `edit(name = null, base64Avatar = null)` - Edits the webhook object
* name (string, optional): New username of the webhook
* base64Avatar (base64String (string), optional): [Base64](https://en.wikipedia.org/wiki/Base64) -String of your
image. If you don't know how to use this, please google `Image to Base64 nodejs` or `File to Base 64` if you
have an image file.
* function `fetchMessage(id)` - Fetches a message. Includes content and all parameters returned by Discord.
* id(string): ID of a message send by this webhook
* Returns `Message`
* function `delete()` - Deletes the webhook. Use with caution.
* function `resolveMessageID(messageID)` - Returns a MessageObject of a Message-ID
* messageID(string): ID of a message send by this webhook
* Returns `Message`
* NOTE: You can only get a `Message`-Object with to edit and delete the message - You can not (!) get the
content of it.
content of it. Use `fetchMessage(id)` if you want to fetch content too.

* Class: `Message(messageData, webhookurl)`
* `messageData` (object) has to have a value called `id` with the id of the message in it
Expand All @@ -65,16 +83,20 @@ message.edit('Hello there!').then(() => console.log('Edited message'))
of [Embed-Objects](https://discord.com/developers/docs/resources/channel#embed-object)
* allowedMentions (object, optional):
A [Allowed-Mentions-Object](https://discord.com/developers/docs/resources/channel#allowed-mentions-object)
* components (array, optional): Array
of [message components](https://discord.com/developers/docs/interactions/message-components#component-object).
⚠ This will only work, if your webhook is owned by an application.

* Returns `Promise<Message>` (with all the values
from [here](https://discord.com/developers/docs/resources/channel#message-object))

# Questions or suggestions?

Feel free to send me a DM on Discord: `SCDerox#4645`
Please create [a discussion](https://github.com/SCDerox/simple-discord-webhooks/discussions) on Github.

# Contributing

Feel free to create any issues and PRs in our [github repository](https://github.com/SCDerox/simple-discord-webhooks) if you
want to contribute.
Feel free to create any issues and PRs in our [github repository](https://github.com/SCDerox/simple-discord-webhooks) if
you want to contribute.

© Simon Csaba, 22021 | mail[at]scderox.de
36 changes: 34 additions & 2 deletions Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ class Webhook {
this.avatarUrl = avatarUrl;
}

async send(content, embeds = [], allowedMentions = {}, tts = false) {
async send(content, embeds = [], allowedMentions = {}, tts = false, components = []) {
const res = await centra(this.url + '?wait=true', 'POST').body({
content: content,
username: this.username,
avatar_url: this.avatarUrl,
tts: tts,
embeds: embeds,
allowed_mentions: allowedMentions
allowed_mentions: allowedMentions,
components
})
.header('Content-Type', 'application/json')
.send('form');
Expand All @@ -26,6 +27,37 @@ class Webhook {
return new Message(JSON.parse(res.body.toString()), this.url);
}

async edit(name = null, base64Avatar = null) {
const res = await centra(this.url, 'PATCH').body({
name,
avatar: base64Avatar ? `data:image/jpeg;base64,${base64Avatar}` : null
})
.header('Content-Type', 'application/json')
.send('form');
if (res.statusCode !== 200) {
console.error(`Something went wrong while sending while sending the webhook ${this.url}. Here is the answer from discord: `, res.body.toString());
return false;
}
}

async delete() {
const res = await centra(this.url, 'DELETE').body().send('form');
if (res.statusCode !== 204) {
console.error(`Something went wrong while sending while sending the webhook ${this.url}. Here is the answer from discord: `, res.body.toString());
return false;
}
}

async fetchMessage(id) {
const res = await centra(this.url + `/messages/${id}`, 'GET')
.send('form');
if (res.statusCode !== 200) {
console.error(`Something went wrong while sending while sending the webhook ${this.url}. Here is the answer from discord: `, res.body.toString());
return false;
}
return new Message(JSON.parse(res.body.toString()), this.url)
}

resolveMessageID(messageID) { // YOU CAN NOT GET ANY CONTENT OF A MESSAGE VIA THIS METHOD. YOU CAN *ONLY* USE THIS TO EDIT / DELETE ALREADY SEND MESSAGES
return new Message({id: messageID}, this.url);
}
Expand Down
27 changes: 23 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"name": "simple-discord-webhooks",
"version": "1.0.1",
"version": "1.1.0",
"main": "Webhook.js",
"description": "Very simple package to send, edit and delete Discord Webhook Messages",
"scripts": {
"test": "node test/test.js"
},
"keywords": ["discord", "discord-webhook", "webhook", "webhooks"],
"keywords": [
"discord",
"discord-webhook",
"webhook",
"webhooks"
],
"author": "SCDerox <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/SCDerox/simple-discord-webhooks",
Expand All @@ -23,4 +28,4 @@
"dependencies": {
"@aero/centra": "^1.0.6"
}
}
}
13 changes: 11 additions & 2 deletions test/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16b1af7

Please sign in to comment.