Skip to content

Commit

Permalink
fix(GuildManager): add missing types and converts (#6683)
Browse files Browse the repository at this point in the history
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
NyanSpaghetti and Jiralite committed Oct 2, 2021
1 parent a7cb314 commit cdf65f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/managers/GuildManager.js
Expand Up @@ -12,6 +12,7 @@ const Role = require('../structures/Role');
const {
ChannelTypes,
Events,
OverwriteTypes,
VerificationLevels,
DefaultMessageNotificationLevels,
ExplicitContentFilterLevels,
Expand Down Expand Up @@ -73,7 +74,7 @@ class GuildManager extends CachedManager {
* Partial overwrite data.
* @typedef {Object} PartialOverwriteData
* @property {Snowflake|number} id The id of the {@link Role} or {@link User} this overwrite belongs to
* @property {string} [type] The type of this overwrite
* @property {OverwriteType} [type] The type of this overwrite
* @property {PermissionResolvable} [allow] The permissions to allow
* @property {PermissionResolvable} [deny] The permissions to deny
*/
Expand All @@ -84,7 +85,7 @@ class GuildManager extends CachedManager {
* @property {Snowflake|number} [id] The channel's id, used to set its parent,
* this is a placeholder and will be replaced by the API after consumption
* @property {Snowflake|number} [parentId] The parent id for this channel
* @property {ChannelType} [type] The type of the channel
* @property {ChannelType|number} [type] The type of the channel
* @property {string} name The name of the channel
* @property {string} [topic] The topic of the text channel
* @property {boolean} [nsfw] Whether the channel is NSFW
Expand Down Expand Up @@ -188,10 +189,18 @@ class GuildManager extends CachedManager {
}
for (const channel of channels) {
if (channel.type) channel.type = ChannelTypes[channel.type.toUpperCase()];
if (channel.type) channel.type = typeof channel.type === 'number' ? channel.type : ChannelTypes[channel.type];
channel.parent_id = channel.parentId;
delete channel.parentId;
channel.user_limit = channel.userLimit;
delete channel.userLimit;
channel.rate_limit_per_user = channel.rateLimitPerUser;
delete channel.rateLimitPerUser;
if (!channel.permissionOverwrites) continue;
for (const overwrite of channel.permissionOverwrites) {
if (typeof overwrite.type === 'string') {
overwrite.type = OverwriteTypes[overwrite.type];
}
if (overwrite.allow) overwrite.allow = Permissions.resolve(overwrite.allow).toString();
if (overwrite.deny) overwrite.deny = Permissions.resolve(overwrite.deny).toString();
}
Expand Down
28 changes: 26 additions & 2 deletions typings/index.d.ts
Expand Up @@ -4563,11 +4563,35 @@ export type PresenceResolvable = Presence | UserResolvable | Snowflake;

export interface PartialChannelData {
id?: Snowflake | number;
parentId?: Snowflake | number;
type?: Exclude<
keyof typeof ChannelTypes | ChannelTypes,
| 'DM'
| 'GROUP_DM'
| 'GUILD_NEWS'
| 'GUILD_STORE'
| 'UNKNOWN'
| 'GUILD_NEWS_THREAD'
| 'GUILD_PUBLIC_THREAD'
| 'GUILD_PRIVATE_THREAD'
| 'GUILD_STAGE_VOICE'
| ChannelTypes.DM
| ChannelTypes.GROUP_DM
| ChannelTypes.GUILD_NEWS
| ChannelTypes.GUILD_STORE
| ChannelTypes.UNKNOWN
| ChannelTypes.GUILD_NEWS_THREAD
| ChannelTypes.GUILD_PUBLIC_THREAD
| ChannelTypes.GUILD_PRIVATE_THREAD
| ChannelTypes.GUILD_STAGE_VOICE
>;
name: string;
topic?: string;
type?: ChannelTypes;
parentId?: Snowflake | number;
nsfw?: boolean;
bitrate?: number;
userLimit?: number;
permissionOverwrites?: PartialOverwriteData[];
rateLimitPerUser?: number;
}

export type Partialize<
Expand Down

0 comments on commit cdf65f7

Please sign in to comment.