-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add Missing discord-api Methods #140
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 all 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,9 @@ | ||
export function getAuditLogHeaders(auditLogReason: string | undefined) { | ||
const headers = new Headers(); | ||
|
||
if (auditLogReason != null) { | ||
headers.set("X-Audit-Log-Reason", auditLogReason); | ||
} | ||
|
||
return headers; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from "./client.js"; | ||
export * from "./routes/commands.js"; | ||
export * from "./routes/application-commands.js"; | ||
export * from "./routes/audit-log.js"; | ||
export * from "./routes/auto-moderation.js"; | ||
export * from "./routes/guild.js"; | ||
export * from "./routes/interactions.js"; |
File renamed without changes.
This file contains 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,16 @@ | ||
import type { RESTGetAPIAuditLogResult } from "discord-api-types/v10"; | ||
import { Routes } from "discord-api-types/v10"; | ||
import type { Snowflake } from "discord-snowflake"; | ||
import { client } from "../client.js"; | ||
|
||
/** | ||
* Get the Audit Log for a Guild. | ||
* {@link https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log | Discord Documentation} | ||
* @param guildId - TThe target Guild to get the Audit Log in. | ||
* @returns The Audit Log for the Guild. | ||
*/ | ||
export async function getGuildAuditLog(guildId: Snowflake) { | ||
return client.get( | ||
Routes.guildAuditLog(guildId) | ||
) as Promise<RESTGetAPIAuditLogResult>; | ||
} |
This file contains 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,97 @@ | ||
import type { | ||
RESTDeleteAPIAutoModerationRuleResult, | ||
RESTGetAPIAutoModerationRuleResult, | ||
RESTGetAPIAutoModerationRulesResult, | ||
RESTPatchAPIAutoModerationRuleResult, | ||
RESTPostAPIAutoModerationRuleJSONBody, | ||
RESTPostAPIAutoModerationRuleResult, | ||
} from "discord-api-types/v10"; | ||
import { Routes } from "discord-api-types/v10"; | ||
import type { Snowflake } from "discord-snowflake"; | ||
import { client } from "../client.js"; | ||
import { getAuditLogHeaders } from "../headers/audit-log.js"; | ||
|
||
/** | ||
* Get a list of all Auto Moderation Rules. | ||
* {@link https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild | Discord Documentation} | ||
* @param guildId - The target Guild to view the Rules in. | ||
* @returns A list of all the Auto Moderation Rules. | ||
*/ | ||
export async function getAutoModerationRules(guildId: Snowflake) { | ||
return client.get( | ||
Routes.guildAutoModerationRules(guildId) | ||
) as Promise<RESTGetAPIAutoModerationRulesResult>; | ||
} | ||
|
||
/** | ||
* Get an Auto Moderation Rule. | ||
* {@link https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule | Discord Documentation} | ||
* @param guildId - The target Guild to get the Rule in. | ||
* @param ruleId - The target Rule to view. | ||
* @returns The Auto Moderation Rule. | ||
*/ | ||
export async function getAutoModerationRule( | ||
guildId: Snowflake, | ||
ruleId: Snowflake | ||
) { | ||
return client.get( | ||
Routes.guildAutoModerationRule(guildId, ruleId) | ||
) as Promise<RESTGetAPIAutoModerationRuleResult>; | ||
} | ||
|
||
/** | ||
* Creates an Auto Moderation Rule. | ||
* {@link https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule | Discord Documentation} | ||
* @param guildId - The target Guild to create the Rule in. | ||
* @param data - The data to use for the new Rule. | ||
* @param auditLogReason - An optional Audit Log entry to record this action under. | ||
* @returns The created Auto Moderation Rule. | ||
*/ | ||
export async function createAutoModerationRule( | ||
guildId: Snowflake, | ||
data: RESTPostAPIAutoModerationRuleJSONBody, | ||
auditLogReason?: string | ||
) { | ||
return client.post(Routes.guildAutoModerationRules(guildId), { | ||
body: data, | ||
headers: getAuditLogHeaders(auditLogReason), | ||
}) as Promise<RESTPostAPIAutoModerationRuleResult>; | ||
} | ||
|
||
/** | ||
* Updates an Auto Moderation Rule. | ||
* {@link https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule | Discord Documentation} | ||
* @param guildId - The target Guild to update the Rule in. | ||
* @param ruleId - The target Rule to update. | ||
* @param data - The new data to use for the Rule. | ||
* @param auditLogReason - An optional Audit Log entry to record this action under. | ||
* @returns The updated Auto Moderation Rule. | ||
*/ | ||
export async function updateAutoModerationRule( | ||
guildId: Snowflake, | ||
ruleId: Snowflake, | ||
data: RESTPostAPIAutoModerationRuleJSONBody, | ||
auditLogReason?: string | ||
) { | ||
return client.patch(Routes.guildAutoModerationRule(guildId, ruleId), { | ||
body: data, | ||
headers: getAuditLogHeaders(auditLogReason), | ||
}) as Promise<RESTPatchAPIAutoModerationRuleResult>; | ||
} | ||
|
||
/** | ||
* Deletes an Auto Moderation Rule. | ||
* {@link https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule | Discord Documentation} | ||
* @param guildId - The target Guild to delete the Rule from. | ||
* @param ruleId - The target Rule to delete. | ||
* @param auditLogReason - An optional Audit Log entry to record this action under. | ||
*/ | ||
export async function deleteAutoModerationRule( | ||
guildId: Snowflake, | ||
ruleId: Snowflake, | ||
auditLogReason?: string | ||
) { | ||
return client.delete(Routes.guildAutoModerationRule(guildId, ruleId), { | ||
headers: getAuditLogHeaders(auditLogReason), | ||
}) as Promise<RESTDeleteAPIAutoModerationRuleResult>; | ||
} |
This file contains 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,56 @@ | ||
import type { | ||
RESTDeleteAPIChannelResult, | ||
RESTGetAPIChannelResult, | ||
RESTPatchAPIChannelJSONBody, | ||
RESTPatchAPIChannelResult, | ||
} from "discord-api-types/v10"; | ||
import { Routes } from "discord-api-types/v10"; | ||
import type { Snowflake } from "discord-snowflake"; | ||
import { client } from "../client.js"; | ||
import { getAuditLogHeaders } from "../headers/audit-log.js"; | ||
|
||
/** | ||
* Get a Channel. | ||
* {@link https://discord.com/developers/docs/resources/channel#get-channel | Discord Documentation} | ||
* @param channelId - The target Channel to get. | ||
* @returns The Channel. | ||
*/ | ||
export async function getChannel(channelId: Snowflake) { | ||
return client.get( | ||
Routes.channel(channelId) | ||
) as Promise<RESTGetAPIChannelResult>; | ||
} | ||
|
||
/** | ||
* Updates a Channel. | ||
* {@link https://discord.com/developers/docs/resources/channel#modify-channel | Discord Documentation} | ||
* @param channelId - The target Channel to update. | ||
* @param data - The new data to use for the Channel. | ||
* @param auditLogReason - An optional Audit Log entry to record this action under. | ||
* @returns The updated Channel. | ||
*/ | ||
export async function updateChannel( | ||
channelId: Snowflake, | ||
data: RESTPatchAPIChannelJSONBody, | ||
auditLogReason?: string | ||
) { | ||
return client.patch(Routes.channel(channelId), { | ||
body: data, | ||
headers: getAuditLogHeaders(auditLogReason), | ||
}) as Promise<RESTPatchAPIChannelResult>; | ||
} | ||
|
||
/** | ||
* Deletes a channel or closes a private message. | ||
* @param channelId - The target Channel to delete. | ||
* @param auditLogReason - An optional Audit Log entry to record this action under. | ||
* @returns The deleted Channel. | ||
*/ | ||
export async function deleteChannel( | ||
channelId: Snowflake, | ||
auditLogReason?: string | ||
) { | ||
return client.delete(Routes.channel(channelId), { | ||
headers: getAuditLogHeaders(auditLogReason), | ||
}) as Promise<RESTDeleteAPIChannelResult>; | ||
} |
This file contains 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,62 @@ | ||
import type { | ||
RESTGetAPIChannelMessageResult, | ||
RESTGetAPIChannelMessagesQuery, | ||
RESTGetAPIChannelMessagesResult, | ||
RESTPostAPIChannelMessageJSONBody, | ||
RESTPostAPIChannelMessageResult, | ||
} from "discord-api-types/v10"; | ||
import { Routes } from "discord-api-types/v10"; | ||
import type { Snowflake } from "discord-snowflake"; | ||
import { client } from "../client.js"; | ||
|
||
/** | ||
* Returns an array of Messages for a Channel. | ||
* {@link https://discord.com/developers/docs/resources/channel#get-channel-messages | Discord Documentation} | ||
* @param channelId - The target Channel to get Messages in. | ||
* @returns An array of Messages | ||
*/ | ||
export async function getMessages( | ||
channelId: Snowflake, | ||
params?: RESTGetAPIChannelMessagesQuery | ||
) { | ||
const query = new URLSearchParams(); | ||
|
||
if (params) { | ||
Object.entries(params).forEach(([key, value]) => { | ||
query.set(key, value); | ||
}); | ||
} | ||
|
||
return client.get(Routes.channelMessages(channelId), { | ||
query, | ||
}) as Promise<RESTGetAPIChannelMessagesResult>; | ||
} | ||
|
||
/** | ||
* Get a Message. | ||
* {@link https://discord.com/developers/docs/resources/channel#get-channel-message | Discord Documentation} | ||
* @param channelId - The target Channel to get the Message in. | ||
* @param messageId - The target Message to get. | ||
* @returns The Message. | ||
*/ | ||
export async function getMessage(channelId: Snowflake, messageId: Snowflake) { | ||
return client.get( | ||
Routes.channelMessage(channelId, messageId) | ||
) as Promise<RESTGetAPIChannelMessageResult>; | ||
} | ||
|
||
/** | ||
* Posts a Message to a Channel. | ||
* {@link https://discord.com/developers/docs/resources/channel#create-message | Discord Documentation} | ||
* @param channelId - The target Channel to post the Message in. | ||
* @param data - The Message content. | ||
* @returns The created Message. | ||
*/ | ||
export async function createMessage( | ||
channelId: Snowflake, | ||
data: RESTPostAPIChannelMessageJSONBody | ||
) { | ||
return client.post(Routes.channelMessages(channelId), { | ||
body: data, | ||
}) as Promise<RESTPostAPIChannelMessageResult>; | ||
} |
This file contains 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,32 @@ | ||
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.js"; | ||
|
||
/** | ||
* Creates a Channel Webhook. | ||
* {@link https://discord.com/developers/docs/resources/webhook#create-webhook | Discord Documentation} | ||
* @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>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 { expect, test } from "vitest"; | ||
import * as API from "../src/index"; | ||
|
||
test("API is backwards compatible", () => { | ||
expect(Object.keys(API)).toMatchInlineSnapshot(` | ||
[ | ||
"DiscordApiClient", | ||
"client", | ||
"getGlobalApplicationCommands", | ||
"createGlobalApplicationCommand", | ||
"getGlobalApplicationCommand", | ||
"editGlobalApplicationCommand", | ||
"deleteGlobalApplicationCommand", | ||
"bulkOverwriteGlobalApplicationCommands", | ||
"getGuildApplicationCommands", | ||
"createGuildApplicationCommand", | ||
"getGuildApplicationCommand", | ||
"editGuildApplicationCommands", | ||
"deleteGuildApplicationCommand", | ||
"bulkOverwriteGuildApplicationCommands", | ||
"getGuild", | ||
"createInteractionFollowup", | ||
"editInteractionFollowup", | ||
"deleteInteractionFollowup", | ||
] | ||
`); | ||
}); |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double
T