diff --git a/LICENSE b/LICENSE index c52f6d0..043f36c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Harmony Org +Copyright (c) 2020-21 Harmony Org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 585d405..d2fe4c3 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,6 @@ Small note: If editing the README, please conform to the [standard-readme](https ## License -[MIT © 2020 Harmony Org](LICENSE) +[MIT © 2020-21 Harmony Org](LICENSE) #### Made with ❤ by Harmony-org diff --git a/src/structures/guild.ts b/src/structures/guild.ts index d50f500..4fe7f9c 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -168,8 +168,9 @@ export class Guild extends Base { constructor(client: Client, data: GuildPayload) { super(client, data) this.id = data.id - this.bans = new GuildBans(client, this) this.unavailable = data.unavailable + this.readFromData(data) + this.bans = new GuildBans(client, this) this.members = new MembersManager(this.client, this) this.voiceStates = new GuildVoiceStatesManager(client, this) this.presences = new GuildPresencesManager(client, this) @@ -181,45 +182,6 @@ export class Guild extends Base { this.roles = new RolesManager(this.client, this) this.emojis = new GuildEmojisManager(this.client, this.client.emojis, this) this.invites = new InviteManager(this.client, this) - - if (!this.unavailable) { - this.name = data.name - this.icon = data.icon - this.iconHash = data.icon_hash - this.splash = data.splash - this.discoverySplash = data.discovery_splash - this.owner = data.owner - this.ownerID = data.owner_id - this.permissions = data.permissions - this.region = data.region - this.afkTimeout = data.afk_timeout - this.afkChannelID = data.afk_channel_id - this.widgetEnabled = data.widget_enabled - this.widgetChannelID = data.widget_channel_id - this.verificationLevel = data.verification_level - this.defaultMessageNotifications = data.default_message_notifications - this.explicitContentFilter = data.explicit_content_filter - this.features = data.features - this.mfaLevel = data.mfa_level - this.systemChannelID = data.system_channel_id - this.systemChannelFlags = data.system_channel_flags - this.rulesChannelID = data.rules_channel_id - this.joinedAt = data.joined_at - this.large = data.large - this.memberCount = data.member_count - this.maxPresences = data.max_presences - this.maxMembers = data.max_members - this.vanityURLCode = data.vanity_url_code - this.description = data.description - this.banner = data.banner - this.premiumTier = data.premium_tier - this.premiumSubscriptionCount = data.premium_subscription_count - this.preferredLocale = data.preferred_locale - this.publicUpdatesChannelID = data.public_updates_channel_id - this.maxVideoChannelUsers = data.max_video_channel_users - this.approximateNumberCount = data.approximate_number_count - this.approximatePresenceCount = data.approximate_presence_count - } } readFromData(data: GuildPayload): void { @@ -343,6 +305,27 @@ export class Guild extends Base { } }) } + + /** + * Fulfills promise when guild becomes available + * @param timeout Configurable timeout to cancel the wait to safely remove listener. + */ + async awaitAvailability(timeout: number = 1000): Promise { + return await new Promise((resolve, reject) => { + if(!this.unavailable) resolve(this); + const listener = (guild: Guild): void => { + if (guild.id === this.id) { + this.client.removeListener('guildLoaded', listener); + resolve(this); + } + }; + this.client.on('guildLoaded', listener); + setTimeout(() => { + this.client.removeListener('guildLoaded', listener); + reject(Error("Timeout. Guild didn't arrive in time.")); + }, timeout); + }); + } } export class GuildIntegration extends Base { diff --git a/src/types/slash.ts b/src/types/slash.ts index 1bd83ba..2dac0cd 100644 --- a/src/types/slash.ts +++ b/src/types/slash.ts @@ -32,7 +32,10 @@ export interface InteractionPayload { /** Token of the Interaction to respond */ token: string /** Member object of user who invoked */ - member: MemberPayload + member: MemberPayload & { + /** Total permissions of the member in the channel, including overrides */ + permissions: string + } /** ID of the Interaction */ id: string /**