feat(client,rest,types): add GetAuditLog.after (#2898)

* feat(client,rest,types): add `GetAuditLog.after`

closes: https://github.com/discordeno/discordeno/issues/2860

* Apply suggestions from code review

---------

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
ITOH
2023-03-29 17:46:21 +02:00
committed by GitHub
parent 08fb3fc5b5
commit a715140df6
3 changed files with 13 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ import type {
StickerTypes,
VerificationLevels,
VideoQualityModes,
WebhookTypes,
WebhookTypes
} from '@discordeno/types'
import type { IncomingHttpHeaders } from 'node:http'
import type Collection from './Collection.js'
@@ -438,6 +438,7 @@ export interface DiscoverySubcategoryResponse {
export interface GetGuildAuditLogOptions {
actionType?: number
before?: string
after?: string
limit?: number
userID?: string
}

View File

@@ -321,6 +321,8 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (options.before) url += `&before=${options.before}`
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (options.after) url += `&after=${options.after}`
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (options.limit) url += `&limit=${options.limit}`
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
if (options.userId) url += `&user_id=${options.userId}`
@@ -973,7 +975,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
}
const headers: HeadersInit = {
Authorization: rest.authorization ?? "",
Authorization: rest.authorization ?? '',
}
if (body) {
headers['Content-Type'] = 'application/json'
@@ -985,13 +987,13 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
})
if (!result.ok) {
const err = await result.json().catch(() => {}) as Record<string, any>;
const err = (await result.json().catch(() => {})) as Record<string, any>
// Legacy Handling to not break old code or when body is missing
if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`)
throw new Error(JSON.stringify(err));
throw new Error(JSON.stringify(err))
}
return result.status !== 204 ? await result.json() as any : undefined
return result.status !== 204 ? ((await result.json()) as any) : undefined
}
return await new Promise((resolve, reject) => {

View File

@@ -328,11 +328,13 @@ export interface ListArchivedThreads {
/** https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log-query-string-parameters */
export interface GetGuildAuditLog {
/** Entries from a specific user ID */
userId?: BigString | string
userId?: BigString
/** Entries for a specific audit log event */
actionType?: AuditLogEvents
/** Entries that preceded a specific audit log entry ID */
before?: BigString | string
/** Entries with ID less than a specific audit log entry ID. */
before?: BigString
/** Entries with ID greater than a specific audit log entry ID. */
after?: BigString
/** Maximum number of entries (between 1-100) to return, defaults to 50 */
limit?: number
}