feat(rest): easily enable or disable snake case

This commit is contained in:
Skillz4Killz
2023-06-06 16:28:50 +00:00
parent 4a6e22d192
commit 73c9788065
2 changed files with 28 additions and 0 deletions

View File

@@ -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

View File

@@ -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. */