add APPLICATION_COMMAND_* events
This commit is contained in:
parent
11fc7e1e21
commit
87c15a9283
8 changed files with 103 additions and 6 deletions
15
src/gateway/handlers/applicationCommandCreate.ts
Normal file
15
src/gateway/handlers/applicationCommandCreate.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { SlashCommand } from '../../models/slashClient.ts'
|
||||||
|
import { ApplicationCommandPayload } from '../../types/gateway.ts'
|
||||||
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
|
|
||||||
|
export const applicationCommandCreate: GatewayEventHandler = async (
|
||||||
|
gateway: Gateway,
|
||||||
|
d: ApplicationCommandPayload
|
||||||
|
) => {
|
||||||
|
const guild =
|
||||||
|
d.guild_id === undefined
|
||||||
|
? undefined
|
||||||
|
: await gateway.client.guilds.get(d.guild_id)
|
||||||
|
const cmd = new SlashCommand(gateway.client.slash.commands, d, guild)
|
||||||
|
gateway.client.emit('slashCommandCreate', cmd)
|
||||||
|
}
|
15
src/gateway/handlers/applicationCommandDelete.ts
Normal file
15
src/gateway/handlers/applicationCommandDelete.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { SlashCommand } from '../../models/slashClient.ts'
|
||||||
|
import { ApplicationCommandPayload } from '../../types/gateway.ts'
|
||||||
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
|
|
||||||
|
export const applicationCommandDelete: GatewayEventHandler = async (
|
||||||
|
gateway: Gateway,
|
||||||
|
d: ApplicationCommandPayload
|
||||||
|
) => {
|
||||||
|
const guild =
|
||||||
|
d.guild_id === undefined
|
||||||
|
? undefined
|
||||||
|
: await gateway.client.guilds.get(d.guild_id)
|
||||||
|
const cmd = new SlashCommand(gateway.client.slash.commands, d, guild)
|
||||||
|
gateway.client.emit('slashCommandDelete', cmd)
|
||||||
|
}
|
15
src/gateway/handlers/applicationCommandUpdate.ts
Normal file
15
src/gateway/handlers/applicationCommandUpdate.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { SlashCommand } from '../../models/slashClient.ts'
|
||||||
|
import { ApplicationCommandPayload } from '../../types/gateway.ts'
|
||||||
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
||||||
|
|
||||||
|
export const applicationCommandUpdate: GatewayEventHandler = async (
|
||||||
|
gateway: Gateway,
|
||||||
|
d: ApplicationCommandPayload
|
||||||
|
) => {
|
||||||
|
const guild =
|
||||||
|
d.guild_id === undefined
|
||||||
|
? undefined
|
||||||
|
: await gateway.client.guilds.get(d.guild_id)
|
||||||
|
const cmd = new SlashCommand(gateway.client.slash.commands, d, guild)
|
||||||
|
gateway.client.emit('slashCommandUpdate', cmd)
|
||||||
|
}
|
|
@ -63,11 +63,18 @@ import { CommandContext } from '../../models/command.ts'
|
||||||
import { RequestMethods } from '../../models/rest.ts'
|
import { RequestMethods } from '../../models/rest.ts'
|
||||||
import { PartialInvitePayload } from '../../types/invite.ts'
|
import { PartialInvitePayload } from '../../types/invite.ts'
|
||||||
import { GuildChannels } from '../../types/guild.ts'
|
import { GuildChannels } from '../../types/guild.ts'
|
||||||
|
import { applicationCommandCreate } from './applicationCommandCreate.ts'
|
||||||
|
import { applicationCommandDelete } from './applicationCommandDelete.ts'
|
||||||
|
import { applicationCommandUpdate } from './applicationCommandUpdate.ts'
|
||||||
|
import { SlashCommand } from '../../models/slashClient.ts'
|
||||||
|
|
||||||
export const gatewayHandlers: {
|
export const gatewayHandlers: {
|
||||||
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
|
||||||
} = {
|
} = {
|
||||||
READY: ready,
|
READY: ready,
|
||||||
|
APPLICATION_COMMAND_CREATE: applicationCommandCreate,
|
||||||
|
APPLICATION_COMMAND_DELETE: applicationCommandDelete,
|
||||||
|
APPLICATION_COMMAND_UPDATE: applicationCommandUpdate,
|
||||||
RECONNECT: reconnect,
|
RECONNECT: reconnect,
|
||||||
RESUMED: resume,
|
RESUMED: resume,
|
||||||
CHANNEL_CREATE: channelCreate,
|
CHANNEL_CREATE: channelCreate,
|
||||||
|
@ -394,7 +401,9 @@ export type ClientEvents = {
|
||||||
guildMemberUpdateUncached: [member: Member]
|
guildMemberUpdateUncached: [member: Member]
|
||||||
guildMemberRemoveUncached: [member: Member]
|
guildMemberRemoveUncached: [member: Member]
|
||||||
channelUpdateUncached: [channel: GuildChannels]
|
channelUpdateUncached: [channel: GuildChannels]
|
||||||
|
slashCommandCreate: [cmd: SlashCommand]
|
||||||
|
slashCommandUpdate: [cmd: SlashCommand]
|
||||||
|
slashCommandDelete: [cmd: SlashCommand]
|
||||||
commandOwnerOnly: [ctx: CommandContext]
|
commandOwnerOnly: [ctx: CommandContext]
|
||||||
commandGuildOnly: [ctx: CommandContext]
|
commandGuildOnly: [ctx: CommandContext]
|
||||||
commandDmOnly: [ctx: CommandContext]
|
commandDmOnly: [ctx: CommandContext]
|
||||||
|
|
|
@ -8,6 +8,12 @@ export const ready: GatewayEventHandler = async (
|
||||||
d: Ready
|
d: Ready
|
||||||
) => {
|
) => {
|
||||||
gateway.client.upSince = new Date()
|
gateway.client.upSince = new Date()
|
||||||
|
|
||||||
|
if ('application' in d) {
|
||||||
|
gateway.client.applicationID = d.application.id
|
||||||
|
gateway.client.applicationFlags = d.application.flags
|
||||||
|
}
|
||||||
|
|
||||||
await gateway.client.guilds.flush()
|
await gateway.client.guilds.flush()
|
||||||
|
|
||||||
await gateway.client.users.set(d.user.id, d.user)
|
await gateway.client.users.set(d.user.id, d.user)
|
||||||
|
|
|
@ -154,6 +154,9 @@ export class Client extends HarmonyEventEmitter<ClientEvents> {
|
||||||
return this.shards.list.get('0') as Gateway
|
return this.shards.list.get('0') as Gateway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applicationID?: string
|
||||||
|
applicationFlags?: number
|
||||||
|
|
||||||
constructor(options: ClientOptions = {}) {
|
constructor(options: ClientOptions = {}) {
|
||||||
super()
|
super()
|
||||||
this._id = options.id
|
this._id = options.id
|
||||||
|
|
|
@ -27,15 +27,21 @@ export class SlashCommand {
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
options: SlashCommandOption[]
|
options: SlashCommandOption[]
|
||||||
|
guild?: Guild
|
||||||
_guild?: string
|
_guild?: string
|
||||||
|
|
||||||
constructor(manager: SlashCommandsManager, data: SlashCommandPayload) {
|
constructor(
|
||||||
|
manager: SlashCommandsManager,
|
||||||
|
data: SlashCommandPayload,
|
||||||
|
guild?: Guild
|
||||||
|
) {
|
||||||
this.slash = manager
|
this.slash = manager
|
||||||
this.id = data.id
|
this.id = data.id
|
||||||
this.applicationID = data.application_id
|
this.applicationID = data.application_id
|
||||||
this.name = data.name
|
this.name = data.name
|
||||||
this.description = data.description
|
this.description = data.description
|
||||||
this.options = data.options ?? []
|
this.options = data.options ?? []
|
||||||
|
this.guild = guild
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(): Promise<void> {
|
async delete(): Promise<void> {
|
||||||
|
@ -236,8 +242,13 @@ export class SlashCommandsManager {
|
||||||
].commands.get()) as SlashCommandPayload[]
|
].commands.get()) as SlashCommandPayload[]
|
||||||
if (!Array.isArray(res)) return col
|
if (!Array.isArray(res)) return col
|
||||||
|
|
||||||
|
const _guild =
|
||||||
|
typeof guild === 'object'
|
||||||
|
? guild
|
||||||
|
: await this.slash.client?.guilds.get(guild)
|
||||||
|
|
||||||
for (const raw of res) {
|
for (const raw of res) {
|
||||||
const cmd = new SlashCommand(this, raw)
|
const cmd = new SlashCommand(this, raw, _guild)
|
||||||
cmd._guild = typeof guild === 'string' ? guild : guild.id
|
cmd._guild = typeof guild === 'string' ? guild : guild.id
|
||||||
col.set(raw.id, cmd)
|
col.set(raw.id, cmd)
|
||||||
}
|
}
|
||||||
|
@ -259,7 +270,14 @@ export class SlashCommandsManager {
|
||||||
|
|
||||||
const payload = await route.post(data)
|
const payload = await route.post(data)
|
||||||
|
|
||||||
const cmd = new SlashCommand(this, payload)
|
const _guild =
|
||||||
|
typeof guild === 'object'
|
||||||
|
? guild
|
||||||
|
: guild === undefined
|
||||||
|
? undefined
|
||||||
|
: await this.slash.client?.guilds.get(guild)
|
||||||
|
|
||||||
|
const cmd = new SlashCommand(this, payload, _guild)
|
||||||
cmd._guild =
|
cmd._guild =
|
||||||
typeof guild === 'string' || guild === undefined ? guild : guild.id
|
typeof guild === 'string' || guild === undefined ? guild : guild.id
|
||||||
|
|
||||||
|
@ -310,7 +328,14 @@ export class SlashCommandsManager {
|
||||||
|
|
||||||
const data = await route.get()
|
const data = await route.get()
|
||||||
|
|
||||||
return new SlashCommand(this, data)
|
const _guild =
|
||||||
|
typeof guild === 'object'
|
||||||
|
? guild
|
||||||
|
: guild === undefined
|
||||||
|
? undefined
|
||||||
|
: await this.slash.client?.guilds.get(guild)
|
||||||
|
|
||||||
|
return new SlashCommand(this, data, _guild)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Bulk Edit Global or Guild Slash Commands */
|
/** Bulk Edit Global or Guild Slash Commands */
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
ClientStatus
|
ClientStatus
|
||||||
} from './presence.ts'
|
} from './presence.ts'
|
||||||
import { RolePayload } from './role.ts'
|
import { RolePayload } from './role.ts'
|
||||||
|
import { SlashCommandPayload } from './slash.ts'
|
||||||
import { UserPayload } from './user.ts'
|
import { UserPayload } from './user.ts'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,7 +107,10 @@ export enum GatewayEvents {
|
||||||
Voice_Server_Update = 'VOICE_SERVER_UPDATE',
|
Voice_Server_Update = 'VOICE_SERVER_UPDATE',
|
||||||
Voice_State_Update = 'VOICE_STATE_UPDATE',
|
Voice_State_Update = 'VOICE_STATE_UPDATE',
|
||||||
Webhooks_Update = 'WEBHOOKS_UPDATE',
|
Webhooks_Update = 'WEBHOOKS_UPDATE',
|
||||||
Interaction_Create = 'INTERACTION_CREATE'
|
Interaction_Create = 'INTERACTION_CREATE',
|
||||||
|
Application_Command_Create = 'APPLICATION_COMMAND_CREATE',
|
||||||
|
Application_Command_Update = 'APPLICATION_COMMAND_UPDATE',
|
||||||
|
Application_Command_Delete = 'APPLICATION_COMMAND_DELETE'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IdentityPayload {
|
export interface IdentityPayload {
|
||||||
|
@ -168,6 +172,7 @@ export interface Ready {
|
||||||
guilds: []
|
guilds: []
|
||||||
session_id: string
|
session_id: string
|
||||||
shard?: number[]
|
shard?: number[]
|
||||||
|
application: { id: string; flags: number }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChannelPinsUpdatePayload {
|
export interface ChannelPinsUpdatePayload {
|
||||||
|
@ -344,3 +349,7 @@ export interface TypingStartGuildData {
|
||||||
guild: Guild
|
guild: Guild
|
||||||
member: Member
|
member: Member
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ApplicationCommandPayload extends SlashCommandPayload {
|
||||||
|
guild_id?: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue