format files and ready for v0.9.0
This commit is contained in:
		
							parent
							
								
									a80a68bf91
								
							
						
					
					
						commit
						5e5b4076ce
					
				
					 112 changed files with 4478 additions and 4282 deletions
				
			
		
							
								
								
									
										2
									
								
								.github/workflows/deno.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/deno.yml
									
										
									
									
										vendored
									
									
								
							|  | @ -20,7 +20,7 @@ jobs: | ||||||
| 
 | 
 | ||||||
|     strategy: |     strategy: | ||||||
|       matrix: |       matrix: | ||||||
|         deno: ["v1.x", "nightly"] |         deno: ['v1.x', 'nightly'] | ||||||
| 
 | 
 | ||||||
|     steps: |     steps: | ||||||
|       - name: Setup repo |       - name: Setup repo | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								.github/workflows/lint.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.github/workflows/lint.yml
									
										
									
									
										vendored
									
									
								
							|  | @ -5,13 +5,12 @@ name: Lint Test | ||||||
| 
 | 
 | ||||||
| on: | on: | ||||||
|   push: |   push: | ||||||
|     branches: [ main ] |     branches: [main] | ||||||
|   pull_request: |   pull_request: | ||||||
|     branches: [ main ] |     branches: [main] | ||||||
| 
 | 
 | ||||||
| jobs: | jobs: | ||||||
|   build: |   build: | ||||||
| 
 |  | ||||||
|     runs-on: ubuntu-latest |     runs-on: ubuntu-latest | ||||||
| 
 | 
 | ||||||
|     steps: |     steps: | ||||||
|  |  | ||||||
|  | @ -2,5 +2,7 @@ | ||||||
|   "tabWidth": 2, |   "tabWidth": 2, | ||||||
|   "useTabs": false, |   "useTabs": false, | ||||||
|   "semi": false, |   "semi": false, | ||||||
|   "singleQuote": true |   "singleQuote": true, | ||||||
|  |   "trailingComma": "none", | ||||||
|  |   "arrowParens": "always" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -48,7 +48,7 @@ Here is a small example of how to use harmony, | ||||||
| import { | import { | ||||||
|   Client, |   Client, | ||||||
|   Message, |   Message, | ||||||
|   Intents, |   Intents | ||||||
| } from 'https://raw.githubusercontent.com/harmony-org/harmony/main/mod.ts' | } from 'https://raw.githubusercontent.com/harmony-org/harmony/main/mod.ts' | ||||||
| 
 | 
 | ||||||
| const client = new Client() | const client = new Client() | ||||||
|  | @ -78,11 +78,11 @@ import { | ||||||
|   Command, |   Command, | ||||||
|   CommandContext, |   CommandContext, | ||||||
|   Message, |   Message, | ||||||
|   Intents, |   Intents | ||||||
| } from 'https://raw.githubusercontent.com/harmony-org/harmony/main/mod.ts' | } from 'https://raw.githubusercontent.com/harmony-org/harmony/main/mod.ts' | ||||||
| 
 | 
 | ||||||
