mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
fix: snakelize request body
This commit is contained in:
@@ -17,16 +17,20 @@ export async function createChannel(guildId: bigint, options?: CreateGuildChanne
|
||||
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
||||
|
||||
const result = await rest.runMethod<Channel>("post", endpoints.GUILD_CHANNELS(guildId), {
|
||||
...snakelize<DiscordCreateGuildChannel>(options ?? {}),
|
||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||
...perm,
|
||||
allow: calculateBits(perm.allow),
|
||||
deny: calculateBits(perm.deny),
|
||||
})),
|
||||
type: options?.type || DiscordChannelTypes.GuildText,
|
||||
reason,
|
||||
});
|
||||
const result = await rest.runMethod<Channel>(
|
||||
"post",
|
||||
endpoints.GUILD_CHANNELS(guildId),
|
||||
snakelize<DiscordCreateGuildChannel>({
|
||||
...options,
|
||||
permissionOverwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||
...perm,
|
||||
allow: calculateBits(perm.allow),
|
||||
deny: calculateBits(perm.deny),
|
||||
})),
|
||||
type: options?.type || DiscordChannelTypes.GuildText,
|
||||
reason,
|
||||
})
|
||||
);
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(result);
|
||||
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
|
||||
|
||||
@@ -72,24 +72,23 @@ export async function editChannel(channelId: bigint, options: ModifyChannel | Mo
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...snakelize<Record<string, unknown>>(options),
|
||||
// deno-lint-ignore camelcase
|
||||
permission_overwrites: hasOwnProperty<ModifyChannel>(options, "permissionOverwrites")
|
||||
? options.permissionOverwrites?.map((overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
};
|
||||
|
||||
const result = await rest.runMethod<Channel>("patch", endpoints.CHANNEL_BASE(channelId), {
|
||||
...payload,
|
||||
reason,
|
||||
});
|
||||
const result = await rest.runMethod<Channel>(
|
||||
"patch",
|
||||
endpoints.CHANNEL_BASE(channelId),
|
||||
snakelize({
|
||||
...options,
|
||||
permissionOverwrites: hasOwnProperty<ModifyChannel>(options, "permissionOverwrites")
|
||||
? options.permissionOverwrites?.map((overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
reason,
|
||||
})
|
||||
);
|
||||
|
||||
return await structures.createDiscordenoChannel(result);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { ModifyGuildChannelPositions } from "../../types/guilds/modify_guild_channel_position.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||
export async function swapChannels(guildId: bigint, channelPositions: ModifyGuildChannelPositions[]) {
|
||||
@@ -8,5 +9,5 @@ export async function swapChannels(guildId: bigint, channelPositions: ModifyGuil
|
||||
throw "You must provide at least two channels to be swapped.";
|
||||
}
|
||||
|
||||
return await rest.runMethod<undefined>("patch", endpoints.GUILD_CHANNELS(guildId), channelPositions);
|
||||
return await rest.runMethod<undefined>("patch", endpoints.GUILD_CHANNELS(guildId), snakelize(channelPositions));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user