refactor
This commit is contained in:
		
							parent
							
								
									7dc316c76f
								
							
						
					
					
						commit
						22e041f440
					
				
					 111 changed files with 1753 additions and 1713 deletions
				
			
		
							
								
								
									
										18
									
								
								deploy.ts
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								deploy.ts
									
										
									
									
									
								
							|  | @ -2,7 +2,7 @@ import { | ||||||
|   SlashCommandsManager, |   SlashCommandsManager, | ||||||
|   SlashClient, |   SlashClient, | ||||||
|   SlashCommandHandlerCallback |   SlashCommandHandlerCallback | ||||||
| } from './src/models/slashClient.ts' | } from './src/interactions/mod.ts' | ||||||
| import { InteractionResponseType, InteractionType } from './src/types/slash.ts' | import { InteractionResponseType, InteractionType } from './src/types/slash.ts' | ||||||
| 
 | 
 | ||||||
| export interface DeploySlashInitOptions { | export interface DeploySlashInitOptions { | ||||||
|  | @ -41,7 +41,7 @@ export function init(options: DeploySlashInitOptions): void { | ||||||
|     try { |     try { | ||||||
|       const d = await client.verifyFetchEvent({ |       const d = await client.verifyFetchEvent({ | ||||||
|         respondWith: (...args: any[]) => evt.respondWith(...args), |         respondWith: (...args: any[]) => evt.respondWith(...args), | ||||||
|         request: evt.request, |         request: evt.request | ||||||
|       }) |       }) | ||||||
|       if (d === false) { |       if (d === false) { | ||||||
|         await evt.respondWith( |         await evt.respondWith( | ||||||
|  | @ -85,9 +85,15 @@ export function handle( | ||||||
|     ...(typeof cmd === 'string' ? {} : cmd) |     ...(typeof cmd === 'string' ? {} : cmd) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (typeof handle.name === 'string' && handle.name.includes(' ') && handle.parent === undefined && handle.group === undefined) { |   if ( | ||||||
|     const parts = handle.name.split(/ +/).filter(e => e !== '') |     typeof handle.name === 'string' && | ||||||
|     if (parts.length > 3 || parts.length < 1) throw new Error('Invalid command name') |     handle.name.includes(' ') && | ||||||
|  |     handle.parent === undefined && | ||||||
|  |     handle.group === undefined | ||||||
|  |   ) { | ||||||
|  |     const parts = handle.name.split(/ +/).filter((e) => e !== '') | ||||||
|  |     if (parts.length > 3 || parts.length < 1) | ||||||
|  |       throw new Error('Invalid command name') | ||||||
|     const root = parts.shift() as string |     const root = parts.shift() as string | ||||||
|     const group = parts.length === 2 ? parts.shift() : undefined |     const group = parts.length === 2 ? parts.shift() : undefined | ||||||
|     const sub = parts.shift() |     const sub = parts.shift() | ||||||
|  | @ -103,4 +109,4 @@ export function handle( | ||||||
| export { commands, client } | export { commands, client } | ||||||
| export * from './src/types/slash.ts' | export * from './src/types/slash.ts' | ||||||
| export * from './src/structures/slash.ts' | export * from './src/structures/slash.ts' | ||||||
| export * from './src/models/slashClient.ts' | export * from './src/interactions/mod.ts' | ||||||
|  |  | ||||||
							
								
								
									
										34
									
								
								mod.ts
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								mod.ts
									
										
									
									
									
								
							|  | @ -1,20 +1,18 @@ | ||||||
| export { GatewayIntents } from './src/types/gateway.ts' | export { GatewayIntents } from './src/types/gateway.ts' | ||||||
| export { Base } from './src/structures/base.ts' | export { Base } from './src/structures/base.ts' | ||||||
| export { Gateway } from './src/gateway/index.ts' | export { Gateway } from './src/gateway/mod.ts' | ||||||
| export type { GatewayTypedEvents } from './src/gateway/index.ts' | export type { GatewayTypedEvents } from './src/gateway/mod.ts' | ||||||
| export type { ClientEvents } from './src/gateway/handlers/index.ts' | export type { ClientEvents } from './src/gateway/handlers/mod.ts' | ||||||
| export * from './src/models/client.ts' | export * from './src/client/mod.ts' | ||||||
| export * from './src/models/slashClient.ts' | export * from './src/interactions/mod.ts' | ||||||
| export { | export { | ||||||
|   RESTManager, |   RESTManager, | ||||||
|   TokenType, |   TokenType, | ||||||
|   HttpResponseCode, |   HttpResponseCode, | ||||||
|   DiscordAPIError |   DiscordAPIError | ||||||
| } from './src/models/rest.ts' | } from './src/rest/mod.ts' | ||||||
| export type { APIMap, DiscordAPIErrorPayload } from './src/models/rest.ts' | export * from './src/rest/mod.ts' | ||||||
| export type { RequestHeaders } from './src/models/rest.ts' | export * from './src/cache/adapter.ts' | ||||||
| export type { RESTOptions } from './src/models/rest.ts' |  | ||||||
| export * from './src/models/cacheAdapter.ts' |  | ||||||
| export { | export { | ||||||
|   Command, |   Command, | ||||||
|   CommandBuilder, |   CommandBuilder, | ||||||
|  | @ -22,16 +20,16 @@ export { | ||||||
|   CommandsManager, |   CommandsManager, | ||||||
|   CategoriesManager, |   CategoriesManager, | ||||||
|   CommandsLoader |   CommandsLoader | ||||||
| } from './src/models/command.ts' | } from './src/commands/command.ts' | ||||||
| export type { CommandContext, CommandOptions } from './src/models/command.ts' | export type { CommandContext, CommandOptions } from './src/commands/command.ts' | ||||||
| export { | export { | ||||||
|   Extension, |   Extension, | ||||||
|   ExtensionCommands, |   ExtensionCommands, | ||||||
|   ExtensionsManager |   ExtensionsManager | ||||||
| } from './src/models/extensions.ts' | } from './src/commands/extension.ts' | ||||||
| export { SlashModule } from './src/models/slashModule.ts' | export { SlashModule } from './src/interactions/slashModule.ts' | ||||||
| export { CommandClient, command } from './src/models/commandClient.ts' | export { CommandClient, command } from './src/commands/client.ts' | ||||||
| export type { CommandClientOptions } from './src/models/commandClient.ts' | export type { CommandClientOptions } from './src/commands/client.ts' | ||||||
| export { BaseManager } from './src/managers/base.ts' | export { BaseManager } from './src/managers/base.ts' | ||||||
| export { BaseChildManager } from './src/managers/baseChild.ts' | export { BaseChildManager } from './src/managers/baseChild.ts' | ||||||
| export { ChannelsManager } from './src/managers/channels.ts' | export { ChannelsManager } from './src/managers/channels.ts' | ||||||
|  | @ -165,8 +163,8 @@ export type { UserPayload } from './src/types/user.ts' | ||||||
| export { UserFlags } from './src/types/userFlags.ts' | export { UserFlags } from './src/types/userFlags.ts' | ||||||
| export type { VoiceStatePayload } from './src/types/voice.ts' | export type { VoiceStatePayload } from './src/types/voice.ts' | ||||||
| export type { WebhookPayload } from './src/types/webhook.ts' | export type { WebhookPayload } from './src/types/webhook.ts' | ||||||
| export * from './src/models/collectors.ts' | export * from './src/client/collectors.ts' | ||||||
| export type { Dict } from './src/utils/dict.ts' | export type { Dict } from './src/utils/dict.ts' | ||||||
| export * from './src/models/redisCache.ts' | export * from './src/cache/redis.ts' | ||||||
| export { ColorUtil } from './src/utils/colorutil.ts' | export { ColorUtil } from './src/utils/colorutil.ts' | ||||||
| export type { Colors } from './src/utils/colorutil.ts' | export type { Colors } from './src/utils/colorutil.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,9 @@ | ||||||
| import { ICacheAdapter } from './cacheAdapter.ts' | import { ICacheAdapter } from './adapter.ts' | ||||||
| import { connect, Redis, RedisConnectOptions } from 'https://deno.land/x/redis@v0.14.1/mod.ts' | import { | ||||||
|  |   connect, | ||||||
|  |   Redis, | ||||||
|  |   RedisConnectOptions | ||||||
|  | } from 'https://deno.land/x/redis@v0.14.1/mod.ts' | ||||||
| 
 | 
 | ||||||
| /** Redis Cache Adapter for using Redis as a cache-provider. */ | /** Redis Cache Adapter for using Redis as a cache-provider. */ | ||||||
| export class RedisCacheAdapter implements ICacheAdapter { | export class RedisCacheAdapter implements ICacheAdapter { | ||||||
|  | @ -1,23 +1,23 @@ | ||||||
| /* eslint-disable @typescript-eslint/method-signature-style */ | /* eslint-disable @typescript-eslint/method-signature-style */ | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { GatewayIntents } from '../types/gateway.ts' | import { GatewayIntents } from '../types/gateway.ts' | ||||||
| import { Gateway } from '../gateway/index.ts' | import { Gateway } from '../gateway/mod.ts' | ||||||
| import { RESTManager, RESTOptions, TokenType } from './rest.ts' | import { RESTManager, RESTOptions, TokenType } from '../rest/mod.ts' | ||||||
| import { DefaultCacheAdapter, ICacheAdapter } from './cacheAdapter.ts' | import { DefaultCacheAdapter, ICacheAdapter } from '../cache/adapter.ts' | ||||||
| import { UsersManager } from '../managers/users.ts' | import { UsersManager } from '../managers/users.ts' | ||||||
| import { GuildManager } from '../managers/guilds.ts' | import { GuildManager } from '../managers/guilds.ts' | ||||||
| import { ChannelsManager } from '../managers/channels.ts' | import { ChannelsManager } from '../managers/channels.ts' | ||||||
| import { ClientPresence } from '../structures/presence.ts' | import { ClientPresence } from '../structures/presence.ts' | ||||||
| import { EmojisManager } from '../managers/emojis.ts' | import { EmojisManager } from '../managers/emojis.ts' | ||||||
| import { ActivityGame, ClientActivity } from '../types/presence.ts' | import { ActivityGame, ClientActivity } from '../types/presence.ts' | ||||||
| import { Extension } from './extensions.ts' | import type { Extension } from '../commands/extension.ts' | ||||||
| import { SlashClient } from './slashClient.ts' | import { SlashClient } from '../interactions/slashClient.ts' | ||||||
| import { Interaction } from '../structures/slash.ts' | import { Interaction } from '../structures/slash.ts' | ||||||
| import { ShardManager } from './shard.ts' | import { ShardManager } from './shard.ts' | ||||||
| import { Application } from '../structures/application.ts' | import { Application } from '../structures/application.ts' | ||||||
| import { Invite } from '../structures/invite.ts' | import { Invite } from '../structures/invite.ts' | ||||||
| import { INVITE } from '../types/endpoint.ts' | import { INVITE } from '../types/endpoint.ts' | ||||||
| import { ClientEvents } from '../gateway/handlers/index.ts' | import { ClientEvents } from '../gateway/handlers/mod.ts' | ||||||
| import type { Collector } from './collectors.ts' | import type { Collector } from './collectors.ts' | ||||||
| import { HarmonyEventEmitter } from '../utils/events.ts' | import { HarmonyEventEmitter } from '../utils/events.ts' | ||||||
| import { VoiceRegion } from '../types/voice.ts' | import { VoiceRegion } from '../types/voice.ts' | ||||||
|  | @ -207,7 +207,7 @@ export class Client extends HarmonyEventEmitter<ClientEvents> { | ||||||
|           this.token = token |           this.token = token | ||||||
|           this.debug('Info', 'Found token in ENV') |           this.debug('Info', 'Found token in ENV') | ||||||
|         } |         } | ||||||
|       } catch (e) { } |       } catch (e) {} | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const restOptions: RESTOptions = { |     const restOptions: RESTOptions = { | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import type { Client } from './client.ts' | import type { Client } from '../client/mod.ts' | ||||||
| import { HarmonyEventEmitter } from '../utils/events.ts' | import { HarmonyEventEmitter } from '../utils/events.ts' | ||||||
| 
 | 
 | ||||||
| export type CollectorFilter = (...args: any[]) => boolean | Promise<boolean> | export type CollectorFilter = (...args: any[]) => boolean | Promise<boolean> | ||||||
							
								
								
									
										3
									
								
								src/client/mod.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/client/mod.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | export * from './client.ts' | ||||||
|  | export * from './collectors.ts' | ||||||
|  | export * from './shard.ts' | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import type { Client } from './client.ts' | import type { Client } from './client.ts' | ||||||
| import { RESTManager } from './rest.ts' | import { RESTManager } from '../rest/mod.ts' | ||||||
| import { Gateway } from '../gateway/index.ts' | import { Gateway } from '../gateway/mod.ts' | ||||||
| import { HarmonyEventEmitter } from '../utils/events.ts' | import { HarmonyEventEmitter } from '../utils/events.ts' | ||||||
| import { GatewayEvents } from '../types/gateway.ts' | import { GatewayEvents } from '../types/gateway.ts' | ||||||
| import { delay } from '../utils/delay.ts' | import { delay } from '../utils/delay.ts' | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { Message } from '../structures/message.ts' | import { Message } from '../structures/message.ts' | ||||||
| import { GuildTextBasedChannel } from '../structures/guildTextChannel.ts' | import { GuildTextBasedChannel } from '../structures/guildTextChannel.ts' | ||||||
| import { Client, ClientOptions } from './client.ts' | import { Client, ClientOptions } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   CategoriesManager, |   CategoriesManager, | ||||||
|   Command, |   Command, | ||||||
|  | @ -9,7 +9,7 @@ import { | ||||||
|   CommandsManager, |   CommandsManager, | ||||||
|   parseCommand |   parseCommand | ||||||
| } from './command.ts' | } from './command.ts' | ||||||
| import { Extension, ExtensionsManager } from './extensions.ts' | import { Extension, ExtensionsManager } from './extension.ts' | ||||||
| 
 | 
 | ||||||
| type PrefixReturnType = string | string[] | Promise<string | string[]> | type PrefixReturnType = string | string[] | Promise<string | string[]> | ||||||
| 
 | 
 | ||||||
|  | @ -3,8 +3,8 @@ import { Message } from '../structures/message.ts' | ||||||
| import { TextChannel } from '../structures/textChannel.ts' | import { TextChannel } from '../structures/textChannel.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import { CommandClient } from './commandClient.ts' | import type { CommandClient } from './client.ts' | ||||||
| import { Extension } from './extensions.ts' | import type { Extension } from './extension.ts' | ||||||
| import { join, walk } from '../../deps.ts' | import { join, walk } from '../../deps.ts' | ||||||
| 
 | 
 | ||||||
| export interface CommandContext { | export interface CommandContext { | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { ClientEvents } from '../../mod.ts' | import { ClientEvents } from '../../mod.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import { Command } from './command.ts' | import { Command } from './command.ts' | ||||||
| import { CommandClient } from './commandClient.ts' | import { CommandClient } from './client.ts' | ||||||
| 
 | 
 | ||||||
| export type ExtensionEventCallback = (ext: Extension, ...args: any[]) => any | export type ExtensionEventCallback = (ext: Extension, ...args: any[]) => any | ||||||
| 
 | 
 | ||||||
							
								
								
									
										3
									
								
								src/commands/mod.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/commands/mod.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | export * from './client.ts' | ||||||
|  | export * from './command.ts' | ||||||
|  | export * from './extension.ts' | ||||||
|  | @ -1,9 +0,0 @@ | ||||||
| export const DISCORD_API_URL: string = 'https://discord.com/api' |  | ||||||
| 
 |  | ||||||
| export const DISCORD_GATEWAY_URL: string = 'wss://gateway.discord.gg' |  | ||||||
| 
 |  | ||||||
| export const DISCORD_CDN_URL: string = 'https://cdn.discordapp.com' |  | ||||||
| 
 |  | ||||||
| export const DISCORD_API_VERSION: number = 8 |  | ||||||
| 
 |  | ||||||
| export const DISCORD_VOICE_VERSION: number = 4 |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { SlashCommand } from '../../models/slashClient.ts' | import { SlashCommand } from '../../interactions/slashCommand.ts' | ||||||
| import { ApplicationCommandPayload } from '../../types/gateway.ts' | import { ApplicationCommandPayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const applicationCommandCreate: GatewayEventHandler = async ( | export const applicationCommandCreate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { SlashCommand } from '../../models/slashClient.ts' | import { SlashCommand } from '../../interactions/slashCommand.ts' | ||||||
| import { ApplicationCommandPayload } from '../../types/gateway.ts' | import { ApplicationCommandPayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const applicationCommandDelete: GatewayEventHandler = async ( | export const applicationCommandDelete: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { SlashCommand } from '../../models/slashClient.ts' | import { SlashCommand } from '../../interactions/slashCommand.ts' | ||||||
| import { ApplicationCommandPayload } from '../../types/gateway.ts' | import { ApplicationCommandPayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const applicationCommandUpdate: GatewayEventHandler = async ( | export const applicationCommandUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import getChannelByType from '../../utils/getChannelByType.ts' | import getChannelByType from '../../utils/getChannelByType.ts' | ||||||
| import { ChannelPayload, GuildChannelPayload } from '../../types/channel.ts' | import { ChannelPayload, GuildChannelPayload } from '../../types/channel.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { ChannelPayload } from '../../types/channel.ts' | import { ChannelPayload } from '../../types/channel.ts' | ||||||
| 
 | 
 | ||||||
| export const channelDelete: GatewayEventHandler = async ( | export const channelDelete: GatewayEventHandler = async ( | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { ChannelPinsUpdatePayload } from '../../types/gateway.ts' | import { ChannelPinsUpdatePayload } from '../../types/gateway.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { Channel } from '../../structures/channel.ts' | import { Channel } from '../../structures/channel.ts' | ||||||
| import { ChannelPayload } from '../../types/channel.ts' | import { ChannelPayload } from '../../types/channel.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const channelUpdate: GatewayEventHandler = async ( | export const channelUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { GuildBanAddPayload } from '../../types/gateway.ts' | import { GuildBanAddPayload } from '../../types/gateway.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { GuildBanRemovePayload } from '../../types/gateway.ts' | import { GuildBanRemovePayload } from '../../types/gateway.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildPayload } from '../../types/guild.ts' | import { GuildPayload } from '../../types/guild.ts' | ||||||
| import { GuildChannelPayload } from '../../types/channel.ts' | import { GuildChannelPayload } from '../../types/channel.ts' | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildPayload } from '../../types/guild.ts' | import { GuildPayload } from '../../types/guild.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const guildDelete: GatewayEventHandler = async ( | export const guildDelete: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Emoji } from '../../structures/emoji.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { EmojiPayload } from '../../types/emoji.ts' | import { EmojiPayload } from '../../types/emoji.ts' | ||||||
| import { GuildEmojiUpdatePayload } from '../../types/gateway.ts' | import { GuildEmojiUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const guildEmojiUpdate: GatewayEventHandler = async ( | export const guildEmojiUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildIntegrationsUpdatePayload } from '../../types/gateway.ts' | import { GuildIntegrationsUpdatePayload } from '../../types/gateway.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildMemberAddPayload } from '../../types/gateway.ts' | import { GuildMemberAddPayload } from '../../types/gateway.ts' | ||||||
| import { Member } from '../../structures/member.ts' | import { Member } from '../../structures/member.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { GuildMemberRemovePayload } from '../../types/gateway.ts' | import { GuildMemberRemovePayload } from '../../types/gateway.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildMemberUpdatePayload } from '../../types/gateway.ts' | import { GuildMemberUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { MemberPayload } from '../../types/guild.ts' | import { MemberPayload } from '../../types/guild.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildMemberChunkPayload } from '../../types/gateway.ts' | import { GuildMemberChunkPayload } from '../../types/gateway.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildRoleCreatePayload } from '../../types/gateway.ts' | import { GuildRoleCreatePayload } from '../../types/gateway.ts' | ||||||
| import { Role } from '../../structures/role.ts' | import { Role } from '../../structures/role.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildRoleDeletePayload } from '../../types/gateway.ts' | import { GuildRoleDeletePayload } from '../../types/gateway.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildRoleUpdatePayload } from '../../types/gateway.ts' | import { GuildRoleUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { Role } from '../../structures/role.ts' | import { Role } from '../../structures/role.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildPayload } from '../../types/guild.ts' | import { GuildPayload } from '../../types/guild.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ import { GuildTextBasedChannel } from '../../structures/guildTextChannel.ts' | ||||||
| import { InteractionPayload } from '../../types/slash.ts' | import { InteractionPayload } from '../../types/slash.ts' | ||||||
| import { UserPayload } from '../../types/user.ts' | import { UserPayload } from '../../types/user.ts' | ||||||
| import { Permissions } from '../../utils/permissions.ts' | import { Permissions } from '../../utils/permissions.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { Role } from '../../structures/role.ts' | import { Role } from '../../structures/role.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { InviteCreatePayload } from '../../types/gateway.ts' | import { InviteCreatePayload } from '../../types/gateway.ts' | ||||||
| import { ChannelPayload } from '../../types/channel.ts' | import { ChannelPayload } from '../../types/channel.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { InviteDeletePayload } from '../../types/gateway.ts' | import { InviteDeletePayload } from '../../types/gateway.ts' | ||||||
| import { PartialInvitePayload } from '../../types/invite.ts' | import { PartialInvitePayload } from '../../types/invite.ts' | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Message } from '../../structures/message.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { MessagePayload } from '../../types/channel.ts' | import { MessagePayload } from '../../types/channel.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const messageCreate: GatewayEventHandler = async ( | export const messageCreate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { MessageDeletePayload } from '../../types/gateway.ts' | import { MessageDeletePayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const messageDelete: GatewayEventHandler = async ( | export const messageDelete: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Message } from '../../structures/message.ts' | ||||||
| import { GuildTextBasedChannel } from '../../structures/guildTextChannel.ts' | import { GuildTextBasedChannel } from '../../structures/guildTextChannel.ts' | ||||||
| import { MessageDeleteBulkPayload } from '../../types/gateway.ts' | import { MessageDeleteBulkPayload } from '../../types/gateway.ts' | ||||||
| import { Collection } from '../../utils/collection.ts' | import { Collection } from '../../utils/collection.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const messageDeleteBulk: GatewayEventHandler = async ( | export const messageDeleteBulk: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { MessageReactionAddPayload } from '../../types/gateway.ts' | import { MessageReactionAddPayload } from '../../types/gateway.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { MessageReaction } from '../../structures/messageReaction.ts' | import { MessageReaction } from '../../structures/messageReaction.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { MessageReactionRemovePayload } from '../../types/gateway.ts' | import { MessageReactionRemovePayload } from '../../types/gateway.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { MessageReactionRemoveAllPayload } from '../../types/gateway.ts' | import { MessageReactionRemoveAllPayload } from '../../types/gateway.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { MessageReactionRemoveEmojiPayload } from '../../types/gateway.ts' | import { MessageReactionRemoveEmojiPayload } from '../../types/gateway.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Message } from '../../structures/message.ts' | import { Message } from '../../structures/message.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { MessagePayload } from '../../types/channel.ts' | import { MessagePayload } from '../../types/channel.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const messageUpdate: GatewayEventHandler = async ( | export const messageUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { GatewayEventHandler } from '../index.ts' | import type { GatewayEventHandler } from '../mod.ts' | ||||||
| import { | import { | ||||||
|   GatewayEvents, |   GatewayEvents, | ||||||
|   MessageDeletePayload, |   MessageDeletePayload, | ||||||
|  | @ -60,14 +60,14 @@ import { | ||||||
| } from '../../utils/getChannelByType.ts' | } from '../../utils/getChannelByType.ts' | ||||||
| import { interactionCreate } from './interactionCreate.ts' | import { interactionCreate } from './interactionCreate.ts' | ||||||
| import { Interaction } from '../../structures/slash.ts' | import { Interaction } from '../../structures/slash.ts' | ||||||
| import { CommandContext } from '../../models/command.ts' | import { CommandContext } from '../../commands/command.ts' | ||||||
| import { RequestMethods } from '../../models/rest.ts' | import { RequestMethods } from '../../rest/types.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 { applicationCommandCreate } from './applicationCommandCreate.ts' | ||||||
| import { applicationCommandDelete } from './applicationCommandDelete.ts' | import { applicationCommandDelete } from './applicationCommandDelete.ts' | ||||||
| import { applicationCommandUpdate } from './applicationCommandUpdate.ts' | import { applicationCommandUpdate } from './applicationCommandUpdate.ts' | ||||||
| import { SlashCommand } from '../../models/slashClient.ts' | import { SlashCommand } from '../../interactions/slashCommand.ts' | ||||||
| 
 | 
 | ||||||
| export const gatewayHandlers: { | export const gatewayHandlers: { | ||||||
|   [eventCode in GatewayEvents]: GatewayEventHandler | undefined |   [eventCode in GatewayEvents]: GatewayEventHandler | undefined | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { PresenceUpdatePayload } from '../../types/gateway.ts' | import { PresenceUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const presenceUpdate: GatewayEventHandler = async ( | export const presenceUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { Ready } from '../../types/gateway.ts' | import { Ready } from '../../types/gateway.ts' | ||||||
| import { GuildPayload } from '../../types/guild.ts' | import { GuildPayload } from '../../types/guild.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const ready: GatewayEventHandler = async ( | export const ready: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const reconnect: GatewayEventHandler = async ( | export const reconnect: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { CLIENT_USER } from '../../types/endpoint.ts' | import { CLIENT_USER } from '../../types/endpoint.ts' | ||||||
| import { Resume } from '../../types/gateway.ts' | import { Resume } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const resume: GatewayEventHandler = async ( | export const resume: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Member } from '../../structures/member.ts' | import { Member } from '../../structures/member.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { TypingStartPayload } from '../../types/gateway.ts' | import { TypingStartPayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| // TODO: Do we need to add uncached events here?
 | // TODO: Do we need to add uncached events here?
 | ||||||
| export const typingStart: GatewayEventHandler = async ( | export const typingStart: GatewayEventHandler = async ( | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { User } from '../../structures/user.ts' | import { User } from '../../structures/user.ts' | ||||||
| import { UserPayload } from '../../types/user.ts' | import { UserPayload } from '../../types/user.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const userUpdate: GatewayEventHandler = async ( | export const userUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { VoiceServerUpdatePayload } from '../../types/gateway.ts' | import { VoiceServerUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const voiceServerUpdate: GatewayEventHandler = async ( | export const voiceServerUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Guild } from '../../structures/guild.ts' | ||||||
| import { VoiceState } from '../../structures/voiceState.ts' | import { VoiceState } from '../../structures/voiceState.ts' | ||||||
| import { MemberPayload } from '../../types/guild.ts' | import { MemberPayload } from '../../types/guild.ts' | ||||||
| import { VoiceStatePayload } from '../../types/voice.ts' | import { VoiceStatePayload } from '../../types/voice.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const voiceStateUpdate: GatewayEventHandler = async ( | export const voiceStateUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import type { Gateway, GatewayEventHandler } from '../mod.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { WebhooksUpdatePayload } from '../../types/gateway.ts' | import { WebhooksUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { GuildTextBasedChannel } from '../../structures/guildTextChannel.ts' | import { GuildTextBasedChannel } from '../../structures/guildTextChannel.ts' | ||||||
|  |  | ||||||
|  | @ -1,9 +1,5 @@ | ||||||
| import { unzlib } from '../../deps.ts' | import { unzlib } from '../../deps.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { |  | ||||||
|   DISCORD_GATEWAY_URL, |  | ||||||
|   DISCORD_API_VERSION |  | ||||||
| } from '../consts/urlsAndVersions.ts' |  | ||||||
| import { GatewayResponse } from '../types/gatewayResponse.ts' | import { GatewayResponse } from '../types/gatewayResponse.ts' | ||||||
| import { | import { | ||||||
|   GatewayOpcodes, |   GatewayOpcodes, | ||||||
|  | @ -12,13 +8,14 @@ import { | ||||||
|   StatusUpdatePayload, |   StatusUpdatePayload, | ||||||
|   GatewayEvents |   GatewayEvents | ||||||
| } from '../types/gateway.ts' | } from '../types/gateway.ts' | ||||||
| import { gatewayHandlers } from './handlers/index.ts' | import { gatewayHandlers } from './handlers/mod.ts' | ||||||
| import { GatewayCache } from '../managers/gatewayCache.ts' | import { GatewayCache } from '../managers/gatewayCache.ts' | ||||||
| import { delay } from '../utils/delay.ts' | import { delay } from '../utils/delay.ts' | ||||||
| import { VoiceChannel } from '../structures/guildVoiceChannel.ts' | import { VoiceChannel } from '../structures/guildVoiceChannel.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { HarmonyEventEmitter } from '../utils/events.ts' | import { HarmonyEventEmitter } from '../utils/events.ts' | ||||||
| import { decodeText } from '../utils/encoding.ts' | import { decodeText } from '../utils/encoding.ts' | ||||||
|  | import { Constants } from '../types/constants.ts' | ||||||
| 
 | 
 | ||||||
| export interface RequestMembersOptions { | export interface RequestMembersOptions { | ||||||
|   limit?: number |   limit?: number | ||||||
|  | @ -417,7 +414,7 @@ export class Gateway extends HarmonyEventEmitter<GatewayTypedEvents> { | ||||||
|     this.debug('Initializing WebSocket...') |     this.debug('Initializing WebSocket...') | ||||||
|     this.websocket = new WebSocket( |     this.websocket = new WebSocket( | ||||||
|       // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
 |       // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
 | ||||||
|       `${DISCORD_GATEWAY_URL}/?v=${DISCORD_API_VERSION}&encoding=json`, |       `${Constants.DISCORD_GATEWAY_URL}/?v=${Constants.DISCORD_API_VERSION}&encoding=json`, | ||||||
|       [] |       [] | ||||||
|     ) |     ) | ||||||
|     this.websocket.binaryType = 'arraybuffer' |     this.websocket.binaryType = 'arraybuffer' | ||||||
							
								
								
									
										3
									
								
								src/interactions/mod.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/interactions/mod.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | export * from './slashClient.ts' | ||||||
|  | export * from './slashModule.ts' | ||||||
|  | export * from './slashCommand.ts' | ||||||
|  | @ -1,4 +1,3 @@ | ||||||
| import type { Guild } from '../structures/guild.ts' |  | ||||||
| import { | import { | ||||||
|   Interaction, |   Interaction, | ||||||
|   InteractionApplicationCommandResolved |   InteractionApplicationCommandResolved | ||||||
|  | @ -7,358 +6,16 @@ import { | ||||||
|   InteractionPayload, |   InteractionPayload, | ||||||
|   InteractionResponsePayload, |   InteractionResponsePayload, | ||||||
|   InteractionType, |   InteractionType, | ||||||
|   SlashCommandChoice, |   SlashCommandOptionType | ||||||
|   SlashCommandOption, |  | ||||||
|   SlashCommandOptionType, |  | ||||||
|   SlashCommandPartial, |  | ||||||
|   SlashCommandPayload |  | ||||||
| } from '../types/slash.ts' | } from '../types/slash.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import type { Client } from '../client/mod.ts' | ||||||
| import type { Client } from './client.ts' | import { RESTManager } from '../rest/mod.ts' | ||||||
| import { RESTManager } from './rest.ts' |  | ||||||
| import { SlashModule } from './slashModule.ts' | import { SlashModule } from './slashModule.ts' | ||||||
| import { verify as edverify } from 'https://deno.land/x/ed25519@1.0.1/mod.ts' | import { verify as edverify } from 'https://deno.land/x/ed25519@1.0.1/mod.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { HarmonyEventEmitter } from '../utils/events.ts' | import { HarmonyEventEmitter } from '../utils/events.ts' | ||||||
| import { encodeText, decodeText } from '../utils/encoding.ts' | import { encodeText, decodeText } from '../utils/encoding.ts' | ||||||
| 
 | import { SlashCommandsManager } from './slashCommand.ts' | ||||||
| export class SlashCommand { |  | ||||||
|   slash: SlashCommandsManager |  | ||||||
|   id: string |  | ||||||
|   applicationID: string |  | ||||||
|   name: string |  | ||||||
|   description: string |  | ||||||
|   options: SlashCommandOption[] |  | ||||||
|   guild?: Guild |  | ||||||
|   _guild?: string |  | ||||||
| 
 |  | ||||||
|   constructor( |  | ||||||
|     manager: SlashCommandsManager, |  | ||||||
|     data: SlashCommandPayload, |  | ||||||
|     guild?: Guild |  | ||||||
|   ) { |  | ||||||
|     this.slash = manager |  | ||||||
|     this.id = data.id |  | ||||||
|     this.applicationID = data.application_id |  | ||||||
|     this.name = data.name |  | ||||||
|     this.description = data.description |  | ||||||
|     this.options = data.options ?? [] |  | ||||||
|     this.guild = guild |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async delete(): Promise<void> { |  | ||||||
|     await this.slash.delete(this.id, this._guild) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async edit(data: SlashCommandPartial): Promise<void> { |  | ||||||
|     await this.slash.edit(this.id, data, this._guild) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Create a handler for this Slash Command */ |  | ||||||
|   handle( |  | ||||||
|     func: SlashCommandHandlerCallback, |  | ||||||
|     options?: { parent?: string; group?: string } |  | ||||||
|   ): SlashCommand { |  | ||||||
|     this.slash.slash.handle({ |  | ||||||
|       name: this.name, |  | ||||||
|       parent: options?.parent, |  | ||||||
|       group: options?.group, |  | ||||||
|       guild: this._guild, |  | ||||||
|       handler: func |  | ||||||
|     }) |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export interface CreateOptions { |  | ||||||
|   name: string |  | ||||||
|   description?: string |  | ||||||
|   options?: Array<SlashCommandOption | SlashOptionCallable> |  | ||||||
|   choices?: Array<SlashCommandChoice | string> |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function createSlashOption( |  | ||||||
|   type: SlashCommandOptionType, |  | ||||||
|   data: CreateOptions |  | ||||||
| ): SlashCommandOption { |  | ||||||
|   return { |  | ||||||
|     name: data.name, |  | ||||||
|     type, |  | ||||||
|     description: |  | ||||||
|       type === 0 || type === 1 |  | ||||||
|         ? undefined |  | ||||||
|         : data.description ?? 'No description.', |  | ||||||
|     options: data.options?.map((e) => |  | ||||||
|       typeof e === 'function' ? e(SlashOption) : e |  | ||||||
|     ), |  | ||||||
|     choices: |  | ||||||
|       data.choices === undefined |  | ||||||
|         ? undefined |  | ||||||
|         : data.choices.map((e) => |  | ||||||
|             typeof e === 'string' ? { name: e, value: e } : e |  | ||||||
|           ) |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // eslint-disable-next-line @typescript-eslint/no-extraneous-class
 |  | ||||||
| export class SlashOption { |  | ||||||
|   static string(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.STRING, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static bool(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.BOOLEAN, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static subCommand(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.SUB_COMMAND, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static subCommandGroup(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.SUB_COMMAND_GROUP, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static role(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.ROLE, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static channel(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.CHANNEL, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static user(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.USER, data) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   static number(data: CreateOptions): SlashCommandOption { |  | ||||||
|     return createSlashOption(SlashCommandOptionType.INTEGER, data) |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export type SlashOptionCallable = (o: typeof SlashOption) => SlashCommandOption |  | ||||||
| 
 |  | ||||||
| export type SlashBuilderOptionsData = |  | ||||||
|   | Array<SlashCommandOption | SlashOptionCallable> |  | ||||||
|   | { |  | ||||||
|       [name: string]: |  | ||||||
|         | { |  | ||||||
|             description: string |  | ||||||
|             type: SlashCommandOptionType |  | ||||||
|             options?: SlashCommandOption[] |  | ||||||
|             choices?: SlashCommandChoice[] |  | ||||||
|           } |  | ||||||
|         | SlashOptionCallable |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| function buildOptionsArray( |  | ||||||
|   options: SlashBuilderOptionsData |  | ||||||
| ): SlashCommandOption[] { |  | ||||||
|   return Array.isArray(options) |  | ||||||
|     ? options.map((op) => (typeof op === 'function' ? op(SlashOption) : op)) |  | ||||||
|     : Object.entries(options).map((entry) => |  | ||||||
|         typeof entry[1] === 'function' |  | ||||||
|           ? entry[1](SlashOption) |  | ||||||
|           : Object.assign(entry[1], { name: entry[0] }) |  | ||||||
|       ) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** Slash Command Builder */ |  | ||||||
| export class SlashBuilder { |  | ||||||
|   data: SlashCommandPartial |  | ||||||
| 
 |  | ||||||
|   constructor( |  | ||||||
|     name?: string, |  | ||||||
|     description?: string, |  | ||||||
|     options?: SlashBuilderOptionsData |  | ||||||
|   ) { |  | ||||||
|     this.data = { |  | ||||||
|       name: name ?? '', |  | ||||||
|       description: description ?? 'No description.', |  | ||||||
|       options: options === undefined ? [] : buildOptionsArray(options) |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   name(name: string): SlashBuilder { |  | ||||||
|     this.data.name = name |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   description(desc: string): SlashBuilder { |  | ||||||
|     this.data.description = desc |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   option(option: SlashOptionCallable | SlashCommandOption): SlashBuilder { |  | ||||||
|     if (this.data.options === undefined) this.data.options = [] |  | ||||||
|     this.data.options.push( |  | ||||||
|       typeof option === 'function' ? option(SlashOption) : option |  | ||||||
|     ) |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   options(options: SlashBuilderOptionsData): SlashBuilder { |  | ||||||
|     this.data.options = buildOptionsArray(options) |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   export(): SlashCommandPartial { |  | ||||||
|     if (this.data.name === '') |  | ||||||
|       throw new Error('Name was not provided in Slash Builder') |  | ||||||
|     return this.data |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** Manages Slash Commands, allows fetching/modifying/deleting/creating Slash Commands. */ |  | ||||||
| export class SlashCommandsManager { |  | ||||||
|   slash: SlashClient |  | ||||||
|   rest: RESTManager |  | ||||||
| 
 |  | ||||||
|   constructor(client: SlashClient) { |  | ||||||
|     this.slash = client |  | ||||||
|     this.rest = client.rest |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Get all Global Slash Commands */ |  | ||||||
|   async all(): Promise<Collection<string, SlashCommand>> { |  | ||||||
|     const col = new Collection<string, SlashCommand>() |  | ||||||
| 
 |  | ||||||
|     const res = (await this.rest.api.applications[ |  | ||||||
|       this.slash.getID() |  | ||||||
|     ].commands.get()) as SlashCommandPayload[] |  | ||||||
|     if (!Array.isArray(res)) return col |  | ||||||
| 
 |  | ||||||
|     for (const raw of res) { |  | ||||||
|       const cmd = new SlashCommand(this, raw) |  | ||||||
|       col.set(raw.id, cmd) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return col |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Get a Guild's Slash Commands */ |  | ||||||
|   async guild( |  | ||||||
|     guild: Guild | string |  | ||||||
|   ): Promise<Collection<string, SlashCommand>> { |  | ||||||
|     const col = new Collection<string, SlashCommand>() |  | ||||||
| 
 |  | ||||||
|     const res = (await this.rest.api.applications[this.slash.getID()].guilds[ |  | ||||||
|       typeof guild === 'string' ? guild : guild.id |  | ||||||
|     ].commands.get()) as SlashCommandPayload[] |  | ||||||
|     if (!Array.isArray(res)) return col |  | ||||||
| 
 |  | ||||||
|     const _guild = |  | ||||||
|       typeof guild === 'object' |  | ||||||
|         ? guild |  | ||||||
|         : await this.slash.client?.guilds.get(guild) |  | ||||||
| 
 |  | ||||||
|     for (const raw of res) { |  | ||||||
|       const cmd = new SlashCommand(this, raw, _guild) |  | ||||||
|       cmd._guild = typeof guild === 'string' ? guild : guild.id |  | ||||||
|       col.set(raw.id, cmd) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return col |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Create a Slash Command (global or Guild) */ |  | ||||||
|   async create( |  | ||||||
|     data: SlashCommandPartial, |  | ||||||
|     guild?: Guild | string |  | ||||||
|   ): Promise<SlashCommand> { |  | ||||||
|     const route = |  | ||||||
|       guild === undefined |  | ||||||
|         ? this.rest.api.applications[this.slash.getID()].commands |  | ||||||
|         : this.rest.api.applications[this.slash.getID()].guilds[ |  | ||||||
|             typeof guild === 'string' ? guild : guild.id |  | ||||||
|           ].commands |  | ||||||
| 
 |  | ||||||
|     const payload = await route.post(data) |  | ||||||
| 
 |  | ||||||
|     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 = |  | ||||||
|       typeof guild === 'string' || guild === undefined ? guild : guild.id |  | ||||||
| 
 |  | ||||||
|     return cmd |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Edit a Slash Command (global or Guild) */ |  | ||||||
|   async edit( |  | ||||||
|     id: string, |  | ||||||
|     data: SlashCommandPartial, |  | ||||||
|     guild?: Guild | string |  | ||||||
|   ): Promise<SlashCommandsManager> { |  | ||||||
|     const route = |  | ||||||
|       guild === undefined |  | ||||||
|         ? this.rest.api.applications[this.slash.getID()].commands[id] |  | ||||||
|         : this.rest.api.applications[this.slash.getID()].guilds[ |  | ||||||
|             typeof guild === 'string' ? guild : guild.id |  | ||||||
|           ].commands[id] |  | ||||||
| 
 |  | ||||||
|     await route.patch(data) |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Delete a Slash Command (global or Guild) */ |  | ||||||
|   async delete( |  | ||||||
|     id: string, |  | ||||||
|     guild?: Guild | string |  | ||||||
|   ): Promise<SlashCommandsManager> { |  | ||||||
|     const route = |  | ||||||
|       guild === undefined |  | ||||||
|         ? this.rest.api.applications[this.slash.getID()].commands[id] |  | ||||||
|         : this.rest.api.applications[this.slash.getID()].guilds[ |  | ||||||
|             typeof guild === 'string' ? guild : guild.id |  | ||||||
|           ].commands[id] |  | ||||||
| 
 |  | ||||||
|     await route.delete() |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** Get a Slash Command (global or Guild) */ |  | ||||||
|   async get(id: string, guild?: Guild | string): Promise<SlashCommand> { |  | ||||||
|     const route = |  | ||||||
|       guild === undefined |  | ||||||
|         ? this.rest.api.applications[this.slash.getID()].commands[id] |  | ||||||
|         : this.rest.api.applications[this.slash.getID()].guilds[ |  | ||||||
|             typeof guild === 'string' ? guild : guild.id |  | ||||||
|           ].commands[id] |  | ||||||
| 
 |  | ||||||
|     const data = await route.get() |  | ||||||
| 
 |  | ||||||
|     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 */ |  | ||||||
|   async bulkEdit( |  | ||||||
|     cmds: Array<SlashCommandPartial | SlashCommandPayload>, |  | ||||||
|     guild?: Guild | string |  | ||||||
|   ): Promise<SlashCommandsManager> { |  | ||||||
|     const route = |  | ||||||
|       guild === undefined |  | ||||||
|         ? this.rest.api.applications[this.slash.getID()].commands |  | ||||||
|         : this.rest.api.applications[this.slash.getID()].guilds[ |  | ||||||
|             typeof guild === 'string' ? guild : guild.id |  | ||||||
|           ].commands |  | ||||||
| 
 |  | ||||||
|     await route.put(cmds) |  | ||||||
| 
 |  | ||||||
|     return this |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| export type SlashCommandHandlerCallback = (interaction: Interaction) => unknown | export type SlashCommandHandlerCallback = (interaction: Interaction) => unknown | ||||||
| export interface SlashCommandHandler { | export interface SlashCommandHandler { | ||||||
							
								
								
									
										349
									
								
								src/interactions/slashCommand.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										349
									
								
								src/interactions/slashCommand.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,349 @@ | ||||||
|  | import { RESTManager } from '../rest/manager.ts' | ||||||
|  | import { Guild } from '../structures/guild.ts' | ||||||
|  | import { | ||||||
|  |   SlashCommandChoice, | ||||||
|  |   SlashCommandOption, | ||||||
|  |   SlashCommandOptionType, | ||||||
|  |   SlashCommandPartial, | ||||||
|  |   SlashCommandPayload | ||||||
|  | } from '../types/slash.ts' | ||||||
|  | import { Collection } from '../utils/collection.ts' | ||||||
|  | import type { SlashClient, SlashCommandHandlerCallback } from './slashClient.ts' | ||||||
|  | 
 | ||||||
|  | export class SlashCommand { | ||||||
|  |   slash: SlashCommandsManager | ||||||
|  |   id: string | ||||||
|  |   applicationID: string | ||||||
|  |   name: string | ||||||
|  |   description: string | ||||||
|  |   options: SlashCommandOption[] | ||||||
|  |   guild?: Guild | ||||||
|  |   _guild?: string | ||||||
|  | 
 | ||||||
|  |   constructor( | ||||||
|  |     manager: SlashCommandsManager, | ||||||
|  |     data: SlashCommandPayload, | ||||||
|  |     guild?: Guild | ||||||
|  |   ) { | ||||||
|  |     this.slash = manager | ||||||
|  |     this.id = data.id | ||||||
|  |     this.applicationID = data.application_id | ||||||
|  |     this.name = data.name | ||||||
|  |     this.description = data.description | ||||||
|  |     this.options = data.options ?? [] | ||||||
|  |     this.guild = guild | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   async delete(): Promise<void> { | ||||||
|  |     await this.slash.delete(this.id, this._guild) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   async edit(data: SlashCommandPartial): Promise<void> { | ||||||
|  |     await this.slash.edit(this.id, data, this._guild) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Create a handler for this Slash Command */ | ||||||
|  |   handle( | ||||||
|  |     func: SlashCommandHandlerCallback, | ||||||
|  |     options?: { parent?: string; group?: string } | ||||||
|  |   ): SlashCommand { | ||||||
|  |     this.slash.slash.handle({ | ||||||
|  |       name: this.name, | ||||||
|  |       parent: options?.parent, | ||||||
|  |       group: options?.group, | ||||||
|  |       guild: this._guild, | ||||||
|  |       handler: func | ||||||
|  |     }) | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface CreateOptions { | ||||||
|  |   name: string | ||||||
|  |   description?: string | ||||||
|  |   options?: Array<SlashCommandOption | SlashOptionCallable> | ||||||
|  |   choices?: Array<SlashCommandChoice | string> | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function createSlashOption( | ||||||
|  |   type: SlashCommandOptionType, | ||||||
|  |   data: CreateOptions | ||||||
|  | ): SlashCommandOption { | ||||||
|  |   return { | ||||||
|  |     name: data.name, | ||||||
|  |     type, | ||||||
|  |     description: | ||||||
|  |       type === 0 || type === 1 | ||||||
|  |         ? undefined | ||||||
|  |         : data.description ?? 'No description.', | ||||||
|  |     options: data.options?.map((e) => | ||||||
|  |       typeof e === 'function' ? e(SlashOption) : e | ||||||
|  |     ), | ||||||
|  |     choices: | ||||||
|  |       data.choices === undefined | ||||||
|  |         ? undefined | ||||||
|  |         : data.choices.map((e) => | ||||||
|  |             typeof e === 'string' ? { name: e, value: e } : e | ||||||
|  |           ) | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // eslint-disable-next-line @typescript-eslint/no-extraneous-class
 | ||||||
|  | export class SlashOption { | ||||||
|  |   static string(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.STRING, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static bool(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.BOOLEAN, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static subCommand(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.SUB_COMMAND, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static subCommandGroup(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.SUB_COMMAND_GROUP, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static role(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.ROLE, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static channel(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.CHANNEL, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static user(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.USER, data) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static number(data: CreateOptions): SlashCommandOption { | ||||||
|  |     return createSlashOption(SlashCommandOptionType.INTEGER, data) | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export type SlashOptionCallable = (o: typeof SlashOption) => SlashCommandOption | ||||||
|  | 
 | ||||||
|  | export type SlashBuilderOptionsData = | ||||||
|  |   | Array<SlashCommandOption | SlashOptionCallable> | ||||||
|  |   | { | ||||||
|  |       [name: string]: | ||||||
|  |         | { | ||||||
|  |             description: string | ||||||
|  |             type: SlashCommandOptionType | ||||||
|  |             options?: SlashCommandOption[] | ||||||
|  |             choices?: SlashCommandChoice[] | ||||||
|  |           } | ||||||
|  |         | SlashOptionCallable | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | function buildOptionsArray( | ||||||
|  |   options: SlashBuilderOptionsData | ||||||
|  | ): SlashCommandOption[] { | ||||||
|  |   return Array.isArray(options) | ||||||
|  |     ? options.map((op) => (typeof op === 'function' ? op(SlashOption) : op)) | ||||||
|  |     : Object.entries(options).map((entry) => | ||||||
|  |         typeof entry[1] === 'function' | ||||||
|  |           ? entry[1](SlashOption) | ||||||
|  |           : Object.assign(entry[1], { name: entry[0] }) | ||||||
|  |       ) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** Slash Command Builder */ | ||||||
|  | export class SlashBuilder { | ||||||
|  |   data: SlashCommandPartial | ||||||
|  | 
 | ||||||
|  |   constructor( | ||||||
|  |     name?: string, | ||||||
|  |     description?: string, | ||||||
|  |     options?: SlashBuilderOptionsData | ||||||
|  |   ) { | ||||||
|  |     this.data = { | ||||||
|  |       name: name ?? '', | ||||||
|  |       description: description ?? 'No description.', | ||||||
|  |       options: options === undefined ? [] : buildOptionsArray(options) | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   name(name: string): SlashBuilder { | ||||||
|  |     this.data.name = name | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   description(desc: string): SlashBuilder { | ||||||
|  |     this.data.description = desc | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   option(option: SlashOptionCallable | SlashCommandOption): SlashBuilder { | ||||||
|  |     if (this.data.options === undefined) this.data.options = [] | ||||||
|  |     this.data.options.push( | ||||||
|  |       typeof option === 'function' ? option(SlashOption) : option | ||||||
|  |     ) | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   options(options: SlashBuilderOptionsData): SlashBuilder { | ||||||
|  |     this.data.options = buildOptionsArray(options) | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   export(): SlashCommandPartial { | ||||||
|  |     if (this.data.name === '') | ||||||
|  |       throw new Error('Name was not provided in Slash Builder') | ||||||
|  |     return this.data | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** Manages Slash Commands, allows fetching/modifying/deleting/creating Slash Commands. */ | ||||||
|  | export class SlashCommandsManager { | ||||||
|  |   slash: SlashClient | ||||||
|  |   rest: RESTManager | ||||||
|  | 
 | ||||||
|  |   constructor(client: SlashClient) { | ||||||
|  |     this.slash = client | ||||||
|  |     this.rest = client.rest | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Get all Global Slash Commands */ | ||||||
|  |   async all(): Promise<Collection<string, SlashCommand>> { | ||||||
|  |     const col = new Collection<string, SlashCommand>() | ||||||
|  | 
 | ||||||
|  |     const res = (await this.rest.api.applications[ | ||||||
|  |       this.slash.getID() | ||||||
|  |     ].commands.get()) as SlashCommandPayload[] | ||||||
|  |     if (!Array.isArray(res)) return col | ||||||
|  | 
 | ||||||
|  |     for (const raw of res) { | ||||||
|  |       const cmd = new SlashCommand(this, raw) | ||||||
|  |       col.set(raw.id, cmd) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return col | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Get a Guild's Slash Commands */ | ||||||
|  |   async guild( | ||||||
|  |     guild: Guild | string | ||||||
|  |   ): Promise<Collection<string, SlashCommand>> { | ||||||
|  |     const col = new Collection<string, SlashCommand>() | ||||||
|  | 
 | ||||||
|  |     const res = (await this.rest.api.applications[this.slash.getID()].guilds[ | ||||||
|  |       typeof guild === 'string' ? guild : guild.id | ||||||
|  |     ].commands.get()) as SlashCommandPayload[] | ||||||
|  |     if (!Array.isArray(res)) return col | ||||||
|  | 
 | ||||||
|  |     const _guild = | ||||||
|  |       typeof guild === 'object' | ||||||
|  |         ? guild | ||||||
|  |         : await this.slash.client?.guilds.get(guild) | ||||||
|  | 
 | ||||||
|  |     for (const raw of res) { | ||||||
|  |       const cmd = new SlashCommand(this, raw, _guild) | ||||||
|  |       cmd._guild = typeof guild === 'string' ? guild : guild.id | ||||||
|  |       col.set(raw.id, cmd) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return col | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Create a Slash Command (global or Guild) */ | ||||||
|  |   async create( | ||||||
|  |     data: SlashCommandPartial, | ||||||
|  |     guild?: Guild | string | ||||||
|  |   ): Promise<SlashCommand> { | ||||||
|  |     const route = | ||||||
|  |       guild === undefined | ||||||
|  |         ? this.rest.api.applications[this.slash.getID()].commands | ||||||
|  |         : this.rest.api.applications[this.slash.getID()].guilds[ | ||||||
|  |             typeof guild === 'string' ? guild : guild.id | ||||||
|  |           ].commands | ||||||
|  | 
 | ||||||
|  |     const payload = await route.post(data) | ||||||
|  | 
 | ||||||
|  |     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 = | ||||||
|  |       typeof guild === 'string' || guild === undefined ? guild : guild.id | ||||||
|  | 
 | ||||||
|  |     return cmd | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Edit a Slash Command (global or Guild) */ | ||||||
|  |   async edit( | ||||||
|  |     id: string, | ||||||
|  |     data: SlashCommandPartial, | ||||||
|  |     guild?: Guild | string | ||||||
|  |   ): Promise<SlashCommandsManager> { | ||||||
|  |     const route = | ||||||
|  |       guild === undefined | ||||||
|  |         ? this.rest.api.applications[this.slash.getID()].commands[id] | ||||||
|  |         : this.rest.api.applications[this.slash.getID()].guilds[ | ||||||
|  |             typeof guild === 'string' ? guild : guild.id | ||||||
|  |           ].commands[id] | ||||||
|  | 
 | ||||||
|  |     await route.patch(data) | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Delete a Slash Command (global or Guild) */ | ||||||
|  |   async delete( | ||||||
|  |     id: string, | ||||||
|  |     guild?: Guild | string | ||||||
|  |   ): Promise<SlashCommandsManager> { | ||||||
|  |     const route = | ||||||
|  |       guild === undefined | ||||||
|  |         ? this.rest.api.applications[this.slash.getID()].commands[id] | ||||||
|  |         : this.rest.api.applications[this.slash.getID()].guilds[ | ||||||
|  |             typeof guild === 'string' ? guild : guild.id | ||||||
|  |           ].commands[id] | ||||||
|  | 
 | ||||||
|  |     await route.delete() | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Get a Slash Command (global or Guild) */ | ||||||
|  |   async get(id: string, guild?: Guild | string): Promise<SlashCommand> { | ||||||
|  |     const route = | ||||||
|  |       guild === undefined | ||||||
|  |         ? this.rest.api.applications[this.slash.getID()].commands[id] | ||||||
|  |         : this.rest.api.applications[this.slash.getID()].guilds[ | ||||||
|  |             typeof guild === 'string' ? guild : guild.id | ||||||
|  |           ].commands[id] | ||||||
|  | 
 | ||||||
|  |     const data = await route.get() | ||||||
|  | 
 | ||||||
|  |     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 */ | ||||||
|  |   async bulkEdit( | ||||||
|  |     cmds: Array<SlashCommandPartial | SlashCommandPayload>, | ||||||
|  |     guild?: Guild | string | ||||||
|  |   ): Promise<SlashCommandsManager> { | ||||||
|  |     const route = | ||||||
|  |       guild === undefined | ||||||
|  |         ? this.rest.api.applications[this.slash.getID()].commands | ||||||
|  |         : this.rest.api.applications[this.slash.getID()].guilds[ | ||||||
|  |             typeof guild === 'string' ? guild : guild.id | ||||||
|  |           ].commands | ||||||
|  | 
 | ||||||
|  |     await route.put(cmds) | ||||||
|  | 
 | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import { BaseManager } from './base.ts' | import { BaseManager } from './base.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Channel } from '../structures/channel.ts' | import { Channel } from '../structures/channel.ts' | ||||||
| import { Embed } from '../structures/embed.ts' | import { Embed } from '../structures/embed.ts' | ||||||
| import { Message } from '../structures/message.ts' | import { Message } from '../structures/message.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Emoji } from '../structures/emoji.ts' | import { Emoji } from '../structures/emoji.ts' | ||||||
| import { EmojiPayload } from '../types/emoji.ts' | import { EmojiPayload } from '../types/emoji.ts' | ||||||
| import { GUILD_EMOJI } from '../types/endpoint.ts' | import { GUILD_EMOJI } from '../types/endpoint.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Cache Manager used for Caching values related to Gateway connection |  * Cache Manager used for Caching values related to Gateway connection | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { BaseChildManager } from './baseChild.ts' | import { BaseChildManager } from './baseChild.ts' | ||||||
| import { VoiceStatePayload } from '../types/voice.ts' | import { VoiceStatePayload } from '../types/voice.ts' | ||||||
| import { VoiceState } from '../structures/voiceState.ts' | import { VoiceState } from '../structures/voiceState.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Channel } from '../structures/channel.ts' | import { Channel } from '../structures/channel.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { CategoryChannel } from '../structures/guildCategoryChannel.ts' | import { CategoryChannel } from '../structures/guildCategoryChannel.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Emoji } from '../structures/emoji.ts' | import { Emoji } from '../structures/emoji.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Role } from '../structures/role.ts' | import { Role } from '../structures/role.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { VoiceChannel } from '../structures/guildVoiceChannel.ts' | import { VoiceChannel } from '../structures/guildVoiceChannel.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { fetchAuto } from '../../deps.ts' | import { fetchAuto } from '../../deps.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Template } from '../structures/template.ts' | import { Template } from '../structures/template.ts' | ||||||
| import { Role } from '../structures/role.ts' | import { Role } from '../structures/role.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { GuildTextChannel, User } from '../../mod.ts' | import { GuildTextChannel, User } from '../../mod.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Invite } from '../structures/invite.ts' | import { Invite } from '../structures/invite.ts' | ||||||
| import { CHANNEL_INVITES, GUILD_INVITES, INVITE } from '../types/endpoint.ts' | import { CHANNEL_INVITES, GUILD_INVITES, INVITE } from '../types/endpoint.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { BaseChildManager } from './baseChild.ts' | import { BaseChildManager } from './baseChild.ts' | ||||||
| import { RolePayload } from '../types/role.ts' | import { RolePayload } from '../types/role.ts' | ||||||
| import { Role } from '../structures/role.ts' | import { Role } from '../structures/role.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Member } from '../structures/member.ts' | import { Member } from '../structures/member.ts' | ||||||
| import { GUILD_MEMBER } from '../types/endpoint.ts' | import { GUILD_MEMBER } from '../types/endpoint.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Emoji } from '../structures/emoji.ts' | import { Emoji } from '../structures/emoji.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Message } from '../structures/message.ts' | import { Message } from '../structures/message.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Message } from '../structures/message.ts' | import { Message } from '../structures/message.ts' | ||||||
| import { TextChannel } from '../structures/textChannel.ts' | import { TextChannel } from '../structures/textChannel.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Presence } from '../structures/presence.ts' | import { Presence } from '../structures/presence.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { MessageReaction } from '../structures/messageReaction.ts' | import { MessageReaction } from '../structures/messageReaction.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { UsersManager } from './users.ts' | import { UsersManager } from './users.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { Permissions } from '../../mod.ts' | import { Permissions } from '../../mod.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Guild } from '../structures/guild.ts' | import { Guild } from '../structures/guild.ts' | ||||||
| import { Role } from '../structures/role.ts' | import { Role } from '../structures/role.ts' | ||||||
| import { GUILD_ROLE, GUILD_ROLES } from '../types/endpoint.ts' | import { GUILD_ROLE, GUILD_ROLES } from '../types/endpoint.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { User } from '../structures/user.ts' | import { User } from '../structures/user.ts' | ||||||
| import { USER } from '../types/endpoint.ts' | import { USER } from '../types/endpoint.ts' | ||||||
| import { UserPayload } from '../types/user.ts' | import { UserPayload } from '../types/user.ts' | ||||||
|  |  | ||||||
|  | @ -1,45 +1,16 @@ | ||||||
| import * as baseEndpoints from '../consts/urlsAndVersions.ts' |  | ||||||
| import { Embed } from '../structures/embed.ts' | import { Embed } from '../structures/embed.ts' | ||||||
| import { MessageAttachment } from '../structures/message.ts' | import { MessageAttachment } from '../structures/message.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import { Client } from './client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { simplifyAPIError } from '../utils/err_fmt.ts' | import { simplifyAPIError } from '../utils/err_fmt.ts' | ||||||
| 
 | import { | ||||||
| export type RequestMethods = |   DiscordAPIErrorPayload, | ||||||
|   | 'get' |   HttpResponseCode, | ||||||
|   | 'post' |   RequestHeaders, | ||||||
|   | 'put' |   RequestMethods, | ||||||
|   | 'patch' |   METHODS | ||||||
|   | 'head' | } from './types.ts' | ||||||
|   | 'delete' | import { Constants } from '../types/constants.ts' | ||||||
| 
 |  | ||||||
| export enum HttpResponseCode { |  | ||||||
|   Ok = 200, |  | ||||||
|   Created = 201, |  | ||||||
|   NoContent = 204, |  | ||||||
|   NotModified = 304, |  | ||||||
|   BadRequest = 400, |  | ||||||
|   Unauthorized = 401, |  | ||||||
|   Forbidden = 403, |  | ||||||
|   NotFound = 404, |  | ||||||
|   MethodNotAllowed = 405, |  | ||||||
|   TooManyRequests = 429, |  | ||||||
|   GatewayUnavailable = 502 |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export interface RequestHeaders { |  | ||||||
|   [name: string]: string |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export interface DiscordAPIErrorPayload { |  | ||||||
|   url: string |  | ||||||
|   status: number |  | ||||||
|   method: string |  | ||||||
|   code?: number |  | ||||||
|   message?: string |  | ||||||
|   errors: object |  | ||||||
|   requestData: { [key: string]: any } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| export class DiscordAPIError extends Error { | export class DiscordAPIError extends Error { | ||||||
|   name = 'DiscordAPIError' |   name = 'DiscordAPIError' | ||||||
|  | @ -90,8 +61,6 @@ export interface RateLimit { | ||||||
|   bucket: string | null |   bucket: string | null | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const METHODS = ['get', 'post', 'patch', 'put', 'delete', 'head'] |  | ||||||
| 
 |  | ||||||
| export type MethodFunction = ( | export type MethodFunction = ( | ||||||
|   body?: unknown, |   body?: unknown, | ||||||
|   maxRetries?: number, |   maxRetries?: number, | ||||||
|  | @ -122,13 +91,13 @@ export const builder = (rest: RESTManager, acum = '/'): APIMap => { | ||||||
|   const proxy = new Proxy(routes, { |   const proxy = new Proxy(routes, { | ||||||
|     get: (_, p, __) => { |     get: (_, p, __) => { | ||||||
|       if (p === 'toString') return () => acum |       if (p === 'toString') return () => acum | ||||||
|       if (METHODS.includes(String(p))) { |       if (METHODS.includes(String(p)) === true) { | ||||||
|         const method = ((rest as unknown) as { |         const method = ((rest as unknown) as { | ||||||
|           [name: string]: MethodFunction |           [name: string]: MethodFunction | ||||||
|         })[String(p)] |         })[String(p)] | ||||||
|         return async (...args: any[]) => |         return async (...args: any[]) => | ||||||
|           await method.bind(rest)( |           await method.bind(rest)( | ||||||
|             `${baseEndpoints.DISCORD_API_URL}/v${rest.version}${acum.substring( |             `${Constants.DISCORD_API_URL}/v${rest.version}${acum.substring( | ||||||
|               0, |               0, | ||||||
|               acum.length - 1 |               acum.length - 1 | ||||||
|             )}`,
 |             )}`,
 | ||||||
|  | @ -228,7 +197,7 @@ export class RESTManager { | ||||||
|   /** Adds a Request to Queue */ |   /** Adds a Request to Queue */ | ||||||
|   private queue(request: QueuedItem): void { |   private queue(request: QueuedItem): void { | ||||||
|     const route = request.url.substring( |     const route = request.url.substring( | ||||||
|       Number(baseEndpoints.DISCORD_API_URL.length) + 1 |       Number(Constants.DISCORD_API_URL.length) + 1 | ||||||
|     ) |     ) | ||||||
|     const parts = route.split('/') |     const parts = route.split('/') | ||||||
|     parts.shift() |     parts.shift() | ||||||
|  | @ -550,9 +519,9 @@ export class RESTManager { | ||||||
|             if (!urlToUse.startsWith('/')) urlToUse = `/${urlToUse}` |             if (!urlToUse.startsWith('/')) urlToUse = `/${urlToUse}` | ||||||
|             urlToUse = |             urlToUse = | ||||||
|               // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
 |               // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
 | ||||||
|               baseEndpoints.DISCORD_API_URL + |               Constants.DISCORD_API_URL + | ||||||
|               '/v' + |               '/v' + | ||||||
|               baseEndpoints.DISCORD_API_VERSION + |               Constants.DISCORD_API_VERSION + | ||||||
|               urlToUse |               urlToUse | ||||||
|           } |           } | ||||||
| 
 | 
 | ||||||
							
								
								
									
										2
									
								
								src/rest/mod.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/rest/mod.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | export * from './manager.ts' | ||||||
|  | export * from './types.ts' | ||||||
							
								
								
									
										37
									
								
								src/rest/types.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/rest/types.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | ||||||
|  | export type RequestMethods = | ||||||
|  |   | 'get' | ||||||
|  |   | 'post' | ||||||
|  |   | 'put' | ||||||
|  |   | 'patch' | ||||||
|  |   | 'head' | ||||||
|  |   | 'delete' | ||||||
|  | 
 | ||||||
|  | export enum HttpResponseCode { | ||||||
|  |   Ok = 200, | ||||||
|  |   Created = 201, | ||||||
|  |   NoContent = 204, | ||||||
|  |   NotModified = 304, | ||||||
|  |   BadRequest = 400, | ||||||
|  |   Unauthorized = 401, | ||||||
|  |   Forbidden = 403, | ||||||
|  |   NotFound = 404, | ||||||
|  |   MethodNotAllowed = 405, | ||||||
|  |   TooManyRequests = 429, | ||||||
|  |   GatewayUnavailable = 502 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface RequestHeaders { | ||||||
|  |   [name: string]: string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface DiscordAPIErrorPayload { | ||||||
|  |   url: string | ||||||
|  |   status: number | ||||||
|  |   method: string | ||||||
|  |   code?: number | ||||||
|  |   message?: string | ||||||
|  |   errors: object | ||||||
|  |   requestData: { [key: string]: any } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export const METHODS = ['get', 'post', 'patch', 'put', 'delete', 'head'] | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { ApplicationPayload } from '../types/application.ts' | import { ApplicationPayload } from '../types/application.ts' | ||||||
| import { SnowflakeBase } from './base.ts' | import { SnowflakeBase } from './base.ts' | ||||||
| import { User } from './user.ts' | import { User } from './user.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Snowflake } from '../utils/snowflake.ts' | import { Snowflake } from '../utils/snowflake.ts' | ||||||
| 
 | 
 | ||||||
| export class Base { | export class Base { | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   ChannelPayload, |   ChannelPayload, | ||||||
|   ChannelTypes, |   ChannelTypes, | ||||||
|  | @ -303,7 +303,10 @@ export class GuildChannel extends Channel { | ||||||
|           : overwrite.allow?.toJSON() ?? overwrites[index].allow |           : overwrite.allow?.toJSON() ?? overwrites[index].allow | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (overwrite.deny !== undefined && overwriteDeny !== OverrideType.REPLACE) { |     if ( | ||||||
|  |       overwrite.deny !== undefined && | ||||||
|  |       overwriteDeny !== OverrideType.REPLACE | ||||||
|  |     ) { | ||||||
|       switch (overwriteDeny) { |       switch (overwriteDeny) { | ||||||
|         case OverrideType.ADD: { |         case OverrideType.ADD: { | ||||||
|           const originalDeny = new Permissions(overwrites[index].deny) |           const originalDeny = new Permissions(overwrites[index].deny) | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { DMChannelPayload } from '../types/channel.ts' | import { DMChannelPayload } from '../types/channel.ts' | ||||||
| import { UserPayload } from '../types/user.ts' | import { UserPayload } from '../types/user.ts' | ||||||
| import { TextChannel } from './textChannel.ts' | import { TextChannel } from './textChannel.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { ImageSize } from '../types/cdn.ts' | import { ImageSize } from '../types/cdn.ts' | ||||||
| import { EmojiPayload } from '../types/emoji.ts' | import { EmojiPayload } from '../types/emoji.ts' | ||||||
| import { CUSTOM_EMOJI, EMOJI } from '../types/endpoint.ts' | import { CUSTOM_EMOJI, EMOJI } from '../types/endpoint.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { GroupDMChannelPayload } from '../types/channel.ts' | import { GroupDMChannelPayload } from '../types/channel.ts' | ||||||
| import { Channel } from './channel.ts' | import { Channel } from './channel.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   GuildBanPayload, |   GuildBanPayload, | ||||||
|   GuildFeatures, |   GuildFeatures, | ||||||
|  | @ -41,11 +41,11 @@ import { | ||||||
|   GUILD_SPLASH |   GUILD_SPLASH | ||||||
| } from '../types/endpoint.ts' | } from '../types/endpoint.ts' | ||||||
| import { GuildVoiceStatesManager } from '../managers/guildVoiceStates.ts' | import { GuildVoiceStatesManager } from '../managers/guildVoiceStates.ts' | ||||||
| import { RequestMembersOptions } from '../gateway/index.ts' | import { RequestMembersOptions } from '../gateway/mod.ts' | ||||||
| import { GuildPresencesManager } from '../managers/presences.ts' | import { GuildPresencesManager } from '../managers/presences.ts' | ||||||
| import { TemplatePayload } from '../types/template.ts' | import { TemplatePayload } from '../types/template.ts' | ||||||
| import { Template } from './template.ts' | import { Template } from './template.ts' | ||||||
| import { DiscordAPIError } from '../models/rest.ts' | import { DiscordAPIError } from '../rest/mod.ts' | ||||||
| import { ImageFormats, ImageSize } from '../types/cdn.ts' | import { ImageFormats, ImageSize } from '../types/cdn.ts' | ||||||
| import { ImageURL } from './cdn.ts' | import { ImageURL } from './cdn.ts' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Mixin } from '../../deps.ts' | import { Mixin } from '../../deps.ts' | ||||||
| import { TextChannel } from './textChannel.ts' | import { TextChannel } from './textChannel.ts' | ||||||
| import { GuildChannel } from './channel.ts' | import { GuildChannel } from './channel.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   ChannelTypes, |   ChannelTypes, | ||||||
|   GuildTextBasedChannelPayload, |   GuildTextBasedChannelPayload, | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { VoiceServerUpdateData } from '../gateway/handlers/index.ts' | import { VoiceServerUpdateData } from '../gateway/handlers/mod.ts' | ||||||
| import { VoiceStateOptions } from '../gateway/index.ts' | import { VoiceStateOptions } from '../gateway/mod.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   GuildVoiceChannelPayload, |   GuildVoiceChannelPayload, | ||||||
|   ModifyVoiceChannelOption, |   ModifyVoiceChannelOption, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { ChannelPayload } from '../types/channel.ts' | import { ChannelPayload } from '../types/channel.ts' | ||||||
| import { INVITE } from '../types/endpoint.ts' | import { INVITE } from '../types/endpoint.ts' | ||||||
| import { GuildPayload } from '../types/guild.ts' | import { GuildPayload } from '../types/guild.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { MemberRolesManager } from '../managers/memberRoles.ts' | import { MemberRolesManager } from '../managers/memberRoles.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { GUILD_MEMBER } from '../types/endpoint.ts' | import { GUILD_MEMBER } from '../types/endpoint.ts' | ||||||
| import { MemberPayload } from '../types/guild.ts' | import { MemberPayload } from '../types/guild.ts' | ||||||
| import { Permissions } from '../utils/permissions.ts' | import { Permissions } from '../utils/permissions.ts' | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import { | ||||||
|   MessagePayload, |   MessagePayload, | ||||||
|   MessageReference |   MessageReference | ||||||
| } from '../types/channel.ts' | } from '../types/channel.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { User } from './user.ts' | import { User } from './user.ts' | ||||||
| import { Member } from './member.ts' | import { Member } from './member.ts' | ||||||
| import { Embed } from './embed.ts' | import { Embed } from './embed.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { MessagePayload } from '../types/channel.ts' | import { MessagePayload } from '../types/channel.ts' | ||||||
| import { Collection } from '../utils/collection.ts' | import { Collection } from '../utils/collection.ts' | ||||||
| import { GuildTextBasedChannel } from './guildTextChannel.ts' | import { GuildTextBasedChannel } from './guildTextChannel.ts' | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { ReactionUsersManager } from '../managers/reactionUsers.ts' | import { ReactionUsersManager } from '../managers/reactionUsers.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { Reaction } from '../types/channel.ts' | import { Reaction } from '../types/channel.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { Emoji } from './emoji.ts' | import { Emoji } from './emoji.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   MessageStickerFormatTypes, |   MessageStickerFormatTypes, | ||||||
|   MessageStickerPayload |   MessageStickerPayload | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ import { PresenceUpdatePayload, StatusUpdatePayload } from '../types/gateway.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { Guild } from './guild.ts' | import { Guild } from './guild.ts' | ||||||
| import { User } from './user.ts' | import { User } from './user.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| 
 | 
 | ||||||
| export enum ActivityTypes { | export enum ActivityTypes { | ||||||
|   PLAYING = 0, |   PLAYING = 0, | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { SnowflakeBase } from './base.ts' | import { SnowflakeBase } from './base.ts' | ||||||
| import { RoleModifyPayload, RolePayload } from '../types/role.ts' | import { RoleModifyPayload, RolePayload } from '../types/role.ts' | ||||||
| import { Permissions } from '../utils/permissions.ts' | import { Permissions } from '../utils/permissions.ts' | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../client/mod.ts' | ||||||
| import { | import { | ||||||
|   AllowedMentionsPayload, |   AllowedMentionsPayload, | ||||||
|   ChannelTypes, |   ChannelTypes, | ||||||
|  |  | ||||||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue