mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
feat(rest): easily enable or disable snake case
This commit is contained in:
@@ -1215,6 +1215,32 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
async upsertGuildApplicationCommands(guildId, body) {
|
||||
return await rest.put<DiscordApplicationCommand[]>(rest.routes.interactions.commands.guilds.all(rest.applicationId, guildId), { body })
|
||||
},
|
||||
|
||||
preferSnakeCase(enabled: boolean) {
|
||||
const camelizer = enabled ? (x: any) => x : camelize
|
||||
|
||||
rest.get = async (url, options) => {
|
||||
return camelizer(await rest.makeRequest('GET', url, options))
|
||||
}
|
||||
|
||||
rest.post = async (url: string, options?: Omit<CreateRequestBodyOptions, 'body' | 'method'>) => {
|
||||
return camelizer(await rest.makeRequest('POST', url, options))
|
||||
}
|
||||
|
||||
rest.delete = async (url: string, options?: Omit<CreateRequestBodyOptions, 'body' | 'method'>) => {
|
||||
camelizer(await rest.makeRequest('DELETE', url, options))
|
||||
}
|
||||
|
||||
rest.patch = async (url: string, options?: Omit<CreateRequestBodyOptions, 'body' | 'method'>) => {
|
||||
return camelizer(await rest.makeRequest('PATCH', url, options))
|
||||
}
|
||||
|
||||
rest.put = async (url: string, options?: Omit<CreateRequestBodyOptions, 'body' | 'method'>) => {
|
||||
return camelizer(await rest.makeRequest('PUT', url, options))
|
||||
}
|
||||
|
||||
return rest
|
||||
},
|
||||
}
|
||||
|
||||
return rest
|
||||
|
||||
@@ -160,6 +160,8 @@ export interface RestManager {
|
||||
invalidBucket: InvalidRequestBucket
|
||||
/** The routes that are available for this manager. */
|
||||
routes: RestRoutes
|
||||
/** Whether or not the rest manager should keep objects in raw snake case from discord. */
|
||||
preferSnakeCase: (enabled: boolean) => RestManager;
|
||||
/** Check the rate limits for a url or a bucket. */
|
||||
checkRateLimits: (url: string) => number | false
|
||||
/** Reshapes and modifies the obj as needed to make it ready for discords api. */
|
||||
|
||||
Reference in New Issue
Block a user