| const client = new CommandClient({ | const client = new CommandClient({ | ||||||
|   prefix: '!', |   prefix: '!' | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| // Listen for event when client is ready (Identified through gateway / Resumed) | // Listen for event when client is ready (Identified through gateway / Resumed) | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ export const channelPinsUpdate: GatewayEventHandler = async ( | ||||||
|     | undefined = await gateway.client.channels.get<TextChannel>(d.channel_id) |     | undefined = await gateway.client.channels.get<TextChannel>(d.channel_id) | ||||||
|   if (after !== undefined) { |   if (after !== undefined) { | ||||||
|     const before = after.refreshFromData({ |     const before = after.refreshFromData({ | ||||||
|       last_pin_timestamp: d.last_pin_timestamp, |       last_pin_timestamp: d.last_pin_timestamp | ||||||
|     }) |     }) | ||||||
|     const raw = await gateway.client.channels._get(d.channel_id) |     const raw = await gateway.client.channels._get(d.channel_id) | ||||||
|     await gateway.client.channels.set( |     await gateway.client.channels.set( | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ export const guildMemberUpdate: GatewayEventHandler = async ( | ||||||
|     nick: d.nick, |     nick: d.nick, | ||||||
|     premium_since: d.premium_since, |     premium_since: d.premium_since, | ||||||
|     deaf: member?.deaf ?? false, |     deaf: member?.deaf ?? false, | ||||||
|     mute: member?.mute ?? false, |     mute: member?.mute ?? false | ||||||
|   } |   } | ||||||
|   await guild.members.set(d.user.id, newMemberPayload) |   await guild.members.set(d.user.id, newMemberPayload) | ||||||
|   const newMember = await guild.members.get(d.user.id) |   const newMember = await guild.members.get(d.user.id) | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ export const guildMembersChunk: GatewayEventHandler = async ( | ||||||
|     presences: |     presences: | ||||||
|       d.presences === undefined ? undefined : d.presences.map((p) => p.user.id), |       d.presences === undefined ? undefined : d.presences.map((p) => p.user.id), | ||||||
|     chunkIndex: d.chunk_index, |     chunkIndex: d.chunk_index, | ||||||
|     chunkCount: d.chunk_count, |     chunkCount: d.chunk_count | ||||||
|   }) |   }) | ||||||
| 
 | 
 | ||||||
|   // Guild is now completely chunked. Emit an event for that.
 |   // Guild is now completely chunked. Emit an event for that.
 | ||||||
|  |  | ||||||
|  | @ -27,8 +27,7 @@ import { webhooksUpdate } from './webhooksUpdate.ts' | ||||||
| import { messageDeleteBulk } from './messageDeleteBulk.ts' | import { messageDeleteBulk } from './messageDeleteBulk.ts' | ||||||
| import { userUpdate } from './userUpdate.ts' | import { userUpdate } from './userUpdate.ts' | ||||||
| import { typingStart } from './typingStart.ts' | import { typingStart } from './typingStart.ts' | ||||||
| import { Channel } from '../../structures/channel.ts' | import { GuildTextChannel } from '../../structures/textChannel.ts' | ||||||
| import { GuildTextChannel, TextChannel } from '../../structures/textChannel.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 { Emoji } from '../../structures/emoji.ts' | import { Emoji } from '../../structures/emoji.ts' | ||||||
|  | @ -50,6 +49,10 @@ import { inviteDelete } from './inviteDelete.ts' | ||||||
| import { MessageReaction } from '../../structures/messageReaction.ts' | import { MessageReaction } from '../../structures/messageReaction.ts' | ||||||
| import { Invite } from '../../structures/invite.ts' | import { Invite } from '../../structures/invite.ts' | ||||||
| import { Presence } from '../../structures/presence.ts' | import { Presence } from '../../structures/presence.ts' | ||||||
|  | import { | ||||||
|  |   EveryChannelTypes, | ||||||
|  |   EveryTextChannelTypes | ||||||
|  | } from '../../utils/getChannelByType.ts' | ||||||
| 
 | 
 | ||||||
| export const gatewayHandlers: { | export const gatewayHandlers: { | ||||||
|   [eventCode in GatewayEvents]: GatewayEventHandler | undefined |   [eventCode in GatewayEvents]: GatewayEventHandler | undefined | ||||||
|  | @ -90,7 +93,7 @@ export const gatewayHandlers: { | ||||||
|   USER_UPDATE: userUpdate, |   USER_UPDATE: userUpdate, | ||||||
|   VOICE_STATE_UPDATE: voiceStateUpdate, |   VOICE_STATE_UPDATE: voiceStateUpdate, | ||||||
|   VOICE_SERVER_UPDATE: voiceServerUpdate, |   VOICE_SERVER_UPDATE: voiceServerUpdate, | ||||||
|   WEBHOOKS_UPDATE: webhooksUpdate, |   WEBHOOKS_UPDATE: webhooksUpdate | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface EventTypes { | export interface EventTypes { | ||||||
|  | @ -107,10 +110,13 @@ export interface ClientEvents extends EventTypes { | ||||||
|   ready: () => void |   ready: () => void | ||||||
|   reconnect: () => void |   reconnect: () => void | ||||||
|   resumed: () => void |   resumed: () => void | ||||||
|   channelCreate: (channel: Channel) => void |   channelCreate: (channel: EveryChannelTypes) => void | ||||||
|   channelDelete: (channel: Channel) => void |   channelDelete: (channel: EveryChannelTypes) => void | ||||||
|   channelPinsUpdate: (before: TextChannel, after: TextChannel) => void |   channelPinsUpdate: ( | ||||||
|   channelUpdate: (before: Channel, after: Channel) => void |     before: EveryTextChannelTypes, | ||||||
|  |     after: EveryTextChannelTypes | ||||||
|  |   ) => void | ||||||
|  |   channelUpdate: (before: EveryChannelTypes, after: EveryChannelTypes) => void | ||||||
|   guildBanAdd: (guild: Guild, user: User) => void |   guildBanAdd: (guild: Guild, user: User) => void | ||||||
|   guildBanRemove: (guild: Guild, user: User) => void |   guildBanRemove: (guild: Guild, user: User) => void | ||||||
|   guildCreate: (guild: Guild) => void |   guildCreate: (guild: Guild) => void | ||||||
|  | @ -140,7 +146,7 @@ export interface ClientEvents extends EventTypes { | ||||||
|   messageReactionRemoveEmoji: (message: Message, emoji: Emoji) => void |   messageReactionRemoveEmoji: (message: Message, emoji: Emoji) => void | ||||||
|   typingStart: ( |   typingStart: ( | ||||||
|     user: User, |     user: User, | ||||||
|     channel: TextChannel, |     channel: EveryChannelTypes, | ||||||
|     at: Date, |     at: Date, | ||||||
|     guildData?: TypingStartGuildData |     guildData?: TypingStartGuildData | ||||||
|   ) => void |   ) => void | ||||||
|  |  | ||||||
|  | @ -1,7 +1,9 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import { Gateway, GatewayEventHandler } from '../index.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, GuildPayload, InvitePayload } from '../../../mod.ts' | import { ChannelPayload } from '../../types/channel.ts' | ||||||
|  | import { GuildPayload } from '../../types/guild.ts' | ||||||
|  | import { InvitePayload } from '../../types/invite.ts' | ||||||
| import { Invite } from '../../structures/invite.ts' | import { Invite } from '../../structures/invite.ts' | ||||||
| 
 | 
 | ||||||
| export const inviteCreate: GatewayEventHandler = async ( | export const inviteCreate: GatewayEventHandler = async ( | ||||||
|  | @ -32,7 +34,7 @@ export const inviteCreate: GatewayEventHandler = async ( | ||||||
|     channel: (cachedChannel as unknown) as ChannelPayload, |     channel: (cachedChannel as unknown) as ChannelPayload, | ||||||
|     inviter: d.inviter, |     inviter: d.inviter, | ||||||
|     target_user: d.target_user, |     target_user: d.target_user, | ||||||
|     target_user_type: d.target_user_type, |     target_user_type: d.target_user_type | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   await guild.invites.set(d.code, dataConverted) |   await guild.invites.set(d.code, dataConverted) | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Gateway, GatewayEventHandler } from '../index.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' | ||||||
| import { Channel } from '../../../mod.ts' | import { Channel } from '../../structures/channel.ts' | ||||||
| 
 | 
 | ||||||
| export const inviteDelete: GatewayEventHandler = async ( | export const inviteDelete: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  | @ -24,7 +24,7 @@ export const inviteDelete: GatewayEventHandler = async ( | ||||||
|     const uncachedInvite: PartialInvitePayload = { |     const uncachedInvite: PartialInvitePayload = { | ||||||
|       guild: (cachedGuild as unknown) as Guild, |       guild: (cachedGuild as unknown) as Guild, | ||||||
|       channel: (cachedChannel as unknown) as Channel, |       channel: (cachedChannel as unknown) as Channel, | ||||||
|       code: d.code, |       code: d.code | ||||||
|     } |     } | ||||||
|     return gateway.client.emit('inviteDeleteUncached', uncachedInvite) |     return gateway.client.emit('inviteDeleteUncached', uncachedInvite) | ||||||
|   } else { |   } else { | ||||||
|  |  | ||||||
|  | @ -34,7 +34,7 @@ export const messageReactionAdd: GatewayEventHandler = async ( | ||||||
|     await message.reactions.set(d.emoji.id, { |     await message.reactions.set(d.emoji.id, { | ||||||
|       count: 1, |       count: 1, | ||||||
|       emoji: d.emoji, |       emoji: d.emoji, | ||||||
|       me: d.user_id === gateway.client.user?.id, |       me: d.user_id === gateway.client.user?.id | ||||||
|     }) |     }) | ||||||
|     reaction = ((await message.reactions.get( |     reaction = ((await message.reactions.get( | ||||||
|       d.emoji.id |       d.emoji.id | ||||||
|  |  | ||||||
|  | @ -9,6 +9,6 @@ export const voiceServerUpdate: GatewayEventHandler = async ( | ||||||
|   gateway.client.emit('voiceServerUpdate', { |   gateway.client.emit('voiceServerUpdate', { | ||||||
|     token: d.token, |     token: d.token, | ||||||
|     endpoint: d.endpoint, |     endpoint: d.endpoint, | ||||||
|     guild: ((await gateway.client.guilds.get(d.guild_id)) as unknown) as Guild, |     guild: ((await gateway.client.guilds.get(d.guild_id)) as unknown) as Guild | ||||||
|   }) |   }) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { unzlib } from 'https://deno.land/x/denoflate@1.1/mod.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { | import { | ||||||
|   DISCORD_GATEWAY_URL, |   DISCORD_GATEWAY_URL, | ||||||
|   DISCORD_API_VERSION, |   DISCORD_API_VERSION | ||||||
| } from '../consts/urlsAndVersions.ts' | } from '../consts/urlsAndVersions.ts' | ||||||
| import { GatewayResponse } from '../types/gatewayResponse.ts' | import { GatewayResponse } from '../types/gatewayResponse.ts' | ||||||
| import { | import { | ||||||
|  | @ -10,7 +10,7 @@ import { | ||||||
|   GatewayIntents, |   GatewayIntents, | ||||||
|   GatewayCloseCodes, |   GatewayCloseCodes, | ||||||
|   IdentityPayload, |   IdentityPayload, | ||||||
|   StatusUpdatePayload, |   StatusUpdatePayload | ||||||
| } from '../types/gateway.ts' | } from '../types/gateway.ts' | ||||||
| import { gatewayHandlers } from './handlers/index.ts' | import { gatewayHandlers } from './handlers/index.ts' | ||||||
| import { GATEWAY_BOT } from '../types/endpoint.ts' | import { GATEWAY_BOT } from '../types/endpoint.ts' | ||||||
|  | @ -230,7 +230,7 @@ class Gateway { | ||||||
|       properties: { |       properties: { | ||||||
|         $os: Deno.build.os, |         $os: Deno.build.os, | ||||||
|         $browser: 'harmony', |         $browser: 'harmony', | ||||||
|         $device: 'harmony', |         $device: 'harmony' | ||||||
|       }, |       }, | ||||||
|       compress: true, |       compress: true, | ||||||
|       shard: [0, 1], // TODO: Make sharding possible
 |       shard: [0, 1], // TODO: Make sharding possible
 | ||||||
|  | @ -238,7 +238,7 @@ class Gateway { | ||||||
|         (previous, current) => previous | current, |         (previous, current) => previous | current, | ||||||
|         0 |         0 | ||||||
|       ), |       ), | ||||||
|       presence: this.client.presence.create(), |       presence: this.client.presence.create() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.client.bot === false) { |     if (this.client.bot === false) { | ||||||
|  | @ -250,13 +250,13 @@ class Gateway { | ||||||
|         $browser: 'Firefox', |         $browser: 'Firefox', | ||||||
|         $device: '', |         $device: '', | ||||||
|         $referrer: '', |         $referrer: '', | ||||||
|         $referring_domain: '', |         $referring_domain: '' | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.send({ |     this.send({ | ||||||
|       op: GatewayOpcodes.IDENTIFY, |       op: GatewayOpcodes.IDENTIFY, | ||||||
|       d: payload, |       d: payload | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -272,8 +272,8 @@ class Gateway { | ||||||
|       d: { |       d: { | ||||||
|         token: this.token, |         token: this.token, | ||||||
|         session_id: this.sessionID, |         session_id: this.sessionID, | ||||||
|         seq: this.sequenceID ?? null, |         seq: this.sequenceID ?? null | ||||||
|       }, |       } | ||||||
|     } |     } | ||||||
|     this.send(resumePayload) |     this.send(resumePayload) | ||||||
|   } |   } | ||||||
|  | @ -292,8 +292,8 @@ class Gateway { | ||||||
|         limit: options.limit, |         limit: options.limit, | ||||||
|         presences: options.presences, |         presences: options.presences, | ||||||
|         user_ids: options.users, |         user_ids: options.users, | ||||||
|         nonce, |         nonce | ||||||
|       }, |       } | ||||||
|     }) |     }) | ||||||
|     return nonce |     return nonce | ||||||
|   } |   } | ||||||
|  | @ -334,7 +334,7 @@ class Gateway { | ||||||
|         op: data.op, |         op: data.op, | ||||||
|         d: data.d, |         d: data.d, | ||||||
|         s: typeof data.s === 'number' ? data.s : null, |         s: typeof data.s === 'number' ? data.s : null, | ||||||
|         t: data.t === undefined ? null : data.t, |         t: data.t === undefined ? null : data.t | ||||||
|       }) |       }) | ||||||
|     ) |     ) | ||||||
|     return true |     return true | ||||||
|  | @ -343,14 +343,14 @@ class Gateway { | ||||||
|   sendPresence(data: StatusUpdatePayload): void { |   sendPresence(data: StatusUpdatePayload): void { | ||||||
|     this.send({ |     this.send({ | ||||||
|       op: GatewayOpcodes.PRESENCE_UPDATE, |       op: GatewayOpcodes.PRESENCE_UPDATE, | ||||||
|       d: data, |       d: data | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   sendHeartbeat(): void { |   sendHeartbeat(): void { | ||||||
|     const payload = { |     const payload = { | ||||||
|       op: GatewayOpcodes.HEARTBEAT, |       op: GatewayOpcodes.HEARTBEAT, | ||||||
|       d: this.sequenceID ?? null, |       d: this.sequenceID ?? null | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     this.send(payload) |     this.send(payload) | ||||||
|  |  | ||||||
|  | @ -8,37 +8,37 @@ export class BaseManager<T, T2> { | ||||||
|   /** Which data type does this cache have */ |   /** Which data type does this cache have */ | ||||||
|   DataType: any |   DataType: any | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, cacheName: string, DataType: any) { |   constructor(client: Client, cacheName: string, DataType: any) { | ||||||
|     this.client = client |     this.client = client | ||||||
|     this.cacheName = cacheName |     this.cacheName = cacheName | ||||||
|     this.DataType = DataType |     this.DataType = DataType | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async _get (key: string): Promise<T | undefined> { |   async _get(key: string): Promise<T | undefined> { | ||||||
|     return this.client.cache.get(this.cacheName, key) |     return this.client.cache.get(this.cacheName, key) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async get (key: string): Promise<T2 | undefined> { |   async get(key: string): Promise<T2 | undefined> { | ||||||
|     const raw = await this._get(key) |     const raw = await this._get(key) | ||||||
|     if (raw === undefined) return |     if (raw === undefined) return | ||||||
|     return new this.DataType(this.client, raw) |     return new this.DataType(this.client, raw) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async set (key: string, value: T): Promise<any> { |   async set(key: string, value: T): Promise<any> { | ||||||
|     return this.client.cache.set(this.cacheName, key, value) |     return this.client.cache.set(this.cacheName, key, value) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async delete (key: string): Promise<boolean> { |   async delete(key: string): Promise<boolean> { | ||||||
|     return this.client.cache.delete(this.cacheName, key) |     return this.client.cache.delete(this.cacheName, key) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async array (): Promise<undefined | T2[]> { |   async array(): Promise<undefined | T2[]> { | ||||||
|     let arr = await (this.client.cache.array(this.cacheName) as T[]) |     let arr = await (this.client.cache.array(this.cacheName) as T[]) | ||||||
|     if (arr === undefined) arr = [] |     if (arr === undefined) arr = [] | ||||||
|     return arr.map(e => new this.DataType(this.client, e)) as any |     return arr.map((e) => new this.DataType(this.client, e)) as any | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async collection (): Promise<Collection<string, T2>> { |   async collection(): Promise<Collection<string, T2>> { | ||||||
|     const arr = await this.array() |     const arr = await this.array() | ||||||
|     if (arr === undefined) return new Collection() |     if (arr === undefined) return new Collection() | ||||||
|     const collection = new Collection() |     const collection = new Collection() | ||||||
|  | @ -49,7 +49,7 @@ export class BaseManager<T, T2> { | ||||||
|     return collection |     return collection | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   flush (): any { |   flush(): any { | ||||||
|     return this.client.cache.deleteCache(this.cacheName) |     return this.client.cache.deleteCache(this.cacheName) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ export class BaseChildManager<T, T2> { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async collection(): Promise<Collection<string, T2>> { |   async collection(): Promise<Collection<string, T2>> { | ||||||
|     const arr = await this.array() as undefined | T2[] |     const arr = (await this.array()) as undefined | T2[] | ||||||
|     if (arr === undefined) return new Collection() |     if (arr === undefined) return new Collection() | ||||||
|     const collection = new Collection() |     const collection = new Collection() | ||||||
|     for (const elem of arr) { |     for (const elem of arr) { | ||||||
|  |  | ||||||
|  | @ -6,12 +6,12 @@ import getChannelByType from '../utils/getChannelByType.ts' | ||||||
| import { BaseManager } from './base.ts' | import { BaseManager } from './base.ts' | ||||||
| 
 | 
 | ||||||
| export class ChannelsManager extends BaseManager<ChannelPayload, Channel> { | export class ChannelsManager extends BaseManager<ChannelPayload, Channel> { | ||||||
|   constructor (client: Client) { |   constructor(client: Client) { | ||||||
|     super(client, 'channels', Channel) |     super(client, 'channels', Channel) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // Override get method as Generic
 |   // Override get method as Generic
 | ||||||
|   async get<T = Channel> (key: string): Promise<T | undefined> { |   async get<T = Channel>(key: string): Promise<T | undefined> { | ||||||
|     const data = await this._get(key) |     const data = await this._get(key) | ||||||
|     if (data === undefined) return |     if (data === undefined) return | ||||||
|     let guild |     let guild | ||||||
|  | @ -25,7 +25,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> { | ||||||
|     return res as any |     return res as any | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async array (): Promise<undefined | Channel[]> { |   async array(): Promise<undefined | Channel[]> { | ||||||
|     const arr = await (this.client.cache.array( |     const arr = await (this.client.cache.array( | ||||||
|       this.cacheName |       this.cacheName | ||||||
|     ) as ChannelPayload[]) |     ) as ChannelPayload[]) | ||||||
|  | @ -43,19 +43,25 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> { | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch<T = Channel> (id: string): Promise<T> { |   async fetch<T = Channel>(id: string): Promise<T> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(CHANNEL(id)) |         .get(CHANNEL(id)) | ||||||
|         .then(async data => { |         .then(async (data) => { | ||||||
|           this.set(id, data as ChannelPayload) |           this.set(id, data as ChannelPayload) | ||||||
|           let guild |           let guild | ||||||
|           if (data.guild_id !== undefined) { |           if (data.guild_id !== undefined) { | ||||||
|             guild = await this.client.guilds.get(data.guild_id) |             guild = await this.client.guilds.get(data.guild_id) | ||||||
|           } |           } | ||||||
|           resolve((getChannelByType(this.client, data as ChannelPayload, guild) as unknown) as T) |           resolve( | ||||||
|  |             (getChannelByType( | ||||||
|  |               this.client, | ||||||
|  |               data as ChannelPayload, | ||||||
|  |               guild | ||||||
|  |             ) as unknown) as T | ||||||
|  |           ) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,12 +5,11 @@ import { GUILD_EMOJI } from '../types/endpoint.ts' | ||||||
| import { BaseManager } from './base.ts' | import { BaseManager } from './base.ts' | ||||||
| 
 | 
 | ||||||
| export class EmojisManager extends BaseManager<EmojiPayload, Emoji> { | export class EmojisManager extends BaseManager<EmojiPayload, Emoji> { | ||||||
| 
 |   constructor(client: Client) { | ||||||
|   constructor (client: Client) { |  | ||||||
|     super(client, `emojis`, Emoji) |     super(client, `emojis`, Emoji) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async get (key: string): Promise<Emoji | undefined> { |   async get(key: string): Promise<Emoji | undefined> { | ||||||
|     const raw = await this._get(key) |     const raw = await this._get(key) | ||||||
|     if (raw === undefined) return |     if (raw === undefined) return | ||||||
|     const emoji = new this.DataType(this.client, raw) |     const emoji = new this.DataType(this.client, raw) | ||||||
|  | @ -21,15 +20,15 @@ export class EmojisManager extends BaseManager<EmojiPayload, Emoji> { | ||||||
|     return emoji |     return emoji | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch (guildID: string, id: string): Promise<Emoji> { |   async fetch(guildID: string, id: string): Promise<Emoji> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(GUILD_EMOJI(guildID, id)) |         .get(GUILD_EMOJI(guildID, id)) | ||||||
|         .then(async data => { |         .then(async (data) => { | ||||||
|           await this.set(id, data as EmojiPayload) |           await this.set(id, data as EmojiPayload) | ||||||
|           resolve(new Emoji(this.client, data as EmojiPayload)) |           resolve(new Emoji(this.client, data as EmojiPayload)) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,22 +4,22 @@ export class GatewayCache { | ||||||
|   client: Client |   client: Client | ||||||
|   cacheName: string = 'discord_gateway_cache' |   cacheName: string = 'discord_gateway_cache' | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, cacheName?: string) { |   constructor(client: Client, cacheName?: string) { | ||||||
|     this.client = client |     this.client = client | ||||||
|     if (cacheName !== undefined) this.cacheName = cacheName |     if (cacheName !== undefined) this.cacheName = cacheName | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async get (key: string): Promise<undefined | any> { |   async get(key: string): Promise<undefined | any> { | ||||||
|     const result = await this.client.cache.get(this.cacheName, key) |     const result = await this.client.cache.get(this.cacheName, key) | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async set (key: string, value: any): Promise<any> { |   async set(key: string, value: any): Promise<any> { | ||||||
|     const result = await this.client.cache.set(this.cacheName, key, value) |     const result = await this.client.cache.set(this.cacheName, key, value) | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async delete (key: string): Promise<boolean> { |   async delete(key: string): Promise<boolean> { | ||||||
|     const result = await this.client.cache.delete(this.cacheName, key) |     const result = await this.client.cache.delete(this.cacheName, key) | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -25,12 +25,12 @@ export class GuildChannelsManager extends BaseChildManager< | ||||||
| > { | > { | ||||||
|   guild: Guild |   guild: Guild | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, parent: ChannelsManager, guild: Guild) { |   constructor(client: Client, parent: ChannelsManager, guild: Guild) { | ||||||
|     super(client, parent as any) |     super(client, parent as any) | ||||||
|     this.guild = guild |     this.guild = guild | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async get (id: string): Promise<GuildChannel | undefined> { |   async get(id: string): Promise<GuildChannel | undefined> { | ||||||
|     const res = await this.parent.get(id) |     const res = await this.parent.get(id) | ||||||
|     if (res !== undefined && res.guild.id === this.guild.id) return res |     if (res !== undefined && res.guild.id === this.guild.id) return res | ||||||
|     else return undefined |     else return undefined | ||||||
|  | @ -40,14 +40,14 @@ export class GuildChannelsManager extends BaseChildManager< | ||||||
|     return this.client.rest.delete(CHANNEL(id)) |     return this.client.rest.delete(CHANNEL(id)) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async array (): Promise<GuildChannel[]> { |   async array(): Promise<GuildChannel[]> { | ||||||
|     const arr = (await this.parent.array()) as Channel[] |     const arr = (await this.parent.array()) as Channel[] | ||||||
|     return arr.filter( |     return arr.filter( | ||||||
|       (c: any) => c.guild !== undefined && c.guild.id === this.guild.id |       (c: any) => c.guild !== undefined && c.guild.id === this.guild.id | ||||||
|     ) as any |     ) as any | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async flush (): Promise<boolean> { |   async flush(): Promise<boolean> { | ||||||
|     const arr = await this.array() |     const arr = await this.array() | ||||||
|     for (const elem of arr) { |     for (const elem of arr) { | ||||||
|       this.parent.delete(elem.id) |       this.parent.delete(elem.id) | ||||||
|  |  | ||||||
|  | @ -8,10 +8,7 @@ import { BaseChildManager } from './baseChild.ts' | ||||||
| import { EmojisManager } from './emojis.ts' | import { EmojisManager } from './emojis.ts' | ||||||
| import { fetchAuto } from 'https://raw.githubusercontent.com/DjDeveloperr/fetch-base64/main/mod.ts' | import { fetchAuto } from 'https://raw.githubusercontent.com/DjDeveloperr/fetch-base64/main/mod.ts' | ||||||
| 
 | 
 | ||||||
| export class GuildEmojisManager extends BaseChildManager< | export class GuildEmojisManager extends BaseChildManager<EmojiPayload, Emoji> { | ||||||
|   EmojiPayload, |  | ||||||
|   Emoji |  | ||||||
|   > { |  | ||||||
|   guild: Guild |   guild: Guild | ||||||
| 
 | 
 | ||||||
|   constructor(client: Client, parent: EmojisManager, guild: Guild) { |   constructor(client: Client, parent: EmojisManager, guild: Guild) { | ||||||
|  | @ -33,28 +30,34 @@ export class GuildEmojisManager extends BaseChildManager< | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(GUILD_EMOJI(this.guild.id, id)) |         .get(GUILD_EMOJI(this.guild.id, id)) | ||||||
|         .then(async data => { |         .then(async (data) => { | ||||||
|           const emoji = new Emoji(this.client, data as EmojiPayload) |           const emoji = new Emoji(this.client, data as EmojiPayload) | ||||||
|           data.guild_id = this.guild.id |           data.guild_id = this.guild.id | ||||||
|           await this.set(id, data as EmojiPayload) |           await this.set(id, data as EmojiPayload) | ||||||
|           emoji.guild = this.guild |           emoji.guild = this.guild | ||||||
|           resolve(emoji) |           resolve(emoji) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async create(name: string, url: string, roles?: Role[] | string[] | string): Promise<Emoji | undefined> { |   async create( | ||||||
|  |     name: string, | ||||||
|  |     url: string, | ||||||
|  |     roles?: Role[] | string[] | string | ||||||
|  |   ): Promise<Emoji | undefined> { | ||||||
|     let data = url |     let data = url | ||||||
|     if (!data.startsWith("data:")) { |     if (!data.startsWith('data:')) { | ||||||
|       data = await fetchAuto(url) |       data = await fetchAuto(url) | ||||||
|     } |     } | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       let roleIDs: string[] = [] |       let roleIDs: string[] = [] | ||||||
|       if (roles !== undefined && typeof roles === "string") roleIDs = [roles] |       if (roles !== undefined && typeof roles === 'string') roleIDs = [roles] | ||||||
|       else if (roles !== undefined) { |       else if (roles !== undefined) { | ||||||
|         if (roles?.length === 0) reject(new Error("Empty Roles array was provided")) |         if (roles?.length === 0) | ||||||
|         if (roles[0] instanceof Role) roleIDs = (roles as any).map((r: Role) => r.id) |           reject(new Error('Empty Roles array was provided')) | ||||||
|  |         if (roles[0] instanceof Role) | ||||||
|  |           roleIDs = (roles as any).map((r: Role) => r.id) | ||||||
|         else roleIDs = roles as string[] |         else roleIDs = roles as string[] | ||||||
|       } else roles = [this.guild.id] |       } else roles = [this.guild.id] | ||||||
|       this.client.rest |       this.client.rest | ||||||
|  | @ -63,14 +66,14 @@ export class GuildEmojisManager extends BaseChildManager< | ||||||
|           image: data, |           image: data, | ||||||
|           roles: roleIDs |           roles: roleIDs | ||||||
|         }) |         }) | ||||||
|         .then(async data => { |         .then(async (data) => { | ||||||
|           const emoji = new Emoji(this.client, data as EmojiPayload) |           const emoji = new Emoji(this.client, data as EmojiPayload) | ||||||
|           data.guild_id = this.guild.id |           data.guild_id = this.guild.id | ||||||
|           await this.set(data.id, data as EmojiPayload) |           await this.set(data.id, data as EmojiPayload) | ||||||
|           emoji.guild = this.guild |           emoji.guild = this.guild | ||||||
|           resolve(emoji) |           resolve(emoji) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ export class GuildVoiceStatesManager extends BaseManager< | ||||||
|             )) as unknown) as VoiceChannel), |             )) as unknown) as VoiceChannel), | ||||||
|       guild, |       guild, | ||||||
|       member: |       member: | ||||||
|         guild === undefined ? undefined : await guild.members.get(raw.user_id), |         guild === undefined ? undefined : await guild.members.get(raw.user_id) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,11 +6,11 @@ import { BaseManager } from './base.ts' | ||||||
| import { MembersManager } from './members.ts' | import { MembersManager } from './members.ts' | ||||||
| 
 | 
 | ||||||
| export class GuildManager extends BaseManager<GuildPayload, Guild> { | export class GuildManager extends BaseManager<GuildPayload, Guild> { | ||||||
|   constructor (client: Client) { |   constructor(client: Client) { | ||||||
|     super(client, 'guilds', Guild) |     super(client, 'guilds', Guild) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch (id: string): Promise<Guild> { |   async fetch(id: string): Promise<Guild> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(GUILD(id)) |         .get(GUILD(id)) | ||||||
|  | @ -29,7 +29,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | ||||||
| 
 | 
 | ||||||
|           resolve(guild) |           resolve(guild) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ import { Member } from '../structures/member.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 { BaseManager } from './base.ts' | import { BaseManager } from './base.ts' | ||||||
| import { Permissions } from "../utils/permissions.ts" | import { Permissions } from '../utils/permissions.ts' | ||||||
| 
 | 
 | ||||||
| export class MembersManager extends BaseManager<MemberPayload, Member> { | export class MembersManager extends BaseManager<MemberPayload, Member> { | ||||||
|   guild: Guild |   guild: Guild | ||||||
|  | @ -22,27 +22,47 @@ export class MembersManager extends BaseManager<MemberPayload, Member> { | ||||||
|     const roles = await this.guild.roles.array() |     const roles = await this.guild.roles.array() | ||||||
|     let permissions = new Permissions(Permissions.DEFAULT) |     let permissions = new Permissions(Permissions.DEFAULT) | ||||||
|     if (roles !== undefined) { |     if (roles !== undefined) { | ||||||
|       const mRoles = roles.filter(r => raw.roles.includes(r.id) as boolean || r.id === this.guild.id) |       const mRoles = roles.filter( | ||||||
|       permissions = new Permissions(mRoles.map(r => r.permissions)) |         (r) => (raw.roles.includes(r.id) as boolean) || r.id === this.guild.id | ||||||
|  |       ) | ||||||
|  |       permissions = new Permissions(mRoles.map((r) => r.permissions)) | ||||||
|     } |     } | ||||||
|     const res = new this.DataType(this.client, raw, user, this.guild, permissions) |     const res = new this.DataType( | ||||||
|  |       this.client, | ||||||
|  |       raw, | ||||||
|  |       user, | ||||||
|  |       this.guild, | ||||||
|  |       permissions | ||||||
|  |     ) | ||||||
|     return res |     return res | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch(id: string): Promise<Member> { |   async fetch(id: string): Promise<Member> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest.get(GUILD_MEMBER(this.guild.id, id)).then(async data => { |       this.client.rest | ||||||
|  |         .get(GUILD_MEMBER(this.guild.id, id)) | ||||||
|  |         .then(async (data) => { | ||||||
|           await this.set(id, data as MemberPayload) |           await this.set(id, data as MemberPayload) | ||||||
|           const user: User = new User(this.client, data.user) |           const user: User = new User(this.client, data.user) | ||||||
|           const roles = await this.guild.roles.array() |           const roles = await this.guild.roles.array() | ||||||
|           let permissions = new Permissions(Permissions.DEFAULT) |           let permissions = new Permissions(Permissions.DEFAULT) | ||||||
|           if (roles !== undefined) { |           if (roles !== undefined) { | ||||||
|           const mRoles = roles.filter(r => data.roles.includes(r.id) as boolean || r.id === this.guild.id) |             const mRoles = roles.filter( | ||||||
|           permissions = new Permissions(mRoles.map(r => r.permissions)) |               (r) => | ||||||
|  |                 (data.roles.includes(r.id) as boolean) || r.id === this.guild.id | ||||||
|  |             ) | ||||||
|  |             permissions = new Permissions(mRoles.map((r) => r.permissions)) | ||||||
|           } |           } | ||||||
|         const res = new Member(this.client, data as MemberPayload, user, this.guild, permissions) |           const res = new Member( | ||||||
|  |             this.client, | ||||||
|  |             data as MemberPayload, | ||||||
|  |             user, | ||||||
|  |             this.guild, | ||||||
|  |             permissions | ||||||
|  |           ) | ||||||
|           resolve(res) |           resolve(res) | ||||||
|       }).catch(e => reject(e)) |         }) | ||||||
|  |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -8,20 +8,20 @@ import { BaseManager } from './base.ts' | ||||||
| export class RolesManager extends BaseManager<RolePayload, Role> { | export class RolesManager extends BaseManager<RolePayload, Role> { | ||||||
|   guild: Guild |   guild: Guild | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, guild: Guild) { |   constructor(client: Client, guild: Guild) { | ||||||
|     super(client, `roles:${guild.id}`, Role) |     super(client, `roles:${guild.id}`, Role) | ||||||
|     this.guild = guild |     this.guild = guild | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch (id: string): Promise<Role> { |   async fetch(id: string): Promise<Role> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(GUILD_ROLE(this.guild.id, id)) |         .get(GUILD_ROLE(this.guild.id, id)) | ||||||
|         .then(data => { |         .then((data) => { | ||||||
|           this.set(id, data as RolePayload) |           this.set(id, data as RolePayload) | ||||||
|           resolve(new Role(this.client, data as RolePayload)) |           resolve(new Role(this.client, data as RolePayload)) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,19 +5,19 @@ import { UserPayload } from '../types/user.ts' | ||||||
| import { BaseManager } from './base.ts' | import { BaseManager } from './base.ts' | ||||||
| 
 | 
 | ||||||
| export class UserManager extends BaseManager<UserPayload, User> { | export class UserManager extends BaseManager<UserPayload, User> { | ||||||
|   constructor (client: Client) { |   constructor(client: Client) { | ||||||
|     super(client, 'users', User) |     super(client, 'users', User) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch (id: string): Promise<User> { |   async fetch(id: string): Promise<User> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(USER(id)) |         .get(USER(id)) | ||||||
|         .then(data => { |         .then((data) => { | ||||||
|           this.set(id, data as UserPayload) |           this.set(id, data as UserPayload) | ||||||
|           resolve(new User(this.client, data as UserPayload)) |           resolve(new User(this.client, data as UserPayload)) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,7 +7,12 @@ import { | ||||||
| 
 | 
 | ||||||
| export interface ICacheAdapter { | export interface ICacheAdapter { | ||||||
|   get: (cacheName: string, key: string) => Promise<any> | any |   get: (cacheName: string, key: string) => Promise<any> | any | ||||||
|   set: (cacheName: string, key: string, value: any, expire?: number) => Promise<any> | any |   set: ( | ||||||
|  |     cacheName: string, | ||||||
|  |     key: string, | ||||||
|  |     value: any, | ||||||
|  |     expire?: number | ||||||
|  |   ) => Promise<any> | any | ||||||
|   delete: (cacheName: string, key: string) => Promise<boolean> | boolean |   delete: (cacheName: string, key: string) => Promise<boolean> | boolean | ||||||
|   array: (cacheName: string) => undefined | any[] | Promise<any[] | undefined> |   array: (cacheName: string) => undefined | any[] | Promise<any[] | undefined> | ||||||
|   deleteCache: (cacheName: string) => any |   deleteCache: (cacheName: string) => any | ||||||
|  | @ -24,14 +29,20 @@ export class DefaultCacheAdapter implements ICacheAdapter { | ||||||
|     return cache.get(key) |     return cache.get(key) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async set(cacheName: string, key: string, value: any, expire?: number): Promise<any> { |   async set( | ||||||
|  |     cacheName: string, | ||||||
|  |     key: string, | ||||||
|  |     value: any, | ||||||
|  |     expire?: number | ||||||
|  |   ): Promise<any> { | ||||||
|     let cache = this.data[cacheName] |     let cache = this.data[cacheName] | ||||||
|     if (cache === undefined) { |     if (cache === undefined) { | ||||||
|       this.data[cacheName] = new Collection() |       this.data[cacheName] = new Collection() | ||||||
|       cache = this.data[cacheName] |       cache = this.data[cacheName] | ||||||
|     } |     } | ||||||
|     cache.set(key, value) |     cache.set(key, value) | ||||||
|     if (expire !== undefined) setTimeout(() => { |     if (expire !== undefined) | ||||||
|  |       setTimeout(() => { | ||||||
|         cache.delete(key) |         cache.delete(key) | ||||||
|       }, expire) |       }, expire) | ||||||
|   } |   } | ||||||
|  | @ -64,7 +75,7 @@ export class RedisCacheAdapter implements ICacheAdapter { | ||||||
|   constructor(options: RedisConnectOptions) { |   constructor(options: RedisConnectOptions) { | ||||||
|     this._redis = connect(options) |     this._redis = connect(options) | ||||||
|     this._redis.then( |     this._redis.then( | ||||||
|       redis => { |       (redis) => { | ||||||
|         this.redis = redis |         this.redis = redis | ||||||
|         this.ready = true |         this.ready = true | ||||||
|         this._startExpireInterval() |         this._startExpireInterval() | ||||||
|  | @ -79,11 +90,11 @@ export class RedisCacheAdapter implements ICacheAdapter { | ||||||
|     this._expireInterval = setInterval(() => { |     this._expireInterval = setInterval(() => { | ||||||
|       this.redis?.scan(0, { pattern: '*:expires' }).then(([_, names]) => { |       this.redis?.scan(0, { pattern: '*:expires' }).then(([_, names]) => { | ||||||
|         for (const name of names) { |         for (const name of names) { | ||||||
|           this.redis?.hvals(name).then(vals => { |           this.redis?.hvals(name).then((vals) => { | ||||||
|             for (const val of vals) { |             for (const val of vals) { | ||||||
|               const expireVal: { |               const expireVal: { | ||||||
|                 name: string, |                 name: string | ||||||
|                 key: string, |                 key: string | ||||||
|                 at: number |                 at: number | ||||||
|               } = JSON.parse(val) |               } = JSON.parse(val) | ||||||
|               const expired = new Date().getTime() > expireVal.at |               const expired = new Date().getTime() > expireVal.at | ||||||
|  | @ -126,7 +137,11 @@ export class RedisCacheAdapter implements ICacheAdapter { | ||||||
|       await this.redis?.hset( |       await this.redis?.hset( | ||||||
|         `${cacheName}:expires`, |         `${cacheName}:expires`, | ||||||
|         key, |         key, | ||||||
|         JSON.stringify({ name: cacheName, key, at: new Date().getTime() + expire }) |         JSON.stringify({ | ||||||
|  |           name: cacheName, | ||||||
|  |           key, | ||||||
|  |           at: new Date().getTime() + expire | ||||||
|  |         }) | ||||||
|       ) |       ) | ||||||
|     } |     } | ||||||
|     return result |     return result | ||||||
|  | @ -148,6 +163,6 @@ export class RedisCacheAdapter implements ICacheAdapter { | ||||||
| 
 | 
 | ||||||
|   async deleteCache(cacheName: string): Promise<boolean> { |   async deleteCache(cacheName: string): Promise<boolean> { | ||||||
|     await this._checkReady() |     await this._checkReady() | ||||||
|     return await this.redis?.del(cacheName) !== 0 |     return (await this.redis?.del(cacheName)) !== 0 | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -11,7 +11,6 @@ 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 { ClientEvents } from '../gateway/handlers/index.ts' | import { ClientEvents } from '../gateway/handlers/index.ts' | ||||||
| // import { Application } from "../../mod.ts"
 |  | ||||||
| 
 | 
 | ||||||
| /** Some Client Options to modify behaviour */ | /** Some Client Options to modify behaviour */ | ||||||
| export interface ClientOptions { | export interface ClientOptions { | ||||||
|  |  | ||||||
|  | @ -142,7 +142,7 @@ export class CommandBuilder extends Command { | ||||||
|       ...new Set( |       ...new Set( | ||||||
|         ...this.aliases, |         ...this.aliases, | ||||||
|         ...(typeof alias === 'string' ? [alias] : alias) |         ...(typeof alias === 'string' ? [alias] : alias) | ||||||
|       ), |       ) | ||||||
|     ] |     ] | ||||||
| 
 | 
 | ||||||
|     return this |     return this | ||||||
|  | @ -166,7 +166,7 @@ export class CommandBuilder extends Command { | ||||||
|       ...new Set( |       ...new Set( | ||||||
|         ...this.usage, |         ...this.usage, | ||||||
|         ...(typeof usage === 'string' ? [usage] : usage) |         ...(typeof usage === 'string' ? [usage] : usage) | ||||||
|       ), |       ) | ||||||
|     ] |     ] | ||||||
| 
 | 
 | ||||||
|     return this |     return this | ||||||
|  | @ -185,7 +185,7 @@ export class CommandBuilder extends Command { | ||||||
|       ...new Set( |       ...new Set( | ||||||
|         ...this.examples, |         ...this.examples, | ||||||
|         ...(typeof examples === 'string' ? [examples] : examples) |         ...(typeof examples === 'string' ? [examples] : examples) | ||||||
|       ), |       ) | ||||||
|     ] |     ] | ||||||
| 
 | 
 | ||||||
|     return this |     return this | ||||||
|  | @ -423,6 +423,6 @@ export const parseCommand = ( | ||||||
|   return { |   return { | ||||||
|     name, |     name, | ||||||
|     args, |     args, | ||||||
|     argString, |     argString | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| import { Message } from '../../mod.ts' | import { Message } from '../structures/message.ts' | ||||||
| import { awaitSync } from '../utils/mixedPromise.ts' | import { awaitSync } from '../utils/mixedPromise.ts' | ||||||
| import { Client, ClientOptions } from './client.ts' | import { Client, ClientOptions } from './client.ts' | ||||||
| import { | import { | ||||||
|   CategoriesManager, |   CategoriesManager, | ||||||
|   CommandContext, |   CommandContext, | ||||||
|   CommandsManager, |   CommandsManager, | ||||||
|   parseCommand, |   parseCommand | ||||||
| } from './command.ts' | } from './command.ts' | ||||||
| import { ExtensionsManager } from './extensions.ts' | import { ExtensionsManager } from './extensions.ts' | ||||||
| 
 | 
 | ||||||
|  | @ -108,12 +108,12 @@ export class CommandClient extends Client implements CommandClientOptions { | ||||||
|       if (isGuildBlacklisted === true) return |       if (isGuildBlacklisted === true) return | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let prefix: string | string[] = this.prefix |     let prefix: string | string[] = await awaitSync( | ||||||
|  |       this.getUserPrefix(msg.author.id) | ||||||
|  |     ) | ||||||
| 
 | 
 | ||||||
|     if (msg.guild !== undefined) { |     if (msg.guild !== undefined) { | ||||||
|       prefix = await awaitSync(this.getGuildPrefix(msg.guild.id)) |       prefix = await awaitSync(this.getGuildPrefix(msg.guild.id)) | ||||||
|     } else { |  | ||||||
|       prefix = await awaitSync(this.getUserPrefix(msg.author.id)) |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let mentionPrefix = false |     let mentionPrefix = false | ||||||
|  | @ -204,7 +204,7 @@ export class CommandClient extends Client implements CommandClientOptions { | ||||||
|       author: msg.author, |       author: msg.author, | ||||||
|       command, |       command, | ||||||
|       channel: msg.channel, |       channel: msg.channel, | ||||||
|       guild: msg.guild, |       guild: msg.guild | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // In these checks too, Command overrides Category if present
 |     // In these checks too, Command overrides Category if present
 | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| 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 './commandClient.ts' | ||||||
| 
 | 
 | ||||||
| export type ExtensionEventCallback = (ext: Extension, ...args: any[]) => any | export type ExtensionEventCallback = (ext: Extension, ...args: any[]) => any | ||||||
| 
 | 
 | ||||||
|  | @ -12,7 +12,9 @@ export class ExtensionCommands { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get list(): Collection<string, Command> { |   get list(): Collection<string, Command> { | ||||||
|     return this.extension.client.commands.list.filter(c => c.extension?.name === this.extension.name) |     return this.extension.client.commands.list.filter( | ||||||
|  |       (c) => c.extension?.name === this.extension.name | ||||||
|  |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get(cmd: string): Command | undefined { |   get(cmd: string): Command | undefined { | ||||||
|  | @ -31,9 +33,15 @@ export class ExtensionCommands { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   delete(cmd: Command | string): boolean { |   delete(cmd: Command | string): boolean { | ||||||
|     const find = this.extension.client.commands.find(typeof cmd === 'string' ? cmd : cmd.name) |     const find = this.extension.client.commands.find( | ||||||
|  |       typeof cmd === 'string' ? cmd : cmd.name | ||||||
|  |     ) | ||||||
|     if (find === undefined) return false |     if (find === undefined) return false | ||||||
|     if (find.extension !== undefined && find.extension.name !== this.extension.name) return false |     if ( | ||||||
|  |       find.extension !== undefined && | ||||||
|  |       find.extension.name !== this.extension.name | ||||||
|  |     ) | ||||||
|  |       return false | ||||||
|     else return this.extension.client.commands.delete(find) |     else return this.extension.client.commands.delete(find) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -61,7 +69,7 @@ export class Extension { | ||||||
|       const fn = (...args: any[]): any => { |       const fn = (...args: any[]): any => { | ||||||
|         // eslint-disable-next-line standard/no-callback-literal
 |         // eslint-disable-next-line standard/no-callback-literal
 | ||||||
|         cb(this, ...args) |         cb(this, ...args) | ||||||
|       }; |       } | ||||||
|       this.client.on(event, fn) |       this.client.on(event, fn) | ||||||
|       this.events[event] = fn |       this.events[event] = fn | ||||||
|       return true |       return true | ||||||
|  | @ -91,7 +99,8 @@ export class ExtensionsManager { | ||||||
|   load(ext: Extension | typeof Extension): void { |   load(ext: Extension | typeof Extension): void { | ||||||
|     // eslint-disable-next-line new-cap
 |     // eslint-disable-next-line new-cap
 | ||||||
|     if (!(ext instanceof Extension)) ext = new ext(this.client) |     if (!(ext instanceof Extension)) ext = new ext(this.client) | ||||||
|     if (this.exists(ext.name)) throw new Error(`Extension with name '${ext.name}' already exists`) |     if (this.exists(ext.name)) | ||||||
|  |       throw new Error(`Extension with name '${ext.name}' already exists`) | ||||||
|     this.list.set(ext.name, ext) |     this.list.set(ext.name, ext) | ||||||
|     ext.load() |     ext.load() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ export enum HttpResponseCode { | ||||||
|   NotFound = 404, |   NotFound = 404, | ||||||
|   MethodNotAllowed = 405, |   MethodNotAllowed = 405, | ||||||
|   TooManyRequests = 429, |   TooManyRequests = 429, | ||||||
|   GatewayUnavailable = 502, |   GatewayUnavailable = 502 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface RequestHeaders { | export interface RequestHeaders { | ||||||
|  | @ -109,7 +109,7 @@ export class RESTManager { | ||||||
|               if (result?.rateLimited !== undefined) { |               if (result?.rateLimited !== undefined) { | ||||||
|                 this.queue({ |                 this.queue({ | ||||||
|                   ...request, |                   ...request, | ||||||
|                   bucket: result.bucket ?? request.bucket, |                   bucket: result.bucket ?? request.bucket | ||||||
|                 }) |                 }) | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|  | @ -121,7 +121,7 @@ export class RESTManager { | ||||||
|               if (result?.rateLimited !== undefined) { |               if (result?.rateLimited !== undefined) { | ||||||
|                 this.queue({ |                 this.queue({ | ||||||
|                   ...request, |                   ...request, | ||||||
|                   bucket: result.bucket ?? request.bucket, |                   bucket: result.bucket ?? request.bucket | ||||||
|                 }) |                 }) | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|  | @ -141,7 +141,7 @@ export class RESTManager { | ||||||
| 
 | 
 | ||||||
|   prepare(body: any, method: RequestMethods): { [key: string]: any } { |   prepare(body: any, method: RequestMethods): { [key: string]: any } { | ||||||
|     const headers: RequestHeaders = { |     const headers: RequestHeaders = { | ||||||
|       'User-Agent': `DiscordBot (harmony, https://github.com/harmony-org/harmony)`, |       'User-Agent': `DiscordBot (harmony, https://github.com/harmony-org/harmony)` | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.client !== undefined) |     if (this.client !== undefined) | ||||||
|  | @ -168,7 +168,7 @@ export class RESTManager { | ||||||
|     const data: { [name: string]: any } = { |     const data: { [name: string]: any } = { | ||||||
|       headers, |       headers, | ||||||
|       body: body?.file ?? JSON.stringify(body), |       body: body?.file ?? JSON.stringify(body), | ||||||
|       method: method.toUpperCase(), |       method: method.toUpperCase() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.client?.bot === false) { |     if (this.client?.bot === false) { | ||||||
|  | @ -222,14 +222,14 @@ export class RESTManager { | ||||||
|       this.rateLimits.set(url, { |       this.rateLimits.set(url, { | ||||||
|         url, |         url, | ||||||
|         resetAt: Number(resetAt) * 1000, |         resetAt: Number(resetAt) * 1000, | ||||||
|         bucket, |         bucket | ||||||
|       }) |       }) | ||||||
| 
 | 
 | ||||||
|       if (bucket !== null) { |       if (bucket !== null) { | ||||||
|         this.rateLimits.set(bucket, { |         this.rateLimits.set(bucket, { | ||||||
|           url, |           url, | ||||||
|           resetAt: Number(resetAt) * 1000, |           resetAt: Number(resetAt) * 1000, | ||||||
|           bucket, |           bucket | ||||||
|         }) |         }) | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | @ -242,14 +242,14 @@ export class RESTManager { | ||||||
|       this.rateLimits.set('global', { |       this.rateLimits.set('global', { | ||||||
|         url: 'global', |         url: 'global', | ||||||
|         resetAt: reset, |         resetAt: reset, | ||||||
|         bucket, |         bucket | ||||||
|       }) |       }) | ||||||
| 
 | 
 | ||||||
|       if (bucket !== null) { |       if (bucket !== null) { | ||||||
|         this.rateLimits.set(bucket, { |         this.rateLimits.set(bucket, { | ||||||
|           url: 'global', |           url: 'global', | ||||||
|           resetAt: reset, |           resetAt: reset, | ||||||
|           bucket, |           bucket | ||||||
|         }) |         }) | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | @ -286,7 +286,7 @@ export class RESTManager { | ||||||
|       url: response.url, |       url: response.url, | ||||||
|       status, |       status, | ||||||
|       method: data.method, |       method: data.method, | ||||||
|       body: data.body, |       body: data.body | ||||||
|     } |     } | ||||||
|     if (body !== undefined) error = Object.assign(error, body) |     if (body !== undefined) error = Object.assign(error, body) | ||||||
| 
 | 
 | ||||||
|  | @ -295,7 +295,7 @@ export class RESTManager { | ||||||
|         HttpResponseCode.BadRequest, |         HttpResponseCode.BadRequest, | ||||||
|         HttpResponseCode.NotFound, |         HttpResponseCode.NotFound, | ||||||
|         HttpResponseCode.Forbidden, |         HttpResponseCode.Forbidden, | ||||||
|         HttpResponseCode.MethodNotAllowed, |         HttpResponseCode.MethodNotAllowed | ||||||
|       ].includes(status) |       ].includes(status) | ||||||
|     ) { |     ) { | ||||||
|       throw new DiscordAPIError(Deno.inspect(error)) |       throw new DiscordAPIError(Deno.inspect(error)) | ||||||
|  | @ -320,7 +320,7 @@ export class RESTManager { | ||||||
|             return { |             return { | ||||||
|               rateLimited: rateLimitResetIn, |               rateLimited: rateLimitResetIn, | ||||||
|               before: true, |               before: true, | ||||||
|               bucket, |               bucket | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
| 
 | 
 | ||||||
|  | @ -367,7 +367,7 @@ export class RESTManager { | ||||||
|             return { |             return { | ||||||
|               rateLimited: json.retry_after, |               rateLimited: json.retry_after, | ||||||
|               before: false, |               before: false, | ||||||
|               bucket: bucketFromHeaders, |               bucket: bucketFromHeaders | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|           return resolve(rawResponse === true ? { response, body: json } : json) |           return resolve(rawResponse === true ? { response, body: json } : json) | ||||||
|  | @ -379,7 +379,7 @@ export class RESTManager { | ||||||
|       this.queue({ |       this.queue({ | ||||||
|         onComplete, |         onComplete, | ||||||
|         bucket, |         bucket, | ||||||
|         url, |         url | ||||||
|       }) |       }) | ||||||
|       if (!this.processing) { |       if (!this.processing) { | ||||||
|         this.processing = true |         this.processing = true | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| 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 { Client } from './client.ts' | import { Client } from './client.ts' | ||||||
| 
 | 
 | ||||||
| export interface VoiceOptions { | export interface VoiceOptions { | ||||||
|   guild: Guild, |   guild: Guild | ||||||
|   channel: VoiceChannel |   channel: VoiceChannel | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Client } from "../models/client.ts"; | import { Client } from '../models/client.ts' | ||||||
| import { ApplicationPayload } from "../types/application.ts"; | import { ApplicationPayload } from '../types/application.ts' | ||||||
| import { Base } from "./base.ts"; | import { Base } from './base.ts' | ||||||
| import { User } from "./user.ts"; | import { User } from './user.ts' | ||||||
| 
 | 
 | ||||||
| export class Application extends Base { | export class Application extends Base { | ||||||
|   id: string |   id: string | ||||||
|  |  | ||||||
|  | @ -13,18 +13,21 @@ export class Base { | ||||||
|   static useCache?: boolean = true |   static useCache?: boolean = true | ||||||
|   static restFunc?: (...restURLfuncArgs: string[]) => string |   static restFunc?: (...restURLfuncArgs: string[]) => string | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, _data?: any) { |   constructor(client: Client, _data?: any) { | ||||||
|     this.client = client |     this.client = client | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   static async autoInit ( |   static async autoInit( | ||||||
|     client: Client, |     client: Client, | ||||||
|     { useCache, endpoint, restURLfuncArgs }: IInit |     { useCache, endpoint, restURLfuncArgs }: IInit | ||||||
|   ): Promise<any> { |   ): Promise<any> { | ||||||
|     this.useCache = useCache |     this.useCache = useCache | ||||||
|     const cacheID = restURLfuncArgs.join(':') |     const cacheID = restURLfuncArgs.join(':') | ||||||
|     if (this.useCache !== undefined) { |     if (this.useCache !== undefined) { | ||||||
|       const cached = await client.cache.get(this.cacheName ?? this.name, cacheID) |       const cached = await client.cache.get( | ||||||
|  |         this.cacheName ?? this.name, | ||||||
|  |         cacheID | ||||||
|  |       ) | ||||||
|       if (cached !== undefined) { |       if (cached !== undefined) { | ||||||
|         return cached |         return cached | ||||||
|       } |       } | ||||||
|  | @ -35,7 +38,7 @@ export class Base { | ||||||
|     return new this(client, jsonParsed) |     return new this(client, jsonParsed) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async refreshFromAPI ( |   async refreshFromAPI( | ||||||
|     client: Client, |     client: Client, | ||||||
|     { endpoint, restURLfuncArgs }: IInit |     { endpoint, restURLfuncArgs }: IInit | ||||||
|   ): Promise<this> { |   ): Promise<this> { | ||||||
|  | @ -48,13 +51,13 @@ export class Base { | ||||||
|     return oldOne |     return oldOne | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   refreshFromData (data: { [k: string]: any }): this { |   refreshFromData(data: { [k: string]: any }): this { | ||||||
|     const oldOne = Object.assign(Object.create(this), this) |     const oldOne = Object.assign(Object.create(this), this) | ||||||
|     this.readFromData(data) |     this.readFromData(data) | ||||||
|     return oldOne |     return oldOne | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: { [k: string]: any }): void {} |   protected readFromData(data: { [k: string]: any }): void {} | ||||||
| 
 | 
 | ||||||
|   // toJSON() {}
 |   // toJSON() {}
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,11 +6,11 @@ export class Channel extends Base { | ||||||
|   type: ChannelTypes |   type: ChannelTypes | ||||||
|   id: string |   id: string | ||||||
|   static cacheName = 'channel' |   static cacheName = 'channel' | ||||||
|   get mention (): string { |   get mention(): string { | ||||||
|     return `<#${this.id}>` |     return `<#${this.id}>` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: ChannelPayload) { |   constructor(client: Client, data: ChannelPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.type = data.type |     this.type = data.type | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|  | @ -18,7 +18,7 @@ export class Channel extends Base { | ||||||
|     // this.client.channels.set(this.id, data)
 |     // this.client.channels.set(this.id, data)
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: ChannelPayload): void { |   protected readFromData(data: ChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.type = data.type ?? this.type |     this.type = data.type ?? this.type | ||||||
|     this.id = data.id ?? this.id |     this.id = data.id ?? this.id | ||||||
|  |  | ||||||
|  | @ -6,12 +6,12 @@ import { TextChannel } from './textChannel.ts' | ||||||
| export class DMChannel extends TextChannel { | export class DMChannel extends TextChannel { | ||||||
|   recipients: UserPayload[] |   recipients: UserPayload[] | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: DMChannelPayload) { |   constructor(client: Client, data: DMChannelPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.recipients = data.recipients |     this.recipients = data.recipients | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: DMChannelPayload): void { |   protected readFromData(data: DMChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.recipients = data.recipients ?? this.recipients |     this.recipients = data.recipients ?? this.recipients | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ export class Embed { | ||||||
|   author?: EmbedAuthor |   author?: EmbedAuthor | ||||||
|   fields?: EmbedField[] |   fields?: EmbedField[] | ||||||
| 
 | 
 | ||||||
|   constructor (data?: EmbedPayload) { |   constructor(data?: EmbedPayload) { | ||||||
|     this.title = data?.title |     this.title = data?.title | ||||||
|     this.type = data?.type |     this.type = data?.type | ||||||
|     this.description = data?.description |     this.description = data?.description | ||||||
|  | @ -42,7 +42,7 @@ export class Embed { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // khk4912
 |   // khk4912
 | ||||||
|   toJSON (): EmbedPayload { |   toJSON(): EmbedPayload { | ||||||
|     return { |     return { | ||||||
|       title: this.title, |       title: this.title, | ||||||
|       type: this.type, |       type: this.type, | ||||||
|  | @ -60,72 +60,72 @@ export class Embed { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setTitle (title: string): Embed { |   setTitle(title: string): Embed { | ||||||
|     this.title = title |     this.title = title | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setDescription (description: string): Embed { |   setDescription(description: string): Embed { | ||||||
|     this.description = description |     this.description = description | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setType (type: EmbedTypes): Embed { |   setType(type: EmbedTypes): Embed { | ||||||
|     this.type = type |     this.type = type | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setURL (url: string): Embed { |   setURL(url: string): Embed { | ||||||
|     this.url = url |     this.url = url | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setTimestamp (timestamp: string): Embed { |   setTimestamp(timestamp: string): Embed { | ||||||
|     this.timestamp = timestamp |     this.timestamp = timestamp | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setColor (hex: number): Embed { |   setColor(hex: number): Embed { | ||||||
|     this.color = hex |     this.color = hex | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setFooter (footer: EmbedFooter): Embed { |   setFooter(footer: EmbedFooter): Embed { | ||||||
|     this.footer = footer |     this.footer = footer | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setImage (image: EmbedImage): Embed { |   setImage(image: EmbedImage): Embed { | ||||||
|     this.image = image |     this.image = image | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setThumbnail (thumbnail: EmbedThumbnail): Embed { |   setThumbnail(thumbnail: EmbedThumbnail): Embed { | ||||||
|     this.thumbnail = thumbnail |     this.thumbnail = thumbnail | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setVideo (video: EmbedVideo): Embed { |   setVideo(video: EmbedVideo): Embed { | ||||||
|     this.video = video |     this.video = video | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setProvider (provider: EmbedProvider): Embed { |   setProvider(provider: EmbedProvider): Embed { | ||||||
|     this.provider = provider |     this.provider = provider | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setAuthor (author: EmbedAuthor): Embed { |   setAuthor(author: EmbedAuthor): Embed { | ||||||
|     this.author = author |     this.author = author | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setFields (fields: EmbedField[]): Embed { |   setFields(fields: EmbedField[]): Embed { | ||||||
|     this.fields = fields |     this.fields = fields | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   addField (name: string, value: string, inline?: boolean): Embed { |   addField(name: string, value: string, inline?: boolean): Embed { | ||||||
|     if (this.fields === undefined) { |     if (this.fields === undefined) { | ||||||
|       this.fields = [ |       this.fields = [ | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ export class Emoji extends Base { | ||||||
|   animated?: boolean |   animated?: boolean | ||||||
|   available?: boolean |   available?: boolean | ||||||
| 
 | 
 | ||||||
|   get getEmojiString (): string { |   get getEmojiString(): string { | ||||||
|     if (this.animated === false) { |     if (this.animated === false) { | ||||||
|       return `<:${this.name}:${this.id}>` |       return `<:${this.name}:${this.id}>` | ||||||
|     } else return `<a:${this.name}:${this.id}>` |     } else return `<a:${this.name}:${this.id}>` | ||||||
|  | @ -26,7 +26,7 @@ export class Emoji extends Base { | ||||||
|     return this.getEmojiString |     return this.getEmojiString | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: EmojiPayload) { |   constructor(client: Client, data: EmojiPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|     this.name = data.name |     this.name = data.name | ||||||
|  | @ -38,7 +38,7 @@ export class Emoji extends Base { | ||||||
|     this.available = data.available |     this.available = data.available | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: EmojiPayload): void { |   protected readFromData(data: EmojiPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.id = data.id ?? this.id |     this.id = data.id ?? this.id | ||||||
|     this.name = data.name ?? this.name |     this.name = data.name ?? this.name | ||||||
|  | @ -51,7 +51,7 @@ export class Emoji extends Base { | ||||||
|       User.autoInit(this.client, { |       User.autoInit(this.client, { | ||||||
|         endpoint: USER, |         endpoint: USER, | ||||||
|         restURLfuncArgs: [data.user.id] |         restURLfuncArgs: [data.user.id] | ||||||
|       }).then(user => (this.user = user)) |       }).then((user) => (this.user = user)) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ export class GroupDMChannel extends Channel { | ||||||
|   icon?: string |   icon?: string | ||||||
|   ownerID: string |   ownerID: string | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: GroupDMChannelPayload) { |   constructor(client: Client, data: GroupDMChannelPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
| 
 | 
 | ||||||
|     this.name = data.name |     this.name = data.name | ||||||
|  | @ -17,7 +17,7 @@ export class GroupDMChannel extends Channel { | ||||||
|     // cache.set('groupchannel', this.id, this)
 |     // cache.set('groupchannel', this.id, this)
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: GroupDMChannelPayload): void { |   protected readFromData(data: GroupDMChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.name = data.name ?? this.name |     this.name = data.name ?? this.name | ||||||
|     this.icon = data.icon ?? this.icon |     this.icon = data.icon ?? this.icon | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ import { | ||||||
|   GuildIntegrationPayload, |   GuildIntegrationPayload, | ||||||
|   GuildPayload, |   GuildPayload, | ||||||
|   IntegrationAccountPayload, |   IntegrationAccountPayload, | ||||||
|   IntegrationExpireBehavior, |   IntegrationExpireBehavior | ||||||
| } from '../types/guild.ts' | } from '../types/guild.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { RolesManager } from '../managers/roles.ts' | import { RolesManager } from '../managers/roles.ts' | ||||||
|  | @ -85,7 +85,7 @@ export class GuildBans { | ||||||
|       GUILD_BAN(this.guild.id, typeof user === 'string' ? user : user.id), |       GUILD_BAN(this.guild.id, typeof user === 'string' ? user : user.id), | ||||||
|       { |       { | ||||||
|         reason, |         reason, | ||||||
|         delete_message_days: deleteMessagesDays, |         delete_message_days: deleteMessagesDays | ||||||
|       }, |       }, | ||||||
|       undefined, |       undefined, | ||||||
|       null, |       null, | ||||||
|  |  | ||||||
|  | @ -1,9 +1,6 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { Channel } from './channel.ts' | import { Channel } from './channel.ts' | ||||||
| import { | import { GuildChannelCategoryPayload, Overwrite } from '../types/channel.ts' | ||||||
|   GuildChannelCategoryPayload, |  | ||||||
|   Overwrite |  | ||||||
| } from '../types/channel.ts' |  | ||||||
| import { Guild } from './guild.ts' | import { Guild } from './guild.ts' | ||||||
| 
 | 
 | ||||||
| export class CategoryChannel extends Channel { | export class CategoryChannel extends Channel { | ||||||
|  | @ -15,7 +12,7 @@ export class CategoryChannel extends Channel { | ||||||
|   guild: Guild |   guild: Guild | ||||||
|   parentID?: string |   parentID?: string | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: GuildChannelCategoryPayload, guild: Guild) { |   constructor(client: Client, data: GuildChannelCategoryPayload, guild: Guild) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.guildID = data.guild_id |     this.guildID = data.guild_id | ||||||
|     this.name = data.name |     this.name = data.name | ||||||
|  | @ -28,7 +25,7 @@ export class CategoryChannel extends Channel { | ||||||
|     // cache.set('guildcategorychannel', this.id, this)
 |     // cache.set('guildcategorychannel', this.id, this)
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: GuildChannelCategoryPayload): void { |   protected readFromData(data: GuildChannelCategoryPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.guildID = data.guild_id ?? this.guildID |     this.guildID = data.guild_id ?? this.guildID | ||||||
|     this.name = data.name ?? this.name |     this.name = data.name ?? this.name | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ export class NewsChannel extends TextChannel { | ||||||
|   parentID?: string |   parentID?: string | ||||||
|   topic?: string |   topic?: string | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: GuildNewsChannelPayload, guild: Guild) { |   constructor(client: Client, data: GuildNewsChannelPayload, guild: Guild) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.guildID = data.guild_id |     this.guildID = data.guild_id | ||||||
|     this.name = data.name |     this.name = data.name | ||||||
|  | @ -25,7 +25,7 @@ export class NewsChannel extends TextChannel { | ||||||
|     this.topic = data.topic |     this.topic = data.topic | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: GuildNewsChannelPayload): void { |   protected readFromData(data: GuildNewsChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.guildID = data.guild_id ?? this.guildID |     this.guildID = data.guild_id ?? this.guildID | ||||||
|     this.name = data.name ?? this.name |     this.name = data.name ?? this.name | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ export class VoiceChannel extends Channel { | ||||||
|   nsfw: boolean |   nsfw: boolean | ||||||
|   parentID?: string |   parentID?: string | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: GuildVoiceChannelPayload, guild: Guild) { |   constructor(client: Client, data: GuildVoiceChannelPayload, guild: Guild) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.bitrate = data.bitrate |     this.bitrate = data.bitrate | ||||||
|     this.userLimit = data.user_limit |     this.userLimit = data.user_limit | ||||||
|  | @ -29,7 +29,7 @@ export class VoiceChannel extends Channel { | ||||||
|     // cache.set('guildvoicechannel', this.id, this)
 |     // cache.set('guildvoicechannel', this.id, this)
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: GuildVoiceChannelPayload): void { |   protected readFromData(data: GuildVoiceChannelPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.bitrate = data.bitrate ?? this.bitrate |     this.bitrate = data.bitrate ?? this.bitrate | ||||||
|     this.userLimit = data.user_limit ?? this.userLimit |     this.userLimit = data.user_limit ?? this.userLimit | ||||||
|  |  | ||||||
|  | @ -85,7 +85,7 @@ export class Member extends Base { | ||||||
|       nick: data.nick, |       nick: data.nick, | ||||||
|       roles: data.roles?.map((e) => (typeof e === 'string' ? e : e.id)), |       roles: data.roles?.map((e) => (typeof e === 'string' ? e : e.id)), | ||||||
|       deaf: data.deaf, |       deaf: data.deaf, | ||||||
|       mute: data.mute, |       mute: data.mute | ||||||
|     } |     } | ||||||
|     const res = await this.client.rest.patch( |     const res = await this.client.rest.patch( | ||||||
|       GUILD_MEMBER(this.guild.id, this.id), |       GUILD_MEMBER(this.guild.id, this.id), | ||||||
|  | @ -109,7 +109,7 @@ export class Member extends Base { | ||||||
|    */ |    */ | ||||||
|   async setNickname(nick?: string): Promise<Member> { |   async setNickname(nick?: string): Promise<Member> { | ||||||
|     return await this.edit({ |     return await this.edit({ | ||||||
|       nick: nick === undefined ? null : nick, |       nick: nick === undefined ? null : nick | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -126,7 +126,7 @@ export class Member extends Base { | ||||||
|    */ |    */ | ||||||
|   async setMute(mute?: boolean): Promise<Member> { |   async setMute(mute?: boolean): Promise<Member> { | ||||||
|     return await this.edit({ |     return await this.edit({ | ||||||
|       mute: mute === undefined ? false : mute, |       mute: mute === undefined ? false : mute | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -136,7 +136,7 @@ export class Member extends Base { | ||||||
|    */ |    */ | ||||||
|   async setDeaf(deaf?: boolean): Promise<Member> { |   async setDeaf(deaf?: boolean): Promise<Member> { | ||||||
|     return await this.edit({ |     return await this.edit({ | ||||||
|       deaf: deaf === undefined ? false : deaf, |       deaf: deaf === undefined ? false : deaf | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import { | ||||||
|   MessageApplication, |   MessageApplication, | ||||||
|   MessageOption, |   MessageOption, | ||||||
|   MessagePayload, |   MessagePayload, | ||||||
|   MessageReference, |   MessageReference | ||||||
| } from '../types/channel.ts' | } from '../types/channel.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { User } from './user.ts' | import { User } from './user.ts' | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import { | ||||||
|   ActivityPayload, |   ActivityPayload, | ||||||
|   ClientActivity, |   ClientActivity, | ||||||
|   ClientStatus, |   ClientStatus, | ||||||
|   StatusType, |   StatusType | ||||||
| } from '../types/presence.ts' | } from '../types/presence.ts' | ||||||
| import { PresenceUpdatePayload, StatusUpdatePayload } from '../types/gateway.ts' | import { PresenceUpdatePayload, StatusUpdatePayload } from '../types/gateway.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
|  | @ -17,7 +17,7 @@ enum ActivityTypes { | ||||||
|   LISTENING = 2, |   LISTENING = 2, | ||||||
|   WATCHING = 3, |   WATCHING = 3, | ||||||
|   CUSTOM_STATUS = 4, |   CUSTOM_STATUS = 4, | ||||||
|   COMPETING = 5, |   COMPETING = 5 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class Presence extends Base { | export class Presence extends Base { | ||||||
|  | @ -88,7 +88,7 @@ export class ClientPresence { | ||||||
|       afk: this.afk === undefined ? false : this.afk, |       afk: this.afk === undefined ? false : this.afk, | ||||||
|       activities: this.createActivity(), |       activities: this.createActivity(), | ||||||
|       since: this.since === undefined ? null : this.since, |       since: this.since === undefined ? null : this.since, | ||||||
|       status: this.status === undefined ? 'online' : this.status, |       status: this.status === undefined ? 'online' : this.status | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { RolePayload } from '../types/role.ts' | import { RolePayload } from '../types/role.ts' | ||||||
| import { Permissions } from "../utils/permissions.ts" | import { Permissions } from '../utils/permissions.ts' | ||||||
| 
 | 
 | ||||||
| export class Role extends Base { | export class Role extends Base { | ||||||
|   id: string |   id: string | ||||||
|  | @ -13,13 +13,15 @@ export class Role extends Base { | ||||||
|   managed: boolean |   managed: boolean | ||||||
|   mentionable: boolean |   mentionable: boolean | ||||||
| 
 | 
 | ||||||
|   get mention (): string { |   get mention(): string { | ||||||
|     return `<@&${this.id}>` |     return `<@&${this.id}>` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   toString(): string { return this.mention } |   toString(): string { | ||||||
|  |     return this.mention | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: RolePayload) { |   constructor(client: Client, data: RolePayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|     this.name = data.name |     this.name = data.name | ||||||
|  | @ -31,13 +33,16 @@ export class Role extends Base { | ||||||
|     this.mentionable = data.mentionable |     this.mentionable = data.mentionable | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: RolePayload): void { |   protected readFromData(data: RolePayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.name = data.name ?? this.name |     this.name = data.name ?? this.name | ||||||
|     this.color = data.color ?? this.color |     this.color = data.color ?? this.color | ||||||
|     this.hoist = data.hoist ?? this.hoist |     this.hoist = data.hoist ?? this.hoist | ||||||
|     this.position = data.position ?? this.position |     this.position = data.position ?? this.position | ||||||
|     this.permissions = new Permissions(data.permissions) ?? this.permissions |     this.permissions = | ||||||
|  |       data.permissions !== undefined | ||||||
|  |         ? new Permissions(data.permissions) | ||||||
|  |         : this.permissions | ||||||
|     this.managed = data.managed ?? this.managed |     this.managed = data.managed ?? this.managed | ||||||
|     this.mentionable = data.mentionable ?? this.mentionable |     this.mentionable = data.mentionable ?? this.mentionable | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -1,22 +1,22 @@ | ||||||
| export class Snowflake { | export class Snowflake { | ||||||
|   snowflake: bigint |   snowflake: bigint | ||||||
|   constructor (id: string) { |   constructor(id: string) { | ||||||
|     this.snowflake = BigInt.asUintN(64, BigInt(id)) |     this.snowflake = BigInt.asUintN(64, BigInt(id)) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get timestamp (): string { |   get timestamp(): string { | ||||||
|     return ((this.snowflake >> 22n) + 1420070400000n).toString() |     return ((this.snowflake >> 22n) + 1420070400000n).toString() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get workerID (): string { |   get workerID(): string { | ||||||
|     return ((this.snowflake & 0x3e0000n) >> 17n).toString() |     return ((this.snowflake & 0x3e0000n) >> 17n).toString() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get processID (): string { |   get processID(): string { | ||||||
|     return ((this.snowflake & 0x1f00n) >> 12n).toString() |     return ((this.snowflake & 0x1f00n) >> 12n).toString() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get increment (): string { |   get increment(): string { | ||||||
|     return (this.snowflake & 0xfffn).toString() |     return (this.snowflake & 0xfffn).toString() | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,10 +1,16 @@ | ||||||
| import { MessagesManager } from "../../mod.ts" | import { MessagesManager } from '../managers/messages.ts' | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { GuildTextChannelPayload, MessageOption, MessageReference, Overwrite, TextChannelPayload } from '../types/channel.ts' | import { | ||||||
|  |   GuildTextChannelPayload, | ||||||
|  |   MessageOption, | ||||||
|  |   MessageReference, | ||||||
|  |   Overwrite, | ||||||
|  |   TextChannelPayload | ||||||
|  | } from '../types/channel.ts' | ||||||
| import { CHANNEL_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts' | import { CHANNEL_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts' | ||||||
| import { Channel } from './channel.ts' | import { Channel } from './channel.ts' | ||||||
| import { Embed } from './embed.ts' | import { Embed } from './embed.ts' | ||||||
| import { Guild } from "./guild.ts" | import { Guild } from './guild.ts' | ||||||
| import { Message } from './message.ts' | import { Message } from './message.ts' | ||||||
| 
 | 
 | ||||||
| export type AllMessageOptions = MessageOption | Embed | export type AllMessageOptions = MessageOption | Embed | ||||||
|  | @ -33,15 +39,20 @@ export class TextChannel extends Channel { | ||||||
|    * @param option Various other Message options. |    * @param option Various other Message options. | ||||||
|    * @param reply Reference to a Message object to reply-to. |    * @param reply Reference to a Message object to reply-to. | ||||||
|    */ |    */ | ||||||
|   async send(text?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message): Promise<Message> { |   async send( | ||||||
|     if (typeof text === "object") { |     text?: string | AllMessageOptions, | ||||||
|  |     option?: AllMessageOptions, | ||||||
|  |     reply?: Message | ||||||
|  |   ): Promise<Message> { | ||||||
|  |     if (typeof text === 'object') { | ||||||
|       option = text |       option = text | ||||||
|       text = undefined |       text = undefined | ||||||
|     } |     } | ||||||
|     if (text === undefined && option === undefined) { |     if (text === undefined && option === undefined) { | ||||||
|       throw new Error('Either text or option is necessary.') |       throw new Error('Either text or option is necessary.') | ||||||
|     } |     } | ||||||
|     if (option instanceof Embed) option = { |     if (option instanceof Embed) | ||||||
|  |       option = { | ||||||
|         embed: option |         embed: option | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  | @ -57,7 +68,7 @@ export class TextChannel extends Channel { | ||||||
|       const reference: MessageReference = { |       const reference: MessageReference = { | ||||||
|         message_id: reply.id, |         message_id: reply.id, | ||||||
|         channel_id: reply.channel.id, |         channel_id: reply.channel.id, | ||||||
|         guild_id: reply.guild?.id, |         guild_id: reply.guild?.id | ||||||
|       } |       } | ||||||
|       payload.message_reference = reference |       payload.message_reference = reference | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { UserPayload } from '../types/user.ts' | import { UserPayload } from '../types/user.ts' | ||||||
| import { UserFlagsManager } from "../utils/userFlags.ts" | import { UserFlagsManager } from '../utils/userFlags.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| 
 | 
 | ||||||
| export class User extends Base { | export class User extends Base { | ||||||
|  | @ -14,7 +14,7 @@ export class User extends Base { | ||||||
|   locale?: string |   locale?: string | ||||||
|   verified?: boolean |   verified?: boolean | ||||||
|   email?: string |   email?: string | ||||||
|   flags?: UserFlagsManager |   flags: UserFlagsManager | ||||||
|   /** |   /** | ||||||
|    * Nitro type of the User. |    * Nitro type of the User. | ||||||
|    * |    * | ||||||
|  | @ -23,21 +23,21 @@ export class User extends Base { | ||||||
|    * 2 = Regular Nitro |    * 2 = Regular Nitro | ||||||
|    */ |    */ | ||||||
|   premiumType?: 0 | 1 | 2 |   premiumType?: 0 | 1 | 2 | ||||||
|   publicFlags?: UserFlagsManager |   publicFlags: UserFlagsManager | ||||||
| 
 | 
 | ||||||
|   get tag (): string { |   get tag(): string { | ||||||
|     return `${this.username}#${this.discriminator}` |     return `${this.username}#${this.discriminator}` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get nickMention (): string { |   get nickMention(): string { | ||||||
|     return `<@!${this.id}>` |     return `<@!${this.id}>` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   get mention (): string { |   get mention(): string { | ||||||
|     return `<@${this.id}>` |     return `<@${this.id}>` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: UserPayload) { |   constructor(client: Client, data: UserPayload) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|     this.username = data.username |     this.username = data.username | ||||||
|  | @ -54,7 +54,7 @@ export class User extends Base { | ||||||
|     this.publicFlags = new UserFlagsManager(data.public_flags) |     this.publicFlags = new UserFlagsManager(data.public_flags) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: UserPayload): void { |   protected readFromData(data: UserPayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.username = data.username ?? this.username |     this.username = data.username ?? this.username | ||||||
|     this.discriminator = data.discriminator ?? this.discriminator |     this.discriminator = data.discriminator ?? this.discriminator | ||||||
|  | @ -65,12 +65,16 @@ export class User extends Base { | ||||||
|     this.locale = data.locale ?? this.locale |     this.locale = data.locale ?? this.locale | ||||||
|     this.verified = data.verified ?? this.verified |     this.verified = data.verified ?? this.verified | ||||||
|     this.email = data.email ?? this.email |     this.email = data.email ?? this.email | ||||||
|     this.flags = new UserFlagsManager(data.flags) ?? this.flags |     this.flags = | ||||||
|  |       data.flags !== undefined ? new UserFlagsManager(data.flags) : this.flags | ||||||
|     this.premiumType = data.premium_type ?? this.premiumType |     this.premiumType = data.premium_type ?? this.premiumType | ||||||
|     this.publicFlags = new UserFlagsManager(data.public_flags) ?? this.publicFlags |     this.publicFlags = | ||||||
|  |       data.public_flags !== undefined | ||||||
|  |         ? new UserFlagsManager(data.public_flags) | ||||||
|  |         : this.publicFlags | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   toString (): string { |   toString(): string { | ||||||
|     return this.mention |     return this.mention | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { VoiceStatePayload } from '../types/voice.ts' | import { VoiceStatePayload } from '../types/voice.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { Guild } from "./guild.ts" | import { Guild } from './guild.ts' | ||||||
| import { VoiceChannel } from "./guildVoiceChannel.ts" | import { VoiceChannel } from './guildVoiceChannel.ts' | ||||||
| import { Member } from "./member.ts" | import { Member } from './member.ts' | ||||||
| import { User } from "./user.ts" | import { User } from './user.ts' | ||||||
| 
 | 
 | ||||||
| export class VoiceState extends Base { | export class VoiceState extends Base { | ||||||
|   guild?: Guild |   guild?: Guild | ||||||
|  | @ -18,12 +18,16 @@ export class VoiceState extends Base { | ||||||
|   video: boolean |   video: boolean | ||||||
|   suppress: boolean |   suppress: boolean | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, data: VoiceStatePayload, _data: { |   constructor( | ||||||
|     user: User, |     client: Client, | ||||||
|     channel: VoiceChannel | null, |     data: VoiceStatePayload, | ||||||
|     member?: Member, |     _data: { | ||||||
|  |       user: User | ||||||
|  |       channel: VoiceChannel | null | ||||||
|  |       member?: Member | ||||||
|       guild?: Guild |       guild?: Guild | ||||||
|   }) { |     } | ||||||
|  |   ) { | ||||||
|     super(client, data) |     super(client, data) | ||||||
|     this.channel = _data.channel |     this.channel = _data.channel | ||||||
|     this.sessionID = data.session_id |     this.sessionID = data.session_id | ||||||
|  | @ -39,7 +43,7 @@ export class VoiceState extends Base { | ||||||
|     this.suppress = data.suppress |     this.suppress = data.suppress | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected readFromData (data: VoiceStatePayload): void { |   protected readFromData(data: VoiceStatePayload): void { | ||||||
|     super.readFromData(data) |     super.readFromData(data) | ||||||
|     this.sessionID = data.session_id ?? this.sessionID |     this.sessionID = data.session_id ?? this.sessionID | ||||||
|     this.deaf = data.deaf ?? this.deaf |     this.deaf = data.deaf ?? this.deaf | ||||||
|  |  | ||||||
|  | @ -45,11 +45,11 @@ export class Webhook { | ||||||
|   applicationID?: string |   applicationID?: string | ||||||
|   rest: RESTManager |   rest: RESTManager | ||||||
| 
 | 
 | ||||||
|   get url (): string { |   get url(): string { | ||||||
|     return `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${this.id}/${this.token}` |     return `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${this.id}/${this.token}` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   constructor (data: WebhookPayload, client?: Client, rest?: RESTManager) { |   constructor(data: WebhookPayload, client?: Client, rest?: RESTManager) { | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|     this.type = data.type |     this.type = data.type | ||||||
|     this.channelID = data.channel_id |     this.channelID = data.channel_id | ||||||
|  | @ -70,7 +70,7 @@ export class Webhook { | ||||||
|     else this.rest = new RESTManager() |     else this.rest = new RESTManager() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private fromPayload (data: WebhookPayload): Webhook { |   private fromPayload(data: WebhookPayload): Webhook { | ||||||
|     this.id = data.id |     this.id = data.id | ||||||
|     this.type = data.type |     this.type = data.type | ||||||
|     this.channelID = data.channel_id |     this.channelID = data.channel_id | ||||||
|  | @ -90,7 +90,7 @@ export class Webhook { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** Send a Message through Webhook. */ |   /** Send a Message through Webhook. */ | ||||||
|   async send ( |   async send( | ||||||
|     text?: string | AllWebhookMessageOptions, |     text?: string | AllWebhookMessageOptions, | ||||||
|     option?: AllWebhookMessageOptions |     option?: AllWebhookMessageOptions | ||||||
|   ): Promise<Message> { |   ): Promise<Message> { | ||||||
|  | @ -153,7 +153,7 @@ export class Webhook { | ||||||
|    * @param url URL of the Webhook |    * @param url URL of the Webhook | ||||||
|    * @param client Client (bot) object, if any. |    * @param client Client (bot) object, if any. | ||||||
|    */ |    */ | ||||||
|   static async fromURL (url: string | URL, client?: Client): Promise<Webhook> { |   static async fromURL(url: string | URL, client?: Client): Promise<Webhook> { | ||||||
|     const rest = client !== undefined ? client.rest : new RESTManager() |     const rest = client !== undefined ? client.rest : new RESTManager() | ||||||
| 
 | 
 | ||||||
|     const raw = await rest.get(typeof url === 'string' ? url : url.toString()) |     const raw = await rest.get(typeof url === 'string' ? url : url.toString()) | ||||||
|  | @ -168,7 +168,7 @@ export class Webhook { | ||||||
|    * Edit the Webhook name, avatar, or channel (requires authentication). |    * Edit the Webhook name, avatar, or channel (requires authentication). | ||||||
|    * @param options Options to edit the Webhook. |    * @param options Options to edit the Webhook. | ||||||
|    */ |    */ | ||||||
|   async edit (options: WebhookEditOptions): Promise<Webhook> { |   async edit(options: WebhookEditOptions): Promise<Webhook> { | ||||||
|     if (options.channelID !== undefined && this.rest.client === undefined) |     if (options.channelID !== undefined && this.rest.client === undefined) | ||||||
|       throw new Error('Authentication is required for editing Webhook Channel') |       throw new Error('Authentication is required for editing Webhook Channel') | ||||||
|     if ( |     if ( | ||||||
|  | @ -186,7 +186,7 @@ export class Webhook { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** Delete the Webhook. */ |   /** Delete the Webhook. */ | ||||||
|   async delete (): Promise<boolean> { |   async delete(): Promise<boolean> { | ||||||
|     const resp = await this.rest.delete(this.url, undefined, 0, undefined, true) |     const resp = await this.rest.delete(this.url, undefined, 0, undefined, true) | ||||||
|     if (resp.response.status !== 204) return false |     if (resp.response.status !== 204) return false | ||||||
|     else return true |     else return true | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import { | ||||||
|   Intents, |   Intents, | ||||||
|   GuildChannel, |   GuildChannel, | ||||||
|   CommandContext, |   CommandContext, | ||||||
|   Extension, |   Extension | ||||||
| } from '../../mod.ts' | } from '../../mod.ts' | ||||||
| import { Invite } from '../structures/invite.ts' | import { Invite } from '../structures/invite.ts' | ||||||
| import { TOKEN } from './config.ts' | import { TOKEN } from './config.ts' | ||||||
|  | @ -12,7 +12,7 @@ import { TOKEN } from './config.ts' | ||||||
| const client = new CommandClient({ | const client = new CommandClient({ | ||||||
|   prefix: ['pls', '!'], |   prefix: ['pls', '!'], | ||||||
|   spacesAfterPrefix: true, |   spacesAfterPrefix: true, | ||||||
|   mentionPrefix: true, |   mentionPrefix: true | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| client.on('debug', console.log) | client.on('debug', console.log) | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ import { CommandContext } from '../../models/command.ts' | ||||||
| 
 | 
 | ||||||
| export default class AddEmojiCommand extends Command { | export default class AddEmojiCommand extends Command { | ||||||
|   name = 'addemoji' |   name = 'addemoji' | ||||||
|   aliases = [ 'ae', 'emojiadd' ] |   aliases = ['ae', 'emojiadd'] | ||||||
|   args = 2 |   args = 2 | ||||||
|   guildOnly = true |   guildOnly = true | ||||||
| 
 | 
 | ||||||
|  | @ -12,10 +12,15 @@ export default class AddEmojiCommand extends Command { | ||||||
|     if (name === undefined) return ctx.message.reply('No name was given!') |     if (name === undefined) return ctx.message.reply('No name was given!') | ||||||
|     const url = ctx.argString.slice(name.length).trim() |     const url = ctx.argString.slice(name.length).trim() | ||||||
|     if (url === '') return ctx.message.reply('No URL was given!') |     if (url === '') return ctx.message.reply('No URL was given!') | ||||||
|     ctx.message.guild?.emojis.create(name, url).then(emoji => { |     ctx.message.guild?.emojis | ||||||
|  |       .create(name, url) | ||||||
|  |       .then((emoji) => { | ||||||
|         if (emoji === undefined) throw new Error('Unknown') |         if (emoji === undefined) throw new Error('Unknown') | ||||||
|         ctx.message.reply(`Successfuly added emoji ${emoji.toString()} ${emoji.name}!`) |         ctx.message.reply( | ||||||
|     }).catch(e => { |           `Successfuly added emoji ${emoji.toString()} ${emoji.name}!` | ||||||
|  |         ) | ||||||
|  |       }) | ||||||
|  |       .catch((e) => { | ||||||
|         ctx.message.reply(`Failed to add emoji. Reason: ${e.message}`) |         ctx.message.reply(`Failed to add emoji. Reason: ${e.message}`) | ||||||
|       }) |       }) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -2,16 +2,34 @@ import { Command, Embed } from '../../../mod.ts' | ||||||
| import { CommandContext } from '../../models/command.ts' | import { CommandContext } from '../../models/command.ts' | ||||||
| 
 | 
 | ||||||
| export default class PingCommand extends Command { | export default class PingCommand extends Command { | ||||||
|   name = "mentions" |   name = 'mentions' | ||||||
|   aliases = ["m"] |   aliases = ['m'] | ||||||
| 
 | 
 | ||||||
|   execute(ctx: CommandContext): void { |   execute(ctx: CommandContext): void { | ||||||
|     const embed = new Embed() |     const embed = new Embed() | ||||||
|       .setTitle('Mentions') |       .setTitle('Mentions') | ||||||
|       .addField('Users', `${ctx.message.mentions.users.size === 0 ? `None` : ''}${ctx.message.mentions.users.map(u => u.toString()).join(", ")}`) |       .addField( | ||||||
|       .addField('Channels', `${ctx.message.mentions.channels.size === 0 ? `None` : ''}${ctx.message.mentions.channels.map(u => u.toString()).join(", ")}`) |         'Users', | ||||||
|       .addField('Roles', `${ctx.message.mentions.roles.size === 0 ? `None` : ''}${ctx.message.mentions.roles.map(u => u.toString()).join(", ")}`) |         `${ | ||||||
|       .addField('Everyone?', ctx.message.mentions.everyone === true ? 'Yes' : 'No') |           ctx.message.mentions.users.size === 0 ? `None` : '' | ||||||
|  |         }${ctx.message.mentions.users.map((u) => u.toString()).join(', ')}` | ||||||
|  |       ) | ||||||
|  |       .addField( | ||||||
|  |         'Channels', | ||||||
|  |         `${ | ||||||
|  |           ctx.message.mentions.channels.size === 0 ? `None` : '' | ||||||
|  |         }${ctx.message.mentions.channels.map((u) => u.toString()).join(', ')}` | ||||||
|  |       ) | ||||||
|  |       .addField( | ||||||
|  |         'Roles', | ||||||
|  |         `${ | ||||||
|  |           ctx.message.mentions.roles.size === 0 ? `None` : '' | ||||||
|  |         }${ctx.message.mentions.roles.map((u) => u.toString()).join(', ')}` | ||||||
|  |       ) | ||||||
|  |       .addField( | ||||||
|  |         'Everyone?', | ||||||
|  |         ctx.message.mentions.everyone === true ? 'Yes' : 'No' | ||||||
|  |       ) | ||||||
|       .setColor(0xff0000) |       .setColor(0xff0000) | ||||||
|     ctx.message.channel.send(embed) |     ctx.message.channel.send(embed) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ import { Command } from '../../../mod.ts' | ||||||
| import { CommandContext } from '../../models/command.ts' | import { CommandContext } from '../../models/command.ts' | ||||||
| 
 | 
 | ||||||
| export default class PingCommand extends Command { | export default class PingCommand extends Command { | ||||||
|   name = "ping" |   name = 'ping' | ||||||
| 
 | 
 | ||||||
|   execute(ctx: CommandContext): void { |   execute(ctx: CommandContext): void { | ||||||
|     ctx.message.reply(`Pong! Latency: ${ctx.client.ping}ms`) |     ctx.message.reply(`Pong! Latency: ${ctx.client.ping}ms`) | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| import { Command, Member, CommandContext, Embed } from '../../../mod.ts' | import { Command, Member, CommandContext, Embed } from '../../../mod.ts' | ||||||
| 
 | 
 | ||||||
| export default class UserinfoCommand extends Command { | export default class UserinfoCommand extends Command { | ||||||
|     name = "userinfo" |   name = 'userinfo' | ||||||
|   guildOnly = true |   guildOnly = true | ||||||
|     aliases = [ 'u', 'user' ] |   aliases = ['u', 'user'] | ||||||
| 
 | 
 | ||||||
|   async execute(ctx: CommandContext): Promise<void> { |   async execute(ctx: CommandContext): Promise<void> { | ||||||
|     const member: Member = ctx.message.member as any |     const member: Member = ctx.message.member as any | ||||||
|  | @ -11,9 +11,12 @@ export default class UserinfoCommand extends Command { | ||||||
|     const embed = new Embed() |     const embed = new Embed() | ||||||
|       .setTitle(`User Info`) |       .setTitle(`User Info`) | ||||||
|       .setAuthor({ name: member.user.tag }) |       .setAuthor({ name: member.user.tag }) | ||||||
|         .addField("ID", member.id) |       .addField('ID', member.id) | ||||||
|         .addField("Roles", roles.map(r => r.name).join(", ")) |       .addField('Roles', roles.map((r) => r.name).join(', ')) | ||||||
|         .addField('Permissions', JSON.stringify(member.permissions.has('ADMINISTRATOR'))) |       .addField( | ||||||
|  |         'Permissions', | ||||||
|  |         JSON.stringify(member.permissions.has('ADMINISTRATOR')) | ||||||
|  |       ) | ||||||
|       .setColor(0xff00ff) |       .setColor(0xff00ff) | ||||||
|     ctx.channel.send(embed) |     ctx.channel.send(embed) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -1,9 +1,11 @@ | ||||||
| import { Webhook } from '../../mod.ts' | import { Webhook } from '../../mod.ts' | ||||||
| import { WEBHOOK } from "./config.ts" | import { WEBHOOK } from './config.ts' | ||||||
| 
 | 
 | ||||||
| const webhook = await Webhook.fromURL(WEBHOOK) | const webhook = await Webhook.fromURL(WEBHOOK) | ||||||
| console.log('Fetched webhook!') | console.log('Fetched webhook!') | ||||||
| 
 | 
 | ||||||
| webhook.send('Hello World', { | webhook | ||||||
|  |   .send('Hello World', { | ||||||
|     name: 'OwO' |     name: 'OwO' | ||||||
| }).then(() => 'Sent message!') |   }) | ||||||
|  |   .then(() => 'Sent message!') | ||||||
|  |  | ||||||
|  | @ -1,11 +1,24 @@ | ||||||
| import { Client, Intents, GuildTextChannel, Message, ClientPresence, Member, Role, GuildChannel, Embed, Guild } from '../../mod.ts' | import { | ||||||
|  |   Client, | ||||||
|  |   Intents, | ||||||
|  |   Message, | ||||||
|  |   ClientPresence, | ||||||
|  |   Member, | ||||||
|  |   Role, | ||||||
|  |   GuildChannel, | ||||||
|  |   Embed, | ||||||
|  |   Guild, | ||||||
|  |   EveryChannelTypes, | ||||||
|  |   ChannelTypes, | ||||||
|  |   GuildTextChannel | ||||||
|  | } from '../../mod.ts' | ||||||
| import { TOKEN } from './config.ts' | import { TOKEN } from './config.ts' | ||||||
| 
 | 
 | ||||||
| const client = new Client({ | const client = new Client({ | ||||||
|   presence: new ClientPresence({ |   presence: new ClientPresence({ | ||||||
|     name: 'Pokémon Sword', |     name: 'Pokémon Sword', | ||||||
|     type: 'COMPETING' |     type: 'COMPETING' | ||||||
|   }), |   }) | ||||||
|   // bot: false,
 |   // bot: false,
 | ||||||
|   // cache: new RedisCacheAdapter({
 |   // cache: new RedisCacheAdapter({
 | ||||||
|   //   hostname: '127.0.0.1',
 |   //   hostname: '127.0.0.1',
 | ||||||
|  | @ -19,13 +32,19 @@ client.on('ready', () => { | ||||||
| 
 | 
 | ||||||
| client.on('debug', console.log) | client.on('debug', console.log) | ||||||
| 
 | 
 | ||||||
| client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) => { | client.on('channelUpdate', (b: EveryChannelTypes, a: EveryChannelTypes) => { | ||||||
|   console.log(before.send('', { |   if (b.type === ChannelTypes.GUILD_TEXT) { | ||||||
|  |     const before = (b as unknown) as GuildTextChannel | ||||||
|  |     const after = (a as unknown) as GuildTextChannel | ||||||
|  |     console.log( | ||||||
|  |       before.send('', { | ||||||
|         embed: new Embed({ |         embed: new Embed({ | ||||||
|           title: 'Channel Update', |           title: 'Channel Update', | ||||||
|           description: `Name Before: ${before.name}\nName After: ${after.name}` |           description: `Name Before: ${before.name}\nName After: ${after.name}` | ||||||
|         }) |         }) | ||||||
|   })) |       }) | ||||||
|  |     ) | ||||||
|  |   } | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| client.on('messageCreate', async (msg: Message) => { | client.on('messageCreate', async (msg: Message) => { | ||||||
|  | @ -35,26 +54,40 @@ client.on('messageCreate', async (msg: Message) => { | ||||||
|     msg.reply(`Pong! Ping: ${client.ping}ms`) |     msg.reply(`Pong! Ping: ${client.ping}ms`) | ||||||
|   } else if (msg.content === '!members') { |   } else if (msg.content === '!members') { | ||||||
|     const col = await msg.guild?.members.collection() |     const col = await msg.guild?.members.collection() | ||||||
|     const data = col?.array().map((c: Member, i: number) => { |     const data = col | ||||||
|  |       ?.array() | ||||||
|  |       .map((c: Member, i: number) => { | ||||||
|         return `${i + 1}. ${c.user.tag}` |         return `${i + 1}. ${c.user.tag}` | ||||||
|     }).join("\n") as string |       }) | ||||||
|     msg.channel.send("Member List:\n" + data) |       .join('\n') as string | ||||||
|  |     msg.channel.send('Member List:\n' + data) | ||||||
|   } else if (msg.content === '!guilds') { |   } else if (msg.content === '!guilds') { | ||||||
|     const guilds = await msg.client.guilds.collection() |     const guilds = await msg.client.guilds.collection() | ||||||
|     msg.channel.send('Guild List:\n' + (guilds.array().map((c: Guild, i: number) => { |     msg.channel.send( | ||||||
|  |       'Guild List:\n' + | ||||||
|  |         (guilds | ||||||
|  |           .array() | ||||||
|  |           .map((c: Guild, i: number) => { | ||||||
|             return `${i + 1}. ${c.name} - ${c.memberCount} members` |             return `${i + 1}. ${c.name} - ${c.memberCount} members` | ||||||
|     }).join("\n") as string)) |           }) | ||||||
|  |           .join('\n') as string) | ||||||
|  |     ) | ||||||
|   } else if (msg.content === '!roles') { |   } else if (msg.content === '!roles') { | ||||||
|     const col = await msg.guild?.roles.collection() |     const col = await msg.guild?.roles.collection() | ||||||
|     const data = col?.array().map((c: Role, i: number) => { |     const data = col | ||||||
|  |       ?.array() | ||||||
|  |       .map((c: Role, i: number) => { | ||||||
|         return `${i + 1}. ${c.name}` |         return `${i + 1}. ${c.name}` | ||||||
|     }).join("\n") as string |       }) | ||||||
|     msg.channel.send("Roles List:\n" + data) |       .join('\n') as string | ||||||
|  |     msg.channel.send('Roles List:\n' + data) | ||||||
|   } else if (msg.content === '!channels') { |   } else if (msg.content === '!channels') { | ||||||
|     const col = await msg.guild?.channels.array() |     const col = await msg.guild?.channels.array() | ||||||
|     const data = col?.map((c: GuildChannel, i: number) => { |     const data = col | ||||||
|  |       ?.map((c: GuildChannel, i: number) => { | ||||||
|         return `${i + 1}. ${c.name}` |         return `${i + 1}. ${c.name}` | ||||||
|     }).join("\n") as string |       }) | ||||||
|  |       .join('\n') as string | ||||||
|     msg.channel.send('Channels List:\n' + data) |     msg.channel.send('Channels List:\n' + data) | ||||||
|   } |   } | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import { UserPayload } from "./user.ts"; | import { UserPayload } from './user.ts' | ||||||
| 
 | 
 | ||||||
| export interface ApplicationPayload { | export interface ApplicationPayload { | ||||||
|   id: string |   id: string | ||||||
|  |  | ||||||
|  | @ -1,2 +1,2 @@ | ||||||
| export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | ||||||
| export type ImageFormats = "jpg" | "jpeg" | "png" | "webp" | "gif" | export type ImageFormats = 'jpg' | 'jpeg' | 'png' | 'webp' | 'gif' | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import { | ||||||
|   ActivityGame, |   ActivityGame, | ||||||
|   ActivityPayload, |   ActivityPayload, | ||||||
|   StatusType, |   StatusType, | ||||||
|   ClientStatus, |   ClientStatus | ||||||
| } from './presence.ts' | } from './presence.ts' | ||||||
| import { RolePayload } from './role.ts' | import { RolePayload } from './role.ts' | ||||||
| import { UserPayload } from './user.ts' | import { UserPayload } from './user.ts' | ||||||
|  | @ -27,7 +27,7 @@ export enum GatewayOpcodes { // 문서를 확인해본 결과 Opcode 5번은 비 | ||||||
|   REQUEST_GUILD_MEMBERS = 8, |   REQUEST_GUILD_MEMBERS = 8, | ||||||
|   INVALID_SESSION = 9, |   INVALID_SESSION = 9, | ||||||
|   HELLO = 10, |   HELLO = 10, | ||||||
|   HEARTBEAT_ACK = 11, |   HEARTBEAT_ACK = 11 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -47,7 +47,7 @@ export enum GatewayCloseCodes { | ||||||
|   SHARDING_REQUIRED = 4011, |   SHARDING_REQUIRED = 4011, | ||||||
|   INVALID_API_VERSION = 4012, |   INVALID_API_VERSION = 4012, | ||||||
|   INVALID_INTENTS = 4013, |   INVALID_INTENTS = 4013, | ||||||
|   DISALLOWED_INTENTS = 4014, |   DISALLOWED_INTENTS = 4014 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum GatewayIntents { | export enum GatewayIntents { | ||||||
|  | @ -65,7 +65,7 @@ export enum GatewayIntents { | ||||||
|   GUILD_MESSAGE_TYPING = 1 << 11, |   GUILD_MESSAGE_TYPING = 1 << 11, | ||||||
|   DIRECT_MESSAGES = 1 << 12, |   DIRECT_MESSAGES = 1 << 12, | ||||||
|   DIRECT_MESSAGE_REACTIONS = 1 << 13, |   DIRECT_MESSAGE_REACTIONS = 1 << 13, | ||||||
|   DIRECT_MESSAGE_TYPING = 1 << 13, |   DIRECT_MESSAGE_TYPING = 1 << 13 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum GatewayEvents { | export enum GatewayEvents { | ||||||
|  | @ -105,7 +105,7 @@ export enum GatewayEvents { | ||||||
|   User_Update = 'USER_UPDATE', |   User_Update = 'USER_UPDATE', | ||||||
|   Voice_Server_Update = 'VOICE_SERVER_UPDATE', |   Voice_Server_Update = 'VOICE_SERVER_UPDATE', | ||||||
|   Voice_State_Update = 'VOICE_STATE_UPDATE', |   Voice_State_Update = 'VOICE_STATE_UPDATE', | ||||||
|   Webhooks_Update = 'WEBHOOKS_UPDATE', |   Webhooks_Update = 'WEBHOOKS_UPDATE' | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface IdentityPayload { | export interface IdentityPayload { | ||||||
|  |  | ||||||
|  | @ -66,18 +66,18 @@ export interface MemberPayload { | ||||||
| 
 | 
 | ||||||
| export enum MessageNotification { | export enum MessageNotification { | ||||||
|   ALL_MESSAGES = 0, |   ALL_MESSAGES = 0, | ||||||
|   ONLY_MENTIONS = 1, |   ONLY_MENTIONS = 1 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum ContentFilter { | export enum ContentFilter { | ||||||
|   DISABLED = 0, |   DISABLED = 0, | ||||||
|   MEMBERS_WITHOUT_ROLES = 1, |   MEMBERS_WITHOUT_ROLES = 1, | ||||||
|   ALL_MEMBERS = 3, |   ALL_MEMBERS = 3 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum MFA { | export enum MFA { | ||||||
|   NONE = 0, |   NONE = 0, | ||||||
|   ELEVATED = 1, |   ELEVATED = 1 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum Verification { | export enum Verification { | ||||||
|  | @ -85,19 +85,19 @@ export enum Verification { | ||||||
|   LOW = 1, |   LOW = 1, | ||||||
|   MEDIUM = 2, |   MEDIUM = 2, | ||||||
|   HIGH = 3, |   HIGH = 3, | ||||||
|   VERY_HIGH = 4, |   VERY_HIGH = 4 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum PremiumTier { | export enum PremiumTier { | ||||||
|   NONE = 0, |   NONE = 0, | ||||||
|   TIER_1 = 1, |   TIER_1 = 1, | ||||||
|   TIER_2 = 2, |   TIER_2 = 2, | ||||||
|   TIER_3 = 3, |   TIER_3 = 3 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum SystemChannelFlags { | export enum SystemChannelFlags { | ||||||
|   SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0, |   SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0, | ||||||
|   SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1, |   SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export type GuildFeatures = | export type GuildFeatures = | ||||||
|  | @ -116,7 +116,7 @@ export type GuildFeatures = | ||||||
| 
 | 
 | ||||||
| export enum IntegrationExpireBehavior { | export enum IntegrationExpireBehavior { | ||||||
|   REMOVE_ROLE = 0, |   REMOVE_ROLE = 0, | ||||||
|   KICK = 1, |   KICK = 1 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface IntegrationAccountPayload { | export interface IntegrationAccountPayload { | ||||||
|  |  | ||||||
|  | @ -31,5 +31,5 @@ export const PermissionFlags: { [key: string]: number } = { | ||||||
|   MANAGE_NICKNAMES: 1 << 27, |   MANAGE_NICKNAMES: 1 << 27, | ||||||
|   MANAGE_ROLES: 1 << 28, |   MANAGE_ROLES: 1 << 28, | ||||||
|   MANAGE_WEBHOOKS: 1 << 29, |   MANAGE_WEBHOOKS: 1 << 29, | ||||||
|   MANAGE_EMOJIS: 1 << 30, |   MANAGE_EMOJIS: 1 << 30 | ||||||
| } | } | ||||||
|  | @ -56,7 +56,7 @@ export enum ActivityFlags { | ||||||
|   SPECTATE = 1 << 2, |   SPECTATE = 1 << 2, | ||||||
|   JOIN_REQUEST = 1 << 3, |   JOIN_REQUEST = 1 << 3, | ||||||
|   SYNC = 1 << 4, |   SYNC = 1 << 4, | ||||||
|   PLAY = 1 << 5, |   PLAY = 1 << 5 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export type ActivityType = | export type ActivityType = | ||||||
|  |  | ||||||
|  | @ -19,12 +19,13 @@ export class BitField { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   has(bit: BitFieldResolvable, ...args: any[]): boolean { |   has(bit: BitFieldResolvable, ...args: any[]): boolean { | ||||||
|     if (Array.isArray(bit)) return bit.every(p => this.has(p)) |     if (Array.isArray(bit)) return bit.every((p) => this.has(p)) | ||||||
|     return (this.bitfield & BitField.resolve(this.flags, bit)) === bit |     return (this.bitfield & BitField.resolve(this.flags, bit)) === bit | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   missing(bits: any, ...hasParams: any[]): string[] { |   missing(bits: any, ...hasParams: any[]): string[] { | ||||||
|     if (!Array.isArray(bits)) bits = new BitField(this.flags, bits).toArray(false) |     if (!Array.isArray(bits)) | ||||||
|  |       bits = new BitField(this.flags, bits).toArray(false) | ||||||
|     return bits.filter((p: any) => !this.has(p, ...hasParams)) |     return bits.filter((p: any) => !this.has(p, ...hasParams)) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -37,7 +38,8 @@ export class BitField { | ||||||
|     for (const bit of bits) { |     for (const bit of bits) { | ||||||
|       total |= BitField.resolve(this.flags, bit) |       total |= BitField.resolve(this.flags, bit) | ||||||
|     } |     } | ||||||
|     if (Object.isFrozen(this)) return new BitField(this.flags, this.bitfield | total) |     if (Object.isFrozen(this)) | ||||||
|  |       return new BitField(this.flags, this.bitfield | total) | ||||||
|     this.bitfield |= total |     this.bitfield |= total | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
|  | @ -47,19 +49,26 @@ export class BitField { | ||||||
|     for (const bit of bits) { |     for (const bit of bits) { | ||||||
|       total |= BitField.resolve(this.flags, bit) |       total |= BitField.resolve(this.flags, bit) | ||||||
|     } |     } | ||||||
|     if (Object.isFrozen(this)) return new BitField(this.flags, this.bitfield & ~total) |     if (Object.isFrozen(this)) | ||||||
|  |       return new BitField(this.flags, this.bitfield & ~total) | ||||||
|     this.bitfield &= ~total |     this.bitfield &= ~total | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   serialize(...hasParams: any[]): { [key: string]: any } { |   serialize(...hasParams: any[]): { [key: string]: any } { | ||||||
|     const serialized: { [key: string]: any } = {} |     const serialized: { [key: string]: any } = {} | ||||||
|     for (const [flag, bit] of Object.entries(this.flags)) serialized[flag] = this.has(BitField.resolve(this.flags, bit), ...hasParams) |     for (const [flag, bit] of Object.entries(this.flags)) | ||||||
|  |       serialized[flag] = this.has( | ||||||
|  |         BitField.resolve(this.flags, bit), | ||||||
|  |         ...hasParams | ||||||
|  |       ) | ||||||
|     return serialized |     return serialized | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   toArray(...hasParams: any[]): string[] { |   toArray(...hasParams: any[]): string[] { | ||||||
|     return Object.keys(this.flags).filter(bit => this.has(BitField.resolve(this.flags, bit), ...hasParams)) |     return Object.keys(this.flags).filter((bit) => | ||||||
|  |       this.has(BitField.resolve(this.flags, bit), ...hasParams) | ||||||
|  |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   toJSON(): number { |   toJSON(): number { | ||||||
|  | @ -78,8 +87,12 @@ export class BitField { | ||||||
|     if (typeof bit === 'string' && !isNaN(parseInt(bit))) return parseInt(bit) |     if (typeof bit === 'string' && !isNaN(parseInt(bit))) return parseInt(bit) | ||||||
|     if (typeof bit === 'number' && bit >= 0) return bit |     if (typeof bit === 'number' && bit >= 0) return bit | ||||||
|     if (bit instanceof BitField) return this.resolve(flags, bit.bitfield) |     if (bit instanceof BitField) return this.resolve(flags, bit.bitfield) | ||||||
|     if (Array.isArray(bit)) return bit.map(p => this.resolve(flags, p)).reduce((prev, p) => prev | p, 0) |     if (Array.isArray(bit)) | ||||||
|     if (typeof bit === 'string' && typeof flags[bit] !== 'undefined') return flags[bit] |       return bit | ||||||
|  |         .map((p) => this.resolve(flags, p)) | ||||||
|  |         .reduce((prev, p) => prev | p, 0) | ||||||
|  |     if (typeof bit === 'string' && typeof flags[bit] !== 'undefined') | ||||||
|  |       return flags[bit] | ||||||
|     const error = new RangeError('BITFIELD_INVALID') |     const error = new RangeError('BITFIELD_INVALID') | ||||||
|     throw error |     throw error | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ export class Collection<K = string, V = any> extends Map<K, V> { | ||||||
| 
 | 
 | ||||||
|   reduce<T>( |   reduce<T>( | ||||||
|     callback: (accumulator: T, value: V, key: K) => T, |     callback: (accumulator: T, value: V, key: K) => T, | ||||||
|     initialValue?: T, |     initialValue?: T | ||||||
|   ): T { |   ): T { | ||||||
|     let accumulator: T = initialValue as T |     let accumulator: T = initialValue as T | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
| export const delay = async (ms: number): Promise<true> => await new Promise((resolve, reject) => { | export const delay = async (ms: number): Promise<true> => | ||||||
|     setTimeout(() => resolve(true), ms); |   await new Promise((resolve, reject) => { | ||||||
| }); |     setTimeout(() => resolve(true), ms) | ||||||
|  |   }) | ||||||
|  |  | ||||||
|  | @ -7,7 +7,8 @@ import { | ||||||
|   GuildChannelCategoryPayload, |   GuildChannelCategoryPayload, | ||||||
|   GuildNewsChannelPayload, |   GuildNewsChannelPayload, | ||||||
|   GuildTextChannelPayload, |   GuildTextChannelPayload, | ||||||
|   GuildVoiceChannelPayload |   GuildVoiceChannelPayload, | ||||||
|  |   TextChannelPayload | ||||||
| } from '../types/channel.ts' | } from '../types/channel.ts' | ||||||
| import { DMChannel } from '../structures/dmChannel.ts' | import { DMChannel } from '../structures/dmChannel.ts' | ||||||
| import { GroupDMChannel } from '../structures/groupChannel.ts' | import { GroupDMChannel } from '../structures/groupChannel.ts' | ||||||
|  | @ -15,39 +16,64 @@ import { CategoryChannel } from '../structures/guildCategoryChannel.ts' | ||||||
| import { NewsChannel } from '../structures/guildNewsChannel.ts' | import { NewsChannel } from '../structures/guildNewsChannel.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 { TextChannel, GuildTextChannel } from '../structures/textChannel.ts' | import { GuildTextChannel, TextChannel } from '../structures/textChannel.ts' | ||||||
|  | import { Channel } from '../structures/channel.ts' | ||||||
|  | 
 | ||||||
|  | export type EveryTextChannelTypes = | ||||||
|  |   | TextChannel | ||||||
|  |   | NewsChannel | ||||||
|  |   | GuildTextChannel | ||||||
|  |   | DMChannel | ||||||
|  |   | GroupDMChannel | ||||||
|  | 
 | ||||||
|  | export type EveryTextChannelPayloadTypes = | ||||||
|  |   | TextChannelPayload | ||||||
|  |   | GuildNewsChannelPayload | ||||||
|  |   | GuildTextChannelPayload | ||||||
|  |   | DMChannelPayload | ||||||
|  |   | GroupDMChannelPayload | ||||||
|  | 
 | ||||||
|  | export type EveryChannelTypes = | ||||||
|  |   | Channel | ||||||
|  |   | CategoryChannel | ||||||
|  |   | VoiceChannel | ||||||
|  |   | EveryTextChannelTypes | ||||||
|  | 
 | ||||||
|  | export type EveryChannelPayloadTypes = | ||||||
|  |   | ChannelPayload | ||||||
|  |   | GuildChannelCategoryPayload | ||||||
|  |   | GuildVoiceChannelPayload | ||||||
|  |   | EveryTextChannelPayloadTypes | ||||||
| 
 | 
 | ||||||
| const getChannelByType = ( | const getChannelByType = ( | ||||||
|   client: Client, |   client: Client, | ||||||
|   data: |   data: EveryChannelPayloadTypes, | ||||||
|     | GuildChannelCategoryPayload |  | ||||||
|     | GuildNewsChannelPayload |  | ||||||
|     | GuildTextChannelPayload |  | ||||||
|     | GuildVoiceChannelPayload |  | ||||||
|     | DMChannelPayload |  | ||||||
|     | GroupDMChannelPayload |  | ||||||
|     | ChannelPayload, |  | ||||||
|   guild?: Guild |   guild?: Guild | ||||||
| ): | ): EveryChannelTypes | undefined => { | ||||||
|   | CategoryChannel |  | ||||||
|   | NewsChannel |  | ||||||
|   | TextChannel |  | ||||||
|   | VoiceChannel |  | ||||||
|   | DMChannel |  | ||||||
|   | GroupDMChannel |  | ||||||
|   | undefined => { |  | ||||||
|   switch (data.type) { |   switch (data.type) { | ||||||
|     case ChannelTypes.GUILD_CATEGORY: |     case ChannelTypes.GUILD_CATEGORY: | ||||||
|       if (guild === undefined) throw new Error("No Guild was provided to construct Channel") |       if (guild === undefined) | ||||||
|       return new CategoryChannel(client, data as GuildChannelCategoryPayload, guild) |         throw new Error('No Guild was provided to construct Channel') | ||||||
|  |       return new CategoryChannel( | ||||||
|  |         client, | ||||||
|  |         data as GuildChannelCategoryPayload, | ||||||
|  |         guild | ||||||
|  |       ) | ||||||
|     case ChannelTypes.GUILD_NEWS: |     case ChannelTypes.GUILD_NEWS: | ||||||
|       if (guild === undefined) throw new Error("No Guild was provided to construct Channel") |       if (guild === undefined) | ||||||
|  |         throw new Error('No Guild was provided to construct Channel') | ||||||
|       return new NewsChannel(client, data as GuildNewsChannelPayload, guild) |       return new NewsChannel(client, data as GuildNewsChannelPayload, guild) | ||||||
|     case ChannelTypes.GUILD_TEXT: |     case ChannelTypes.GUILD_TEXT: | ||||||
|       if (guild === undefined) throw new Error("No Guild was provided to construct Channel") |       if (guild === undefined) | ||||||
|       return new GuildTextChannel(client, data as GuildTextChannelPayload, guild) |         throw new Error('No Guild was provided to construct Channel') | ||||||
|  |       return new GuildTextChannel( | ||||||
|  |         client, | ||||||
|  |         data as GuildTextChannelPayload, | ||||||
|  |         guild | ||||||
|  |       ) | ||||||
|     case ChannelTypes.GUILD_VOICE: |     case ChannelTypes.GUILD_VOICE: | ||||||
|       if (guild === undefined) throw new Error("No Guild was provided to construct Channel") |       if (guild === undefined) | ||||||
|  |         throw new Error('No Guild was provided to construct Channel') | ||||||
|       return new VoiceChannel(client, data as GuildVoiceChannelPayload, guild) |       return new VoiceChannel(client, data as GuildVoiceChannelPayload, guild) | ||||||
|     case ChannelTypes.DM: |     case ChannelTypes.DM: | ||||||
|       return new DMChannel(client, data as DMChannelPayload) |       return new DMChannel(client, data as DMChannelPayload) | ||||||
|  |  | ||||||
|  | @ -1,3 +1,3 @@ | ||||||
| export { default as getChannelByType } from './getChannelByType.ts' | export { default as getChannelByType } from './getChannelByType.ts' | ||||||
| export type AnyFunction<ReturnType = any> = (...args:any[]) => ReturnType; | export type AnyFunction<ReturnType = any> = (...args: any[]) => ReturnType | ||||||
| export { delay } from './delay.ts' | export { delay } from './delay.ts' | ||||||
|  | @ -36,22 +36,23 @@ export class Intents { | ||||||
|     ...Intents.NonPriviliged |     ...Intents.NonPriviliged | ||||||
|   ] |   ] | ||||||
| 
 | 
 | ||||||
|   static None: number[] = [ |   static None: number[] = [...Intents.NonPriviliged] | ||||||
|     ...Intents.NonPriviliged |  | ||||||
|   ] |  | ||||||
| 
 | 
 | ||||||
|   static create(priviliged?: PriviligedIntents[], disable?: number[]): number[] { |   static create( | ||||||
|     let intents: number[] = [ |     priviliged?: PriviligedIntents[], | ||||||
|       ...Intents.NonPriviliged |     disable?: number[] | ||||||
|     ] |   ): number[] { | ||||||
|  |     let intents: number[] = [...Intents.NonPriviliged] | ||||||
| 
 | 
 | ||||||
|     if (priviliged !== undefined && priviliged.length !== 0) { |     if (priviliged !== undefined && priviliged.length !== 0) { | ||||||
|       if (priviliged.includes('GUILD_MEMBERS')) intents.push(GatewayIntents.GUILD_MEMBERS) |       if (priviliged.includes('GUILD_MEMBERS')) | ||||||
|       if (priviliged.includes('GUILD_PRESENCES')) intents.push(GatewayIntents.GUILD_PRESENCES) |         intents.push(GatewayIntents.GUILD_MEMBERS) | ||||||
|  |       if (priviliged.includes('GUILD_PRESENCES')) | ||||||
|  |         intents.push(GatewayIntents.GUILD_PRESENCES) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (disable !== undefined) { |     if (disable !== undefined) { | ||||||
|       intents = intents.filter(intent => !disable.includes(intent)) |       intents = intents.filter((intent) => !disable.includes(intent)) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return intents |     return intents | ||||||
|  |  | ||||||
|  | @ -1,3 +1,3 @@ | ||||||
| export const awaitSync = async(val: any | Promise<any>): Promise<any> => { | export const awaitSync = async (val: any | Promise<any>): Promise<any> => { | ||||||
|   return val instanceof Promise ? await val : val |   return val instanceof Promise ? await val : val | ||||||
| } | } | ||||||
|  | @ -1,8 +1,12 @@ | ||||||
| // Ported from https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js
 | // Ported from https://github.com/discordjs/discord.js/blob/master/src/util/Permissions.js
 | ||||||
| import { PermissionFlags } from "../types/permissionFlags.ts" | import { PermissionFlags } from '../types/permissionFlags.ts' | ||||||
| import { BitField } from "./bitfield.ts" | import { BitField } from './bitfield.ts' | ||||||
| 
 | 
 | ||||||
| export type PermissionResolvable = string | number | Permissions | PermissionResolvable[] | export type PermissionResolvable = | ||||||
|  |   | string | ||||||
|  |   | number | ||||||
|  |   | Permissions | ||||||
|  |   | PermissionResolvable[] | ||||||
| 
 | 
 | ||||||
| export class Permissions extends BitField { | export class Permissions extends BitField { | ||||||
|   static DEFAULT = 104324673 |   static DEFAULT = 104324673 | ||||||
|  | @ -13,10 +17,16 @@ export class Permissions extends BitField { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(permission: PermissionResolvable, checkAdmin = true): boolean { |   any(permission: PermissionResolvable, checkAdmin = true): boolean { | ||||||
|     return (checkAdmin && super.has(this.flags.ADMINISTRATOR)) || super.any(permission as any) |     return ( | ||||||
|  |       (checkAdmin && super.has(this.flags.ADMINISTRATOR)) || | ||||||
|  |       super.any(permission as any) | ||||||
|  |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   has(permission: PermissionResolvable, checkAdmin = true): boolean { |   has(permission: PermissionResolvable, checkAdmin = true): boolean { | ||||||
|     return (checkAdmin && super.has(this.flags.ADMINISTRATOR)) || super.has(permission as any) |     return ( | ||||||
|  |       (checkAdmin && super.has(this.flags.ADMINISTRATOR)) || | ||||||
|  |       super.has(permission as any) | ||||||
|  |     ) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import { UserFlags } from "../types/userFlags.ts"; | import { UserFlags } from '../types/userFlags.ts' | ||||||
| import { BitField } from "./bitfield.ts"; | import { BitField } from './bitfield.ts' | ||||||
| 
 | 
 | ||||||
| export class UserFlagsManager extends BitField { | export class UserFlagsManager extends BitField { | ||||||
|   constructor(bits: any) { |   constructor(bits: any) { | ||||||
|  |  | ||||||
|  | @ -60,7 +60,7 @@ | ||||||
|     // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */ |     // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */ | ||||||
|     // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ |     // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||||||
|     /* Experimental Options */ |     /* Experimental Options */ | ||||||
|     "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */ |     "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, | ||||||
|     "emitDecoratorMetadata": false /* Enables experimental support for emitting type metadata for decorators. */, |     "emitDecoratorMetadata": false /* Enables experimental support for emitting type metadata for decorators. */, | ||||||
|     /* Advanced Options */ |     /* Advanced Options */ | ||||||
|     "skipLibCheck": true, |     "skipLibCheck": true, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue