-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add Missing discord-api Methods #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IanMitchell
wants to merge
17
commits into
main
Choose a base branch
from
api-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3ff874e
Add quick notes
IanMitchell 3cb8588
Merge remote-tracking branch 'origin/main' into api-example
IanMitchell 1985eaf
Add Webhook Example
IanMitchell d6d0ea3
cleanup
IanMitchell c0a0ccd
cleanup
IanMitchell 91ef337
add note
IanMitchell 77bec85
Merge remote-tracking branch 'origin/main' into api-example
IanMitchell 035e71c
update
IanMitchell 6dd1c1a
Merge remote-tracking branch 'origin/main' into api-example
IanMitchell 1d2df31
save state
IanMitchell 84b41b5
excess files
IanMitchell bbe93c3
Merge remote-tracking branch 'origin/main' into api-example
IanMitchell 5069c06
Add Audit Log
IanMitchell d12c09f
Add Auto Mod API
IanMitchell d7dd28d
Add Channel Functions
IanMitchell 3b3ee63
Add Message Functions
IanMitchell be1764f
language tweak
IanMitchell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { | ||
| RESTPostAPIChannelWebhookJSONBody, | ||
| RESTPostAPIChannelWebhookResult, | ||
| } from "discord-api-types/v10"; | ||
| import { Routes } from "discord-api-types/v10"; | ||
| import type { Snowflake } from "discord-snowflake"; | ||
| import { client } from "../client"; | ||
|
|
||
| /** | ||
| * Creates a Channel Webhook | ||
| * @link https://discord.com/developers/docs/resources/webhook#create-webhook | ||
| * @param channelId The Channel to create the webhook in | ||
| * @param data The Webhook name and avatar | ||
| * @param auditLogReason An optional entry to add to the audit log | ||
| * @returns The created Webhook | ||
| */ | ||
| export async function createWebhook( | ||
| channelId: Snowflake, | ||
| data: RESTPostAPIChannelWebhookJSONBody, | ||
| auditLogReason?: string | ||
| ) { | ||
| const headers = new Headers(); | ||
|
|
||
| if (auditLogReason != null) { | ||
| headers.set("X-Audit-Log-Reason", auditLogReason); | ||
| } | ||
|
|
||
| return client.post(Routes.channelWebhooks(channelId), { | ||
| body: data, | ||
| headers, | ||
| }) as Promise<RESTPostAPIChannelWebhookResult>; | ||
| } | ||
|
|
||
| /** | ||
| * createWebhook | ||
| * getChannelWebhooks | ||
| * getGuildWebhooks | ||
| * getWebhook | ||
| * getWebhookWithToken | ||
| * modifyWebhook | ||
| * modifyWebhookWithToken | ||
| * deleteWebhook | ||
| * deleteWebhookWithToken | ||
| * executeWebook | ||
| * executeSlackWebhook | ||
| * executeGitHubWebook | ||
| * getWebhookMessage | ||
| * editWebhookMessage | ||
| * deleteWebhookMessage | ||
| * | ||
| * or | ||
| * postWebhook | ||
| * getChannelWebhooks | ||
| * getGuildWebhooks | ||
| * getWebhook | ||
| * getWebhookWithToken | ||
| * patchWebhook | ||
| * patchWebhookWithToken | ||
| * deleteWebhook | ||
| * deleteWebhookWithToken | ||
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, expect, test, vi } from "vitest"; | ||
| import { client } from "../src/client"; | ||
| import { createWebhook } from "../src/routes/webhook"; | ||
|
|
||
| describe("createWebhook", () => { | ||
| test("Accepts an optional audit log entry", async () => { | ||
| const spy = vi | ||
| .spyOn(client, "post") | ||
| .mockImplementation(async () => Promise.resolve("")); | ||
|
|
||
| await createWebhook( | ||
| "123", | ||
| { name: "Test Webhook", avatar: "avatar.png" }, | ||
| "Vitest Log" | ||
| ); | ||
| expect(spy).toHaveBeenCalledWith( | ||
| expect.anything, | ||
| { | ||
| body: expect.anything, | ||
| headers: { "X-Audit-Log-Reason": "Vitest Log" }, | ||
| }, | ||
| expect.anything | ||
| ); | ||
| }); | ||
|
|
||
| test.todo("Includes webhook information"); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.