2021-04-04 09:29:56 +00:00
import type { Client } from '../client/mod.ts'
import type { ChannelPayload } from '../types/channel.ts'
2020-12-25 16:44:05 +00:00
import { INVITE } from '../types/endpoint.ts'
2021-04-04 09:29:56 +00:00
import type { GuildPayload } from '../types/guild.ts'
import type { InvitePayload } from '../types/invite.ts'
import type { UserPayload } from '../types/user.ts'
2020-12-02 12:29:52 +00:00
import { Base } from './base.ts'
export class Invite extends Base {
code : string
guild? : GuildPayload
channel : ChannelPayload
inviter? : UserPayload
targetUser? : UserPayload
targetUserType? : number
approximatePresenceCount? : number
approximateMemberCount? : number
2021-01-01 04:48:18 +00:00
/** Number of times Invite was used. This is an Invite Metadata property (not always available) */
uses? : number
/** Max number of times this Invite can be used. This is an Invite Metadata property (not always available) */
maxUses? : number
/** Max age of the Invite in seconds. This is an Invite Metadata property (not always available) */
maxAge? : number
/** Whether Invite is temporary or not. This is an Invite Metadata property (not always available) */
temporary? : boolean
/** Timestamp (string) when Invite was created. This is an Invite Metadata property (not always available) */
createdAtTimestamp? : string
/** Timestamp (Date) when Invite was created. This is an Invite Metadata property (not always available) */
get createdAt ( ) : Date | undefined {
return this . createdAtTimestamp === undefined
? undefined
: new Date ( this . createdAtTimestamp )
}
2020-12-02 12:29:52 +00:00
get link ( ) : string {
return ` https://discord.gg/ ${ this . code } `
}
2021-01-01 04:48:18 +00:00
toString ( ) : string {
return this . link
}
2020-12-02 12:29:52 +00:00
constructor ( client : Client , data : InvitePayload ) {
super ( client )
this . code = data . code
this . guild = data . guild
this . channel = data . channel
this . inviter = data . inviter
this . targetUser = data . target_user
this . targetUserType = data . target_user_type
this . approximateMemberCount = data . approximate_member_count
this . approximatePresenceCount = data . approximate_presence_count
2021-01-01 04:48:18 +00:00
this . uses = ( data as any ) . uses
this . maxUses = ( data as any ) . maxUses
this . maxAge = ( data as any ) . maxAge
this . temporary = ( data as any ) . temporary
this . createdAtTimestamp = ( data as any ) . createdAtTimestamp
2020-12-02 12:29:52 +00:00
}
2020-12-25 16:44:05 +00:00
/** Delete an invite. Requires the MANAGE_CHANNELS permission on the channel this invite belongs to, or MANAGE_GUILD to remove any invite across the guild. Returns an invite object on success. Fires a Invite Delete Gateway event. */
async delete ( ) : Promise < Invite > {
const res = await this . client . rest . delete ( INVITE ( this . code ) )
return new Invite ( this . client , res )
}
2020-12-03 05:28:20 +00:00
readFromData ( data : InvitePayload ) : void {
2020-12-02 12:29:52 +00:00
this . code = data . code ? ? this . code
this . guild = data . guild ? ? this . guild
this . channel = data . channel ? ? this . channel
this . inviter = data . inviter ? ? this . inviter
this . targetUser = data . target_user ? ? this . targetUser
this . targetUserType = data . target_user_type ? ? this . targetUserType
this . approximateMemberCount =
data . approximate_member_count ? ? this . approximateMemberCount
this . approximatePresenceCount =
data . approximate_presence_count ? ? this . approximatePresenceCount
2021-01-01 04:48:18 +00:00
this . uses = ( data as any ) . uses ? ? this . uses
this . maxUses = ( data as any ) . maxUses ? ? this . maxUses
this . maxAge = ( data as any ) . maxAge ? ? this . maxAge
this . temporary = ( data as any ) . temporary ? ? this . temporary
this . createdAtTimestamp =
( data as any ) . createdAtTimestamp ? ? this . createdAtTimestamp
2020-12-02 12:29:52 +00:00
}
}