feat(integrations|application): implementation
This commit is contained in:
parent
6e87aa2e83
commit
c1bce28334
6 changed files with 518 additions and 395 deletions
10
mod.ts
10
mod.ts
|
@ -4,6 +4,7 @@ export * from './src/models/rest.ts'
|
|||
export * from './src/models/cacheAdapter.ts'
|
||||
export * from './src/models/shard.ts'
|
||||
export * from './src/models/command.ts'
|
||||
export * from './src/models/extensions.ts'
|
||||
export * from './src/models/commandClient.ts'
|
||||
export * from './src/managers/base.ts'
|
||||
export * from './src/managers/baseChild.ts'
|
||||
|
@ -12,10 +13,13 @@ export * from './src/managers/emojis.ts'
|
|||
export * from './src/managers/gatewayCache.ts'
|
||||
export * from './src/managers/guildChannels.ts'
|
||||
export * from './src/managers/guilds.ts'
|
||||
export * from './src/managers/guildChannels.ts'
|
||||
export * from './src/managers/guildEmojis.ts'
|
||||
export * from './src/managers/members.ts'
|
||||
export * from './src/managers/messages.ts'
|
||||
export * from './src/managers/roles.ts'
|
||||
export * from './src/managers/users.ts'
|
||||
export * from './src/structures/application.ts'
|
||||
export * from './src/structures/base.ts'
|
||||
export * from './src/structures/cdn.ts'
|
||||
export * from './src/structures/channel.ts'
|
||||
|
@ -37,6 +41,7 @@ export * from './src/structures/snowflake.ts'
|
|||
export * from './src/structures/textChannel.ts'
|
||||
export * from './src/structures/user.ts'
|
||||
export * from './src/structures/webhook.ts'
|
||||
export * from './src/types/application.ts'
|
||||
export * from './src/types/cdn.ts'
|
||||
export * from './src/types/channel.ts'
|
||||
export * from './src/types/emoji.ts'
|
||||
|
@ -55,3 +60,8 @@ export * from './src/types/voice.ts'
|
|||
export * from './src/types/webhook.ts'
|
||||
export * from './src/utils/collection.ts'
|
||||
export * from './src/utils/intents.ts'
|
||||
export * from './src/utils/buildInfo.ts'
|
||||
export * from './src/utils/permissions.ts'
|
||||
export * from './src/utils/userFlags.ts'
|
||||
export * from './src/utils/bitfield.ts'
|
||||
export * from './src/utils/getChannelByType.ts'
|
|
@ -12,6 +12,7 @@ import {
|
|||
} from '../structures/presence.ts'
|
||||
import { EmojisManager } from '../managers/emojis.ts'
|
||||
import { ActivityGame, ClientActivity } from "../types/presence.ts"
|
||||
// import { Application } from "../../mod.ts"
|
||||
|
||||
/** Some Client Options to modify behaviour */
|
||||
export interface ClientOptions {
|
||||
|
@ -103,6 +104,9 @@ export class Client extends EventEmitter {
|
|||
this.emit('debug', `[${tag}] ${msg}`)
|
||||
}
|
||||
|
||||
// TODO(DjDeveloperr): Implement this
|
||||
// fetchApplication(): Promise<Application>
|
||||
|
||||
/**
|
||||
* This function is used for connect to discord.
|
||||
* @param token Your token. This is required.
|
||||
|
|
24
src/structures/application.ts
Normal file
24
src/structures/application.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { Client } from "../models/client.ts";
|
||||
import { ApplicationPayload } from "../types/application.ts";
|
||||
import { Base } from "./base.ts";
|
||||
import { User } from "./user.ts";
|
||||
|
||||
export class Application extends Base {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
description: string
|
||||
summary: string
|
||||
bot?: User
|
||||
|
||||
constructor(client: Client, data: ApplicationPayload) {
|
||||
super(client, data)
|
||||
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
this.icon = data.icon
|
||||
this.description = data.description
|
||||
this.summary = data.summary
|
||||
this.bot = data.bot !== undefined ? new User(client, data.bot) : undefined
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { Client } from '../models/client.ts'
|
||||
import { GuildFeatures, GuildPayload } from '../types/guild.ts'
|
||||
import { GuildFeatures, GuildIntegrationPayload, GuildPayload, IntegrationAccountPayload, IntegrationExpireBehavior } from '../types/guild.ts'
|
||||
import { PresenceUpdatePayload } from '../types/gateway.ts'
|
||||
import { Base } from './base.ts'
|
||||
import { VoiceState } from './voiceState.ts'
|
||||
|
@ -9,6 +9,9 @@ import { MembersManager } from '../managers/members.ts'
|
|||
import { Role } from './role.ts'
|
||||
import { GuildEmojisManager } from '../managers/guildEmojis.ts'
|
||||
import { Member } from "./member.ts"
|
||||
import { User } from "./user.ts"
|
||||
import { Application } from "./application.ts"
|
||||
import { GUILD_INTEGRATIONS } from "../types/endpoint.ts"
|
||||
|
||||
export class Guild extends Base {
|
||||
id: string
|
||||
|
@ -213,7 +216,7 @@ export class Guild extends Base {
|
|||
}
|
||||
|
||||
async getEveryoneRole (): Promise<Role> {
|
||||
return (await this.roles.array().then(arr => arr?.sort((b, a) => a.position - b.position)[0]) as any) as Role
|
||||
return (await this.roles.get(this.id) as unknown) as Role
|
||||
}
|
||||
|
||||
async me(): Promise<Member> {
|
||||
|
@ -221,4 +224,47 @@ export class Guild extends Base {
|
|||
if (get === undefined) throw new Error('Guild#me is not cached')
|
||||
return get
|
||||
}
|
||||
|
||||
async fetchIntegrations(): Promise<GuildIntegration[]> {
|
||||
const raw = await this.client.rest.get(GUILD_INTEGRATIONS(this.id)) as GuildIntegrationPayload[]
|
||||
return raw.map(e => new GuildIntegration(this.client, e))
|
||||
}
|
||||
}
|
||||
|
||||
export class GuildIntegration extends Base {
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
enabled: boolean
|
||||
syncing?: boolean
|
||||
roleID?: string
|
||||
enableEmoticons?: boolean
|
||||
expireBehaviour?: IntegrationExpireBehavior
|
||||
expireGracePeriod?: number
|
||||
user?: User
|
||||
account: IntegrationAccountPayload
|
||||
syncedAt?: string // Actually a ISO Timestamp, but we parse in constructor'
|
||||
subscriberCount?: number
|
||||
revoked?: boolean
|
||||
application?: Application
|
||||
|
||||
constructor(client: Client, data: GuildIntegrationPayload) {
|
||||
super(client, data)
|
||||
|
||||
this.id = data.id
|
||||
this.name= data.name
|
||||
this.type = data.type
|
||||
this.enabled = data.enabled
|
||||
this.syncing = data.syncing
|
||||
this.roleID = data.role_id
|
||||
this.enableEmoticons = data.enable_emoticons
|
||||
this.expireBehaviour = data.expire_behaviour
|
||||
this.expireGracePeriod = data.expire_grace_period
|
||||
this.user = data.user !== undefined ? new User(client, data.user) : undefined
|
||||
this.account = data.account
|
||||
this.syncedAt = data.synced_at
|
||||
this.subscriberCount = data.subscriber_count
|
||||
this.revoked = data.revoked
|
||||
this.application = data.application !== undefined ? new Application(client, data.application) : undefined
|
||||
}
|
||||
}
|
10
src/types/application.ts
Normal file
10
src/types/application.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { UserPayload } from "./user.ts";
|
||||
|
||||
export interface ApplicationPayload {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
description: string
|
||||
summary: string
|
||||
bot?: UserPayload
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import { ApplicationPayload } from "./application.ts"
|
||||
import { ChannelPayload } from './channel.ts'
|
||||
import { EmojiPayload } from './emoji.ts'
|
||||
import { PresenceUpdatePayload } from './gateway.ts'
|
||||
|
@ -112,3 +113,31 @@ export type GuildFeatures =
|
|||
| 'FEATURABLE'
|
||||
| 'ANIMATED_ICON'
|
||||
| 'BANNER'
|
||||
|
||||
export enum IntegrationExpireBehavior {
|
||||
REMOVE_ROLE = 0,
|
||||
KICK = 1
|
||||
}
|
||||
|
||||
export interface IntegrationAccountPayload {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface GuildIntegrationPayload {
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
enabled: boolean
|
||||
syncing?: boolean
|
||||
role_id?: string
|
||||
enable_emoticons?: boolean
|
||||
expire_behaviour?: IntegrationExpireBehavior
|
||||
expire_grace_period?: number
|
||||
user?: UserPayload
|
||||
account: IntegrationAccountPayload
|
||||
synced_at?: string // Actually a ISO Timestamp, but we parse in constructor'
|
||||
subscriber_count?: number
|
||||
revoked?: boolean
|
||||
application?: ApplicationPayload
|
||||
}
|
Loading…
Reference in a new issue