Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
24 changes: 24 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Dependabot auto-merge

on:
pull_request_target:
branches:
- master
- main
types:
- opened

permissions:
pull-requests: write
contents: write

jobs:
enableAutoMerge:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
## Release Notes
## Release Notes

## [1.1.0]

### Fixed

- `Webhook.Execute()` built an invalid query string (`&?wait=true`) when a `threadID` was
passed, so Discord never returned the created message body and `Webhook.Edit()` could not
be used afterwards.
- `Embed.GetField()` / `Webhook.GetEmbed()` used an inverted bounds check
(`array.Length < index`), returning `null` for every valid index and reading out of bounds
for invalid ones.
- Memory leaks: the `JSONArray` handles obtained in `AddField()`, `AddEmbed()`, `GetField()`
and `GetEmbed()` were never freed.
- Sub-object / array getters (`GetFooter`, `GetImage`, `GetThumbnail`, `GetVideo`,
`GetProvider`, `GetAuthor`, `GetFields`, `GetEmbeds`) raised a native error instead of
returning `null` when the key was not set.
- `Embed.SetTimeStampNow()` used a malformed format string (`"%FT\%T.000%z"`).
- `DEBUG` build path did not compile (`this.toString` instead of `this.ToString`) and passed
unescaped JSON as a format string to `PrintToServer`.
- URL buffers in `Execute()` / `Edit()` could truncate a near-maximum-length webhook URL.

### Added

- `Webhook.GetThreadName()`.
- `Webhook.Execute()` now skips the `thread_id` query parameter when `thread_name` is set,
avoiding Discord error `220002` (a forum webhook cannot use both).

### Changed

- `Webhook.SetThreadName()` now takes a `const char[]` and its documentation reflects the
real Discord limit of 100 characters.

## [1.0.0]

### Added

- Initial release.
- Initial release.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ Contrary to other includes, discordWebhookAPI:
public Action SendDiscordWebhook(int client, int args)
{
Webhook webhook = new Webhook("This is the content of the webhook.");
webhook.Execute("https://discordapp.com/api/webhooks/6758765876/769876789009/", OnWebHookExecuted);
webhook.Execute("https://discord.com/api/webhooks/6758765876/769876789009", OnWebHookExecuted);
delete webhook;
return Plugin_Continue;
}

public void OnWebHookExecuted(HTTPResponse response, DataPack pack)
public void OnWebHookExecuted(HTTPResponse response, any data)
{
if (response.Status == HTTPStatus_NoContent)
// Execute() always appends ?wait=true, so Discord answers 200 OK with the message body.
if (response.Status == HTTPStatus_OK)
{
PrintToServer("Webhook sent successfully!");
}
Expand Down
9 changes: 6 additions & 3 deletions example.sp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ Action SendDiscordWebhook(int client, int args)
public void OnWebHookExecuted(HTTPResponse response, DataPack pack)
{
int client = pack.ReadCell();
delete pack;

PrintToServer("Processed client n°%s's webhook, status %d", client, response.Status);
PrintToServer("Processed client n°%d's webhook, status %d", client, response.Status);
if (response.Status != HTTPStatus_OK)
{
PrintToServer("An error has occured while sending the webhook.");
Expand All @@ -167,10 +168,11 @@ public void OnWebHookExecuted(HTTPResponse response, DataPack pack)
PrintToServer("The webhook has been sent successfuly.");

// Retrieve the message's id.
// Note: response.Data is owned by the extension, do not delete it.
JSONObject resData = view_as<JSONObject>(response.Data);
char messageId[64];
resData.GetString("id", messageId, sizeof messageId);
PrintToServer(messageId);
PrintToServer("%s", messageId);
editWebhook(messageId, client);
}

Expand Down Expand Up @@ -205,8 +207,9 @@ void editWebhook(const char[] messageId, int client)
void OnWebHookEdited(HTTPResponse response, DataPack pack)
{
int client = pack.ReadCell();
delete pack;

PrintToServer("Edited client n°%s's webhook, status %d", client, response.Status);
PrintToServer("Edited client n°%d's webhook, status %d", client, response.Status);
if (response.Status != HTTPStatus_OK)
{
PrintToServer("An error has occured while editing the webhook.");
Expand Down
Loading
Loading