2020-10-22 15:50:47 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
2020-10-31 12:33:34 +00:00
|
|
|
import { GuildFeatures, GuildPayload } from '../types/guild.ts'
|
2020-11-03 09:21:29 +00:00
|
|
|
import { PresenceUpdatePayload } from '../types/gateway.ts'
|
2020-10-22 15:50:47 +00:00
|
|
|
import { Base } from './base.ts'
|
2020-10-25 17:03:53 +00:00
|
|
|
import { VoiceState } from './voiceState.ts'
|
2020-11-08 07:57:24 +00:00
|
|
|
import { RolesManager } from '../managers/roles.ts'
|
|
|
|
import { GuildChannelsManager } from '../managers/guildChannels.ts'
|
|
|
|
import { MembersManager } from '../managers/members.ts'
|
2020-11-08 11:37:35 +00:00
|
|
|
import { Role } from './role.ts'
|
|
|
|
import { GuildEmojisManager } from '../managers/guildEmojis.ts'
|
2020-11-15 07:32:46 +00:00
|
|
|
import { Member } from "./member.ts"
|
2020-10-22 15:50:47 +00:00
|
|
|
|
2020-10-23 16:11:00 +00:00
|
|
|
export class Guild extends Base {
|
2020-10-22 15:50:47 +00:00
|
|
|
id: string
|
2020-10-29 14:43:27 +00:00
|
|
|
name?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
icon?: string
|
|
|
|
iconHash?: string
|
|
|
|
splash?: string
|
|
|
|
discoverySplash?: string
|
|
|
|
owner?: boolean
|
2020-10-29 14:43:27 +00:00
|
|
|
ownerID?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
permissions?: string
|
2020-10-29 14:43:27 +00:00
|
|
|
region?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
afkChannelID?: string
|
2020-10-29 14:43:27 +00:00
|
|
|
afkTimeout?: number
|
2020-10-23 16:11:00 +00:00
|
|
|
widgetEnabled?: boolean
|
|
|
|
widgetChannelID?: string
|
2020-10-29 14:43:27 +00:00
|
|
|
verificationLevel?: string
|
|
|
|
defaultMessageNotifications?: string
|
|
|
|
explicitContentFilter?: string
|
2020-11-02 12:08:38 +00:00
|
|
|
roles: RolesManager
|
2020-11-08 11:10:33 +00:00
|
|
|
emojis: GuildEmojisManager
|
2020-10-29 14:43:27 +00:00
|
|
|
features?: GuildFeatures[]
|
|
|
|
mfaLevel?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
applicationID?: string
|
|
|
|
systemChannelID?: string
|
2020-10-29 14:43:27 +00:00
|
|
|
systemChannelFlags?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
rulesChannelID?: string
|
|
|
|
joinedAt?: string
|
|
|
|
large?: boolean
|
2020-10-22 15:50:47 +00:00
|
|
|
unavailable: boolean
|
2020-10-23 16:11:00 +00:00
|
|
|
memberCount?: number
|
2020-10-25 17:03:53 +00:00
|
|
|
voiceStates?: VoiceState[]
|
2020-11-08 08:04:41 +00:00
|
|
|
members: MembersManager
|
2020-11-02 12:08:38 +00:00
|
|
|
channels: GuildChannelsManager
|
2020-10-23 16:11:00 +00:00
|
|
|
presences?: PresenceUpdatePayload[]
|
|
|
|
maxPresences?: number
|
|
|
|
maxMembers?: number
|
|
|
|
vanityURLCode?: string
|
|
|
|
description?: string
|
|
|
|
banner?: string
|
2020-10-29 14:43:27 +00:00
|
|
|
premiumTier?: number
|
2020-10-23 16:11:00 +00:00
|
|
|
premiumSubscriptionCount?: number
|
2020-10-29 14:43:27 +00:00
|
|
|
preferredLocale?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
publicUpdatesChannelID?: string
|
|
|
|
maxVideoChannelUsers?: number
|
|
|
|
approximateNumberCount?: number
|
|
|
|
approximatePresenceCount?: number
|
2020-10-22 15:50:47 +00:00
|
|
|
|
|
|
|
constructor (client: Client, data: GuildPayload) {
|
2020-10-25 06:50:32 +00:00
|
|
|
super(client, data)
|
2020-10-22 15:50:47 +00:00
|
|
|
this.id = data.id
|
|
|
|
this.unavailable = data.unavailable
|
2020-11-02 12:08:38 +00:00
|
|
|
this.members = new MembersManager(this.client, this)
|
2020-11-08 08:31:00 +00:00
|
|
|
this.channels = new GuildChannelsManager(
|
|
|
|
this.client,
|
|
|
|
this.client.channels,
|
|
|
|
this
|
|
|
|
)
|
2020-11-02 12:08:38 +00:00
|
|
|
this.roles = new RolesManager(this.client, this)
|
2020-11-08 11:10:33 +00:00
|
|
|
this.emojis = new GuildEmojisManager(this.client, this.client.emojis, this)
|
2020-10-29 14:43:27 +00:00
|
|
|
|
|
|
|
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
|
2020-10-31 11:45:33 +00:00
|
|
|
// this.roles = data.roles.map(
|
|
|
|
// v => cache.get('role', v.id) ?? new Role(client, v)
|
|
|
|
// )
|
2020-11-01 11:22:09 +00:00
|
|
|
// data.roles.forEach(role => {
|
|
|
|
// this.roles.set(role.id, new Role(client, role))
|
|
|
|
// })
|
|
|
|
// this.emojis = data.emojis.map(
|
|
|
|
// v => cache.get('emoji', v.id) ?? new Emoji(client, v)
|
|
|
|
// )
|
2020-10-29 14:43:27 +00:00
|
|
|
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
|
2020-11-01 11:22:09 +00:00
|
|
|
// TODO: Cache in Gateway Event code
|
|
|
|
// this.voiceStates = data.voice_states?.map(
|
|
|
|
// v =>
|
|
|
|
// cache.get('voiceState', `${v.guild_id}:${v.user_id}`) ??
|
|
|
|
// new VoiceState(client, v)
|
|
|
|
// )
|
|
|
|
// this.members = data.members?.map(
|
|
|
|
// v =>
|
|
|
|
// cache.get('member', `${this.id}:${v.user.id}`) ??
|
|
|
|
// new Member(client, v)
|
|
|
|
// )
|
|
|
|
// this.channels = data.channels?.map(
|
|
|
|
// v => cache.get('channel', v.id) ?? getChannelByType(this.client, v)
|
|
|
|
// )
|
2020-10-29 14:43:27 +00:00
|
|
|
this.presences = data.presences
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 14:51:40 +00:00
|
|
|
protected readFromData (data: GuildPayload): void {
|
2020-10-29 14:43:27 +00:00
|
|
|
super.readFromData(data)
|
|
|
|
this.id = data.id ?? this.id
|
|
|
|
this.unavailable = data.unavailable ?? this.unavailable
|
|
|
|
|
|
|
|
if (!this.unavailable) {
|
|
|
|
this.name = data.name ?? this.name
|
|
|
|
this.icon = data.icon ?? this.icon
|
|
|
|
this.iconHash = data.icon_hash ?? this.iconHash
|
|
|
|
this.splash = data.splash ?? this.splash
|
|
|
|
this.discoverySplash = data.discovery_splash ?? this.discoverySplash
|
|
|
|
this.owner = data.owner ?? this.owner
|
|
|
|
this.ownerID = data.owner_id ?? this.ownerID
|
|
|
|
this.permissions = data.permissions ?? this.permissions
|
|
|
|
this.region = data.region ?? this.region
|
|
|
|
this.afkTimeout = data.afk_timeout ?? this.afkTimeout
|
|
|
|
this.afkChannelID = data.afk_channel_id ?? this.afkChannelID
|
|
|
|
this.widgetEnabled = data.widget_enabled ?? this.widgetEnabled
|
|
|
|
this.widgetChannelID = data.widget_channel_id ?? this.widgetChannelID
|
|
|
|
this.verificationLevel = data.verification_level ?? this.verificationLevel
|
|
|
|
this.defaultMessageNotifications =
|
|
|
|
data.default_message_notifications ?? this.defaultMessageNotifications
|
|
|
|
this.explicitContentFilter =
|
|
|
|
data.explicit_content_filter ?? this.explicitContentFilter
|
2020-10-31 11:45:33 +00:00
|
|
|
// this.roles =
|
|
|
|
// data.roles.map(
|
|
|
|
// v => cache.get('role', v.id) ?? new Role(this.client, v)
|
|
|
|
// ) ?? this.roles
|
2020-11-07 13:05:37 +00:00
|
|
|
// this.emojis =
|
|
|
|
// data.emojis.map(
|
|
|
|
// v => cache.get('emoji', v.id) ?? new Emoji(this.client, v)
|
|
|
|
// ) ?? this.emojis
|
2020-10-29 14:43:27 +00:00
|
|
|
this.features = data.features ?? this.features
|
|
|
|
this.mfaLevel = data.mfa_level ?? this.mfaLevel
|
|
|
|
this.systemChannelID = data.system_channel_id ?? this.systemChannelID
|
|
|
|
this.systemChannelFlags =
|
|
|
|
data.system_channel_flags ?? this.systemChannelFlags
|
|
|
|
this.rulesChannelID = data.rules_channel_id ?? this.rulesChannelID
|
|
|
|
this.joinedAt = data.joined_at ?? this.joinedAt
|
|
|
|
this.large = data.large ?? this.large
|
|
|
|
this.memberCount = data.member_count ?? this.memberCount
|
2020-11-01 13:42:00 +00:00
|
|
|
// this.voiceStates =
|
|
|
|
// data.voice_states?.map(
|
|
|
|
// v =>
|
|
|
|
// cache.get('voiceState', `${v.guild_id}:${v.user_id}`) ??
|
|
|
|
// new VoiceState(this.client, v)
|
|
|
|
// ) ?? this.voiceStates
|
|
|
|
// this.members =
|
|
|
|
// data.members?.map(
|
|
|
|
// v =>
|
|
|
|
// cache.get('member', `${this.id}:${v.user.id}`) ??
|
|
|
|
// new Member(this.client, v)
|
|
|
|
// ) ?? this.members
|
|
|
|
// this.channels =
|
|
|
|
// data.channels?.map(
|
|
|
|
// v => cache.get('channel', v.id) ?? getChannelByType(this.client, v, this)
|
|
|
|
// ) ?? this.members
|
2020-10-29 14:43:27 +00:00
|
|
|
this.presences = data.presences ?? this.presences
|
|
|
|
this.maxPresences = data.max_presences ?? this.maxPresences
|
|
|
|
this.maxMembers = data.max_members ?? this.maxMembers
|
|
|
|
this.vanityURLCode = data.vanity_url_code ?? this.vanityURLCode
|
|
|
|
this.description = data.description ?? this.description
|
|
|
|
this.banner = data.banner ?? this.banner
|
|
|
|
this.premiumTier = data.premium_tier ?? this.premiumTier
|
|
|
|
this.premiumSubscriptionCount =
|
|
|
|
data.premium_subscription_count ?? this.premiumSubscriptionCount
|
|
|
|
this.preferredLocale = data.preferred_locale ?? this.preferredLocale
|
|
|
|
this.publicUpdatesChannelID =
|
|
|
|
data.public_updates_channel_id ?? this.publicUpdatesChannelID
|
|
|
|
this.maxVideoChannelUsers =
|
|
|
|
data.max_video_channel_users ?? this.maxVideoChannelUsers
|
|
|
|
this.approximateNumberCount =
|
|
|
|
data.approximate_number_count ?? this.approximateNumberCount
|
|
|
|
this.approximatePresenceCount =
|
|
|
|
data.approximate_presence_count ?? this.approximatePresenceCount
|
|
|
|
}
|
2020-10-23 16:11:00 +00:00
|
|
|
}
|
2020-11-08 11:10:33 +00:00
|
|
|
|
2020-11-08 11:36:30 +00:00
|
|
|
async getEveryoneRole (): Promise<Role> {
|
2020-11-08 11:10:33 +00:00
|
|
|
return (await this.roles.array().then(arr => arr?.sort((b, a) => a.position - b.position)[0]) as any) as Role
|
|
|
|
}
|
2020-11-15 07:32:46 +00:00
|
|
|
|
|
|
|
async me(): Promise<Member> {
|
|
|
|
const get = await this.members.get(this.client.user?.id as string)
|
|
|
|
if (get === undefined) throw new Error('Guild#me is not cached')
|
|
|
|
return get
|
|
|
|
}
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|