Merge pull request #38 from DjDeveloperr/main
feat: Gateway Events, Webhooks, and other structures
This commit is contained in:
		
						commit
						214a1065ee
					
				
					 32 changed files with 1368 additions and 869 deletions
				
			
		
							
								
								
									
										17
									
								
								.vscode/settings.json
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								.vscode/settings.json
									
										
									
									
										vendored
									
									
								
							|  | @ -1,9 +1,10 @@ | ||||||
| { | { | ||||||
|   "deno.enable": true, |   "deno.enable": true, | ||||||
|   "deno.lint": false, |   "deno.lint": false, | ||||||
|   "deno.unstable": false, |   "deno.unstable": false, | ||||||
|   "deepscan.enable": true, |   "deepscan.enable": true, | ||||||
|   "deno.import_intellisense_origins": { |   "deno.import_intellisense_origins": { | ||||||
|     "https://deno.land": true |     "https://deno.land": true | ||||||
|   } |   }, | ||||||
|  |   "editor.tabSize": 2 | ||||||
| } | } | ||||||
							
								
								
									
										124
									
								
								mod.ts
									
										
									
									
									
								
							
							
						
						
									
										124
									
								
								mod.ts
									
										
									
									
									
								
							|  | @ -1,57 +1,67 @@ | ||||||
| export * from './src/gateway/index.ts' | export * from './src/gateway/index.ts' | ||||||
| export * from './src/models/client.ts' | export * from './src/models/client.ts' | ||||||
| export * from './src/models/rest.ts' | export * from './src/models/rest.ts' | ||||||
| export * from './src/models/cacheAdapter.ts' | export * from './src/models/cacheAdapter.ts' | ||||||
| export * from './src/models/shard.ts' | export * from './src/models/shard.ts' | ||||||
| export * from './src/models/command.ts' | export * from './src/models/command.ts' | ||||||
| export * from './src/models/commandClient.ts' | export * from './src/models/extensions.ts' | ||||||
| export * from './src/managers/base.ts' | export * from './src/models/commandClient.ts' | ||||||
| export * from './src/managers/baseChild.ts' | export * from './src/managers/base.ts' | ||||||
| export * from './src/managers/channels.ts' | export * from './src/managers/baseChild.ts' | ||||||
| export * from './src/managers/emojis.ts' | export * from './src/managers/channels.ts' | ||||||
| export * from './src/managers/gatewayCache.ts' | export * from './src/managers/emojis.ts' | ||||||
| export * from './src/managers/guildChannels.ts' | export * from './src/managers/gatewayCache.ts' | ||||||
| export * from './src/managers/guilds.ts' | export * from './src/managers/guildChannels.ts' | ||||||
| export * from './src/managers/members.ts' | export * from './src/managers/guilds.ts' | ||||||
| export * from './src/managers/messages.ts' | export * from './src/managers/guildChannels.ts' | ||||||
| export * from './src/managers/roles.ts' | export * from './src/managers/guildEmojis.ts' | ||||||
| export * from './src/managers/users.ts' | export * from './src/managers/members.ts' | ||||||
| export * from './src/structures/base.ts' | export * from './src/managers/messages.ts' | ||||||
| export * from './src/structures/cdn.ts' | export * from './src/managers/roles.ts' | ||||||
| export * from './src/structures/channel.ts' | export * from './src/managers/users.ts' | ||||||
| export * from './src/structures/dmChannel.ts' | export * from './src/structures/application.ts' | ||||||
| export * from './src/structures/embed.ts' | export * from './src/structures/base.ts' | ||||||
| export * from './src/structures/emoji.ts' | export * from './src/structures/cdn.ts' | ||||||
| export * from './src/structures/groupChannel.ts' | export * from './src/structures/channel.ts' | ||||||
| export * from './src/structures/guild.ts' | export * from './src/structures/dmChannel.ts' | ||||||
| export * from './src/structures/guildCategoryChannel.ts' | export * from './src/structures/embed.ts' | ||||||
| export * from './src/structures/guildNewsChannel.ts' | export * from './src/structures/emoji.ts' | ||||||
| export * from './src/structures/guildVoiceChannel.ts' | export * from './src/structures/groupChannel.ts' | ||||||
| export * from './src/structures/invite.ts' | export * from './src/structures/guild.ts' | ||||||
| export * from './src/structures/member.ts' | export * from './src/structures/guildCategoryChannel.ts' | ||||||
| export * from './src/structures/message.ts' | export * from './src/structures/guildNewsChannel.ts' | ||||||
| export * from './src/structures/messageMentions.ts' | export * from './src/structures/guildVoiceChannel.ts' | ||||||
| export * from './src/structures/presence.ts' | export * from './src/structures/invite.ts' | ||||||
| export * from './src/structures/role.ts' | export * from './src/structures/member.ts' | ||||||
| export * from './src/structures/snowflake.ts' | export * from './src/structures/message.ts' | ||||||
| export * from './src/structures/textChannel.ts' | export * from './src/structures/messageMentions.ts' | ||||||
| export * from './src/structures/user.ts' | export * from './src/structures/presence.ts' | ||||||
| export * from './src/structures/webhook.ts' | export * from './src/structures/role.ts' | ||||||
| export * from './src/types/cdn.ts' | export * from './src/structures/snowflake.ts' | ||||||
| export * from './src/types/channel.ts' | export * from './src/structures/textChannel.ts' | ||||||
| export * from './src/types/emoji.ts' | export * from './src/structures/user.ts' | ||||||
| export * from './src/types/endpoint.ts' | export * from './src/structures/webhook.ts' | ||||||
| export * from './src/types/gateway.ts' | export * from './src/types/application.ts' | ||||||
| export * from './src/types/gatewayBot.ts' | export * from './src/types/cdn.ts' | ||||||
| export * from './src/types/gatewayResponse.ts' | export * from './src/types/channel.ts' | ||||||
| export * from './src/types/guild.ts' | export * from './src/types/emoji.ts' | ||||||
| export * from './src/types/invite.ts' | export * from './src/types/endpoint.ts' | ||||||
| export * from './src/types/permissionFlags.ts' | export * from './src/types/gateway.ts' | ||||||
| export * from './src/types/presence.ts' | export * from './src/types/gatewayBot.ts' | ||||||
| export * from './src/types/role.ts' | export * from './src/types/gatewayResponse.ts' | ||||||
| export * from './src/types/template.ts' | export * from './src/types/guild.ts' | ||||||
| export * from './src/types/user.ts' | export * from './src/types/invite.ts' | ||||||
| export * from './src/types/voice.ts' | export * from './src/types/permissionFlags.ts' | ||||||
| export * from './src/types/webhook.ts' | export * from './src/types/presence.ts' | ||||||
| export * from './src/utils/collection.ts' | export * from './src/types/role.ts' | ||||||
| export * from './src/utils/intents.ts' | export * from './src/types/template.ts' | ||||||
|  | export * from './src/types/user.ts' | ||||||
|  | export * from './src/types/voice.ts' | ||||||
|  | export * from './src/types/webhook.ts' | ||||||
|  | export * from './src/utils/collection.ts' | ||||||
|  | export * from './src/utils/intents.ts' | ||||||
|  | export * from './src/utils/buildInfo.ts' | ||||||
|  | export * from './src/utils/permissions.ts' | ||||||
|  | export * from './src/utils/userFlags.ts' | ||||||
|  | export * from './src/utils/bitfield.ts' | ||||||
|  | export * from './src/utils/getChannelByType.ts' | ||||||
|  | @ -1,21 +1,21 @@ | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
| import { TextChannel } from '../../structures/textChannel.ts' | import { TextChannel } from '../../structures/textChannel.ts' | ||||||
| import { ChannelPinsUpdatePayload } from '../../types/gateway.ts' | import { ChannelPinsUpdatePayload } from '../../types/gateway.ts' | ||||||
| 
 | 
 | ||||||
| export const channelPinsUpdate: GatewayEventHandler = async ( | export const channelPinsUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|   d: ChannelPinsUpdatePayload |   d: ChannelPinsUpdatePayload | ||||||
| ) => { | ) => { | ||||||
|   const after: TextChannel | undefined = await gateway.client.channels.get<TextChannel>(d.channel_id) |   const after: TextChannel | 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( | ||||||
|       after.id, |       after.id, | ||||||
|       Object.assign(raw, { last_pin_timestamp: d.last_pin_timestamp }) |       Object.assign(raw, { last_pin_timestamp: d.last_pin_timestamp }) | ||||||
|     ) |     ) | ||||||
|     gateway.client.emit('channelPinsUpdate', before, after) |     gateway.client.emit('channelPinsUpdate', before, after) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,28 +1,21 @@ | ||||||
| import { Channel } from '../../structures/channel.ts' | import { Channel } from '../../structures/channel.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { ChannelPayload } from "../../types/channel.ts" | ||||||
| import { ChannelPayload, GuildChannelPayload } from '../../types/channel.ts' | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
| import getChannelByType from '../../utils/getChannelByType.ts' | 
 | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | export const channelUpdate: GatewayEventHandler = async ( | ||||||
| 
 |   gateway: Gateway, | ||||||
| export const channelUpdate: GatewayEventHandler = async ( |   d: ChannelPayload | ||||||
|   gateway: Gateway, | ) => { | ||||||
|   d: ChannelPayload |   const oldChannel: Channel | undefined = await gateway.client.channels.get(d.id) | ||||||
| ) => { |   await gateway.client.channels.set(d.id, d) | ||||||
|   const oldChannel: Channel | undefined = await gateway.client.channels.get(d.id) |   const newChannel: Channel = (await gateway.client.channels.get(d.id) as unknown) as Channel | ||||||
| 
 | 
 | ||||||
|   if (oldChannel !== undefined) { |   if (oldChannel !== undefined) { | ||||||
|     await gateway.client.channels.set(d.id, d) |     // (DjDeveloperr): Already done by ChannelsManager. I'll recheck later
 | ||||||
|     let guild: undefined | Guild; |     // if ('guild_id' in d) {
 | ||||||
|     if ('guild_id' in d) { |     //   // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
 | ||||||
|       // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
 |     //   (newChannel as GuildChannel).guild = await gateway.client.guilds.get((d as GuildChannelPayload).guild_id) as Guild
 | ||||||
|       guild = await gateway.client.guilds.get((d as GuildChannelPayload).guild_id) as Guild | undefined |     // }
 | ||||||
|     } |     gateway.client.emit('channelUpdate', oldChannel, newChannel) | ||||||
|     if (oldChannel.type !== d.type) { |   } else gateway.client.emit('channelUpdateUncached', newChannel) | ||||||
|       const channel: Channel = getChannelByType(gateway.client, d, guild) ?? oldChannel | } | ||||||
|       gateway.client.emit('channelUpdate', oldChannel, channel) |  | ||||||
|     } else { |  | ||||||
|       const before = oldChannel.refreshFromData(d) |  | ||||||
|       gateway.client.emit('channelUpdate', before, oldChannel) |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -1,53 +1,53 @@ | ||||||
| import { Emoji } from "../../structures/emoji.ts" | import { Emoji } from "../../structures/emoji.ts" | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { EmojiPayload } from "../../types/emoji.ts" | import { EmojiPayload } from "../../types/emoji.ts" | ||||||
| import { GuildEmojiUpdatePayload } from '../../types/gateway.ts' | import { GuildEmojiUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { Gateway, GatewayEventHandler } from '../index.ts' | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
| 
 | 
 | ||||||
| export const guildEmojiUpdate: GatewayEventHandler = async ( | export const guildEmojiUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|   d: GuildEmojiUpdatePayload |   d: GuildEmojiUpdatePayload | ||||||
| ) => { | ) => { | ||||||
|   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) |   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ||||||
|   if (guild !== undefined) { |   if (guild !== undefined) { | ||||||
|     const emojis = await guild.emojis.collection() |     const emojis = await guild.emojis.collection() | ||||||
|     const deleted: Emoji[] = [] |     const deleted: Emoji[] = [] | ||||||
|     const added: Emoji[] = [] |     const added: Emoji[] = [] | ||||||
|     const updated: Array<{ before: Emoji, after: Emoji }> = [] |     const updated: Array<{ before: Emoji, after: Emoji }> = [] | ||||||
|     const _updated: EmojiPayload[] = [] |     const _updated: EmojiPayload[] = [] | ||||||
| 
 | 
 | ||||||
|     for (const raw of d.emojis) { |     for (const raw of d.emojis) { | ||||||
|       const has = emojis.get(raw.id) |       const has = emojis.get(raw.id) | ||||||
|       if (has === undefined) { |       if (has === undefined) { | ||||||
|         await guild.emojis.set(raw.id, raw) |         await guild.emojis.set(raw.id, raw) | ||||||
|         const emoji = await guild.emojis.get(raw.id) as Emoji |         const emoji = await guild.emojis.get(raw.id) as Emoji | ||||||
|         added.push(emoji) |         added.push(emoji) | ||||||
|       } else _updated.push(raw) |       } else _updated.push(raw) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const emoji of emojis.values()) { |     for (const emoji of emojis.values()) { | ||||||
|       const find = _updated.find(e => emoji.id === e.id) |       const find = _updated.find(e => emoji.id === e.id) | ||||||
|       if (find === undefined) { |       if (find === undefined) { | ||||||
|         await guild.emojis.delete(emoji.id) |         await guild.emojis.delete(emoji.id) | ||||||
|         deleted.push(emoji) |         deleted.push(emoji) | ||||||
|       } else { |       } else { | ||||||
|         const before = await guild.emojis.get(find.id) as Emoji |         const before = await guild.emojis.get(find.id) as Emoji | ||||||
|         await guild.emojis.set(find.id, find) |         await guild.emojis.set(find.id, find) | ||||||
|         const after = await guild.emojis.get(find.id) as Emoji |         const after = await guild.emojis.get(find.id) as Emoji | ||||||
|         updated.push({ before, after }) |         updated.push({ before, after }) | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const emoji of deleted) { |     for (const emoji of deleted) { | ||||||
|       gateway.client.emit('guildEmojiDelete', emoji) |       gateway.client.emit('guildEmojiDelete', guild, emoji) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const emoji of added) { |     for (const emoji of added) { | ||||||
|       gateway.client.emit('guildEmojiAdd', emoji) |       gateway.client.emit('guildEmojiAdd', guild, emoji) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const emoji of updated) { |     for (const emoji of updated) { | ||||||
|       gateway.client.emit('guildEmojiUpdate', emoji.before, emoji.after) |       gateway.client.emit('guildEmojiUpdate', guild, emoji.before, emoji.after) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								src/gateway/handlers/guildIntegrationsUpdate.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/gateway/handlers/guildIntegrationsUpdate.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | ||||||
|  | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
|  | import { Guild } from '../../structures/guild.ts' | ||||||
|  | import { GuildIntegrationsUpdatePayload } from "../../types/gateway.ts" | ||||||
|  | 
 | ||||||
|  | export const guildIntegrationsUpdate: GatewayEventHandler = async ( | ||||||
|  |   gateway: Gateway, | ||||||
|  |   d: GuildIntegrationsUpdatePayload | ||||||
|  | ) => { | ||||||
|  |   console.log(d) | ||||||
|  |   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ||||||
|  |   if (guild === undefined) return | ||||||
|  | 
 | ||||||
|  |   gateway.client.emit('guildIntegrationsUpdate', guild) | ||||||
|  | } | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| 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 { GuildMemberAddPayload } from "../../../mod.ts" | import { GuildMemberAddPayload } from "../../types/gateway.ts" | ||||||
|  | import { Member } from "../../structures/member.ts" | ||||||
| 
 | 
 | ||||||
| export const guildMemberAdd: GatewayEventHandler = async ( | export const guildMemberAdd: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  | @ -11,6 +12,6 @@ export const guildMemberAdd: GatewayEventHandler = async ( | ||||||
|   if (guild === undefined) return |   if (guild === undefined) return | ||||||
| 
 | 
 | ||||||
|   await guild.members.set(d.user.id, d) |   await guild.members.set(d.user.id, d) | ||||||
|   const member = await guild.members.get(d.user.id) |   const member = await guild.members.get(d.user.id) as Member | ||||||
|   gateway.client.emit('guildMemberAdd', member) |   gateway.client.emit('guildMemberAdd', member) | ||||||
| } | } | ||||||
|  | @ -2,6 +2,7 @@ import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { GuildMemberUpdatePayload } from '../../types/gateway.ts' | import { GuildMemberUpdatePayload } from '../../types/gateway.ts' | ||||||
| import { MemberPayload } from '../../types/guild.ts' | import { MemberPayload } from '../../types/guild.ts' | ||||||
|  | import { Member } from "../../structures/member.ts" | ||||||
| 
 | 
 | ||||||
| export const guildMemberUpdate: GatewayEventHandler = async ( | export const guildMemberUpdate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  | @ -25,7 +26,7 @@ export const guildMemberUpdate: GatewayEventHandler = async ( | ||||||
|   const newMember = await guild.members.get(d.user.id) |   const newMember = await guild.members.get(d.user.id) | ||||||
| 
 | 
 | ||||||
|   if (member !== undefined) |   if (member !== undefined) | ||||||
|     gateway.client.emit('guildMemberRemove', member, newMember) |     gateway.client.emit('guildMemberUpdate', member, (newMember as unknown) as Member) | ||||||
|   else { |   else { | ||||||
|     gateway.client.emit('guildMemberUpdateUncached', newMember) |     gateway.client.emit('guildMemberUpdateUncached', newMember) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -1,16 +1,17 @@ | ||||||
| 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 { GuildRoleCreatePayload } from "../../types/gateway.ts" | import { GuildRoleCreatePayload } from "../../types/gateway.ts" | ||||||
| 
 | import { Role } from "../../structures/role.ts" | ||||||
| export const guildRoleCreate: GatewayEventHandler = async ( | 
 | ||||||
|   gateway: Gateway, | export const guildRoleCreate: GatewayEventHandler = async ( | ||||||
|   d: GuildRoleCreatePayload |   gateway: Gateway, | ||||||
| ) => { |   d: GuildRoleCreatePayload | ||||||
|   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ) => { | ||||||
|   // Weird case, shouldn't happen
 |   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ||||||
|   if (guild === undefined) return |   // Weird case, shouldn't happen
 | ||||||
| 
 |   if (guild === undefined) return | ||||||
|   await guild.roles.set(d.role.id, d.role) | 
 | ||||||
|   const role = await guild.roles.get(d.role.id) |   await guild.roles.set(d.role.id, d.role) | ||||||
|   gateway.client.emit('guildRoleCreate', role) |   const role = await guild.roles.get(d.role.id) | ||||||
|  |   gateway.client.emit('guildRoleCreate', (role as unknown) as Role) | ||||||
| } | } | ||||||
|  | @ -1,21 +1,22 @@ | ||||||
| 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 { GuildRoleUpdatePayload } from "../../types/gateway.ts" | import { GuildRoleUpdatePayload } from "../../types/gateway.ts" | ||||||
| 
 | import { Role } from "../../structures/role.ts" | ||||||
| export const guildRoleUpdate: GatewayEventHandler = async ( | 
 | ||||||
|   gateway: Gateway, | export const guildRoleUpdate: GatewayEventHandler = async ( | ||||||
|   d: GuildRoleUpdatePayload |   gateway: Gateway, | ||||||
| ) => { |   d: GuildRoleUpdatePayload | ||||||
|   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ) => { | ||||||
|   // Weird case, shouldn't happen
 |   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ||||||
|   if (guild === undefined) return |   // Weird case, shouldn't happen
 | ||||||
| 
 |   if (guild === undefined) return | ||||||
|   const role = await guild.roles.get(d.role.id) | 
 | ||||||
|   await guild.roles.set(d.role.id, d.role) |   const role = await guild.roles.get(d.role.id) | ||||||
|   const newRole = await guild.roles.get(d.role.id) |   await guild.roles.set(d.role.id, d.role) | ||||||
| 
 |   const newRole = await guild.roles.get(d.role.id) | ||||||
|   // Shouldn't happen either
 | 
 | ||||||
|   if(role === undefined) return gateway.client.emit('guildRoleUpdateUncached', newRole) |   // Shouldn't happen either
 | ||||||
| 
 |   if(role === undefined) return gateway.client.emit('guildRoleUpdateUncached', newRole) | ||||||
|   gateway.client.emit('guildRoleUpdate', role, newRole) | 
 | ||||||
|  |   gateway.client.emit('guildRoleUpdate', role, (newRole as unknown) as Role) | ||||||
| } | } | ||||||
|  | @ -1,65 +1,115 @@ | ||||||
| import { GatewayEventHandler } from '../index.ts' | import { GatewayEventHandler } from '../index.ts' | ||||||
| import { GatewayEvents } from '../../types/gateway.ts' | import { GatewayEvents, TypingStartGuildData } from '../../types/gateway.ts' | ||||||
| import { channelCreate } from './channelCreate.ts' | import { channelCreate } from './channelCreate.ts' | ||||||
| import { channelDelete } from './channelDelete.ts' | import { channelDelete } from './channelDelete.ts' | ||||||
| import { channelUpdate } from './channelUpdate.ts' | import { channelUpdate } from './channelUpdate.ts' | ||||||
| import { channelPinsUpdate } from './channelPinsUpdate.ts' | import { channelPinsUpdate } from './channelPinsUpdate.ts' | ||||||
| import { guildCreate } from './guildCreate.ts' | import { guildCreate } from './guildCreate.ts' | ||||||
| import { guildDelte as guildDelete } from './guildDelete.ts' | import { guildDelte as guildDelete } from './guildDelete.ts' | ||||||
| import { guildUpdate } from './guildUpdate.ts' | import { guildUpdate } from './guildUpdate.ts' | ||||||
| import { guildBanAdd } from './guildBanAdd.ts' | import { guildBanAdd } from './guildBanAdd.ts' | ||||||
| import { ready } from './ready.ts' | import { ready } from './ready.ts' | ||||||
| import { guildBanRemove } from './guildBanRemove.ts' | import { guildBanRemove } from './guildBanRemove.ts' | ||||||
| import { messageCreate } from './messageCreate.ts' | import { messageCreate } from './messageCreate.ts' | ||||||
| import { resume } from './resume.ts' | import { resume } from './resume.ts' | ||||||
| import { reconnect } from './reconnect.ts' | import { reconnect } from './reconnect.ts' | ||||||
| import { messageDelete } from "./messageDelete.ts" | import { messageDelete } from "./messageDelete.ts" | ||||||
| import { messageUpdate } from "./messageUpdate.ts" | import { messageUpdate } from "./messageUpdate.ts" | ||||||
| import { guildEmojiUpdate } from "./guildEmojiUpdate.ts" | import { guildEmojiUpdate } from "./guildEmojiUpdate.ts" | ||||||
| import { guildMemberAdd } from "./guildMemberAdd.ts" | import { guildMemberAdd } from "./guildMemberAdd.ts" | ||||||
| import { guildMemberRemove } from "./guildMemberRemove.ts" | import { guildMemberRemove } from "./guildMemberRemove.ts" | ||||||
| import { guildMemberUpdate } from "./guildMemberUpdate.ts" | import { guildMemberUpdate } from "./guildMemberUpdate.ts" | ||||||
| import { guildRoleCreate } from "./guildRoleCreate.ts" | import { guildRoleCreate } from "./guildRoleCreate.ts" | ||||||
| import { guildRoleDelete } from "./guildRoleDelete.ts" | import { guildRoleDelete } from "./guildRoleDelete.ts" | ||||||
| import { guildRoleUpdate } from "./guildRoleUpdate.ts" | import { guildRoleUpdate } from "./guildRoleUpdate.ts" | ||||||
| 
 | import { guildIntegrationsUpdate } from "./guildIntegrationsUpdate.ts" | ||||||
| export const gatewayHandlers: { | import { webhooksUpdate } from "./webhooksUpdate.ts" | ||||||
|   [eventCode in GatewayEvents]: GatewayEventHandler | undefined | import { messageDeleteBulk } from "./messageDeleteBulk.ts" | ||||||
| } = { | import { userUpdate } from "./userUpdate.ts" | ||||||
|   READY: ready, | import { typingStart } from "./typingStart.ts" | ||||||
|   RECONNECT: reconnect, | import { Channel } from "../../structures/channel.ts" | ||||||
|   RESUMED: resume, | import { GuildTextChannel, TextChannel } from "../../structures/textChannel.ts" | ||||||
|   CHANNEL_CREATE: channelCreate, | import { Guild } from "../../structures/guild.ts" | ||||||
|   CHANNEL_DELETE: channelDelete, | import { User } from "../../structures/user.ts" | ||||||
|   CHANNEL_UPDATE: channelUpdate, | import { Emoji } from "../../structures/emoji.ts" | ||||||
|   CHANNEL_PINS_UPDATE: channelPinsUpdate, | import { Member } from "../../structures/member.ts" | ||||||
|   GUILD_CREATE: guildCreate, | import { Role } from "../../structures/role.ts" | ||||||
|   GUILD_DELETE: guildDelete, | import { Message } from "../../structures/message.ts" | ||||||
|   GUILD_UPDATE: guildUpdate, | import { Collection } from "../../utils/collection.ts" | ||||||
|   GUILD_BAN_ADD: guildBanAdd, | 
 | ||||||
|   GUILD_BAN_REMOVE: guildBanRemove, | export const gatewayHandlers: { | ||||||
|   GUILD_EMOJIS_UPDATE: guildEmojiUpdate, |   [eventCode in GatewayEvents]: GatewayEventHandler | undefined | ||||||
|   GUILD_INTEGRATIONS_UPDATE: undefined, | } = { | ||||||
|   GUILD_MEMBER_ADD: guildMemberAdd, |   READY: ready, | ||||||
|   GUILD_MEMBER_REMOVE: guildMemberRemove, |   RECONNECT: reconnect, | ||||||
|   GUILD_MEMBER_UPDATE: guildMemberUpdate, |   RESUMED: resume, | ||||||
|   GUILD_MEMBERS_CHUNK: undefined, |   CHANNEL_CREATE: channelCreate, | ||||||
|   GUILD_ROLE_CREATE: guildRoleCreate, |   CHANNEL_DELETE: channelDelete, | ||||||
|   GUILD_ROLE_UPDATE: guildRoleUpdate, |   CHANNEL_UPDATE: channelUpdate, | ||||||
|   GUILD_ROLE_DELETE: guildRoleDelete, |   CHANNEL_PINS_UPDATE: channelPinsUpdate, | ||||||
|   INVITE_CREATE: undefined, |   GUILD_CREATE: guildCreate, | ||||||
|   INVITE_DELETE: undefined, |   GUILD_DELETE: guildDelete, | ||||||
|   MESSAGE_CREATE: messageCreate, |   GUILD_UPDATE: guildUpdate, | ||||||
|   MESSAGE_UPDATE: messageUpdate, |   GUILD_BAN_ADD: guildBanAdd, | ||||||
|   MESSAGE_DELETE: messageDelete, |   GUILD_BAN_REMOVE: guildBanRemove, | ||||||
|   MESSAGE_DELETE_BULK: undefined, |   GUILD_EMOJIS_UPDATE: guildEmojiUpdate, | ||||||
|   MESSAGE_REACTION_ADD: undefined, |   GUILD_INTEGRATIONS_UPDATE: guildIntegrationsUpdate, | ||||||
|   MESSAGE_REACTION_REMOVE: undefined, |   GUILD_MEMBER_ADD: guildMemberAdd, | ||||||
|   MESSAGE_REACTION_REMOVE_ALL: undefined, |   GUILD_MEMBER_REMOVE: guildMemberRemove, | ||||||
|   MESSAGE_REACTION_REMOVE_EMOJI: undefined, |   GUILD_MEMBER_UPDATE: guildMemberUpdate, | ||||||
|   PRESENCE_UPDATE: undefined, |   GUILD_MEMBERS_CHUNK: undefined, | ||||||
|   TYPING_START: undefined, |   GUILD_ROLE_CREATE: guildRoleCreate, | ||||||
|   USER_UPDATE: undefined, |   GUILD_ROLE_UPDATE: guildRoleUpdate, | ||||||
|   VOICE_SERVER_UPDATE: undefined, |   GUILD_ROLE_DELETE: guildRoleDelete, | ||||||
|   WEBHOOKS_UPDATE: undefined |   INVITE_CREATE: undefined, | ||||||
| } |   INVITE_DELETE: undefined, | ||||||
|  |   MESSAGE_CREATE: messageCreate, | ||||||
|  |   MESSAGE_UPDATE: messageUpdate, | ||||||
|  |   MESSAGE_DELETE: messageDelete, | ||||||
|  |   MESSAGE_DELETE_BULK: messageDeleteBulk, | ||||||
|  |   MESSAGE_REACTION_ADD: undefined, | ||||||
|  |   MESSAGE_REACTION_REMOVE: undefined, | ||||||
|  |   MESSAGE_REACTION_REMOVE_ALL: undefined, | ||||||
|  |   MESSAGE_REACTION_REMOVE_EMOJI: undefined, | ||||||
|  |   PRESENCE_UPDATE: undefined, | ||||||
|  |   TYPING_START: typingStart, | ||||||
|  |   USER_UPDATE: userUpdate, | ||||||
|  |   VOICE_SERVER_UPDATE: undefined, | ||||||
|  |   WEBHOOKS_UPDATE: webhooksUpdate | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface EventTypes { | ||||||
|  |   [name: string]: (...args: any[]) => void | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface ClientEvents extends EventTypes { | ||||||
|  |   'ready': () => void | ||||||
|  |   'reconnect': () => void | ||||||
|  |   'resumed': () => void | ||||||
|  |   'channelCreate': (channel: Channel) => void | ||||||
|  |   'channelDelete': (channel: Channel) => void | ||||||
|  |   'channelPinsUpdate': (before: TextChannel, after: TextChannel) => void | ||||||
|  |   'channelUpdate': (before: Channel, after: Channel) => void | ||||||
|  |   'guildBanAdd': (guild: Guild, user: User) => void | ||||||
|  |   'guildBanRemove': (guild: Guild, user: User) => void | ||||||
|  |   'guildCreate': (guild: Guild) => void | ||||||
|  |   'guildDelete': (guild: Guild) => void | ||||||
|  |   'guildEmojiAdd': (guild: Guild, emoji: Emoji) => void | ||||||
|  |   'guildEmojiDelete': (guild: Guild, emoji: Emoji) => void | ||||||
|  |   'guildEmojiUpdate': (guild: Guild, before: Emoji, after: Emoji) => void | ||||||
|  |   'guildIntegrationsUpdate': (guild: Guild) => void | ||||||
|  |   'guildMemberAdd': (member: Member) => void | ||||||
|  |   'guildMemberRemove': (member: Member) => void | ||||||
|  |   'guildMemberUpdate': (before: Member, after: Member) => void | ||||||
|  |   'guildRoleCreate': (role: Role) => void | ||||||
|  |   'guildRoleDelete': (role: Role) => void | ||||||
|  |   'guildRoleUpdate': (before: Role, after: Role) => void | ||||||
|  |   'guildUpdate': (before: Guild, after: Guild) => void | ||||||
|  |   'messageCreate': (message: Message) => void | ||||||
|  |   'messageDelete': (message: Message) => void | ||||||
|  |   'messageDeleteBulk': (channel: GuildTextChannel, messages: Collection<string, Message>, uncached: Set<string>) => void | ||||||
|  |   'messageUpdate': (before: Message, after: Message) => void | ||||||
|  |   'typingStart': (user: User, channel: TextChannel, at: Date, guildData?: TypingStartGuildData) => void | ||||||
|  |   'userUpdate': (before: User, after: User) => void | ||||||
|  |   'webhooksUpdate': (guild: Guild, channel: GuildTextChannel) => void | ||||||
|  | } | ||||||
							
								
								
									
										29
									
								
								src/gateway/handlers/messageDeleteBulk.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/gateway/handlers/messageDeleteBulk.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | ||||||
|  | import { Message } from "../../structures/message.ts" | ||||||
|  | import { GuildTextChannel } from '../../structures/textChannel.ts' | ||||||
|  | import { MessageDeleteBulkPayload } from "../../types/gateway.ts" | ||||||
|  | import { Collection } from "../../utils/collection.ts" | ||||||
|  | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
|  | 
 | ||||||
|  | export const messageDeleteBulk: GatewayEventHandler = async ( | ||||||
|  |   gateway: Gateway, | ||||||
|  |   d: MessageDeleteBulkPayload | ||||||
|  | ) => { | ||||||
|  |   let channel = await gateway.client.channels.get<GuildTextChannel>(d.channel_id) | ||||||
|  |   // Fetch the channel if not cached
 | ||||||
|  |   if (channel === undefined) | ||||||
|  |     // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
 | ||||||
|  |     channel = (await gateway.client.channels.fetch(d.channel_id)) as GuildTextChannel | ||||||
|  | 
 | ||||||
|  |   const messages = new Collection<string, Message>() | ||||||
|  |   const uncached = new Set<string>() | ||||||
|  |   for (const id of d.ids) { | ||||||
|  |     const message = await channel.messages.get(id) | ||||||
|  |     if (message === undefined) uncached.add(id) | ||||||
|  |     else { | ||||||
|  |       messages.set(id, message) | ||||||
|  |       await channel.messages.delete(id) | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   gateway.client.emit('messageDeleteBulk', channel, messages, uncached) | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								src/gateway/handlers/typingStart.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/gateway/handlers/typingStart.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | ||||||
|  | import { Member } from "../../structures/member.ts" | ||||||
|  | import { TextChannel } from "../../structures/textChannel.ts" | ||||||
|  | import { TypingStartPayload } from "../../types/gateway.ts" | ||||||
|  | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
|  | 
 | ||||||
|  | // TODO: Do we need to add uncached events here?
 | ||||||
|  | export const typingStart: GatewayEventHandler = async ( | ||||||
|  |   gateway: Gateway, | ||||||
|  |   d: TypingStartPayload | ||||||
|  | ) => { | ||||||
|  |   const user = await gateway.client.users.get(d.user_id) | ||||||
|  |   if (user === undefined) return console.log('user not cached') | ||||||
|  | 
 | ||||||
|  |   const channel = await gateway.client.channels.get(d.channel_id) | ||||||
|  |   if (channel === undefined) return console.log(`channel not cached`) | ||||||
|  | 
 | ||||||
|  |   const guild = d.guild_id !== undefined ? await gateway.client.guilds.get(d.guild_id) : undefined | ||||||
|  |   if(guild === undefined && d.guild_id !== undefined) return console.log('guild not cached') | ||||||
|  | 
 | ||||||
|  |   const member = d.member !== undefined && guild !== undefined ? new Member(gateway.client, d.member, user, guild) : undefined | ||||||
|  | 
 | ||||||
|  |   gateway.client.emit('typingStart', user, (channel as unknown) as TextChannel, new Date(d.timestamp), guild !== undefined && member !== undefined ? { guild, member } : undefined) | ||||||
|  | } | ||||||
							
								
								
									
										16
									
								
								src/gateway/handlers/userUpdate.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/gateway/handlers/userUpdate.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | ||||||
|  | import { User } from "../../structures/user.ts" | ||||||
|  | import { UserPayload } from "../../types/user.ts" | ||||||
|  | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
|  | 
 | ||||||
|  | export const userUpdate: GatewayEventHandler = async ( | ||||||
|  |   gateway: Gateway, | ||||||
|  |   d: UserPayload | ||||||
|  | ) => { | ||||||
|  |   const oldUser: User | undefined = await gateway.client.users.get(d.id) | ||||||
|  |   await gateway.client.users.set(d.id, d) | ||||||
|  |   const newUser: User = (await gateway.client.users.get(d.id) as unknown) as User | ||||||
|  | 
 | ||||||
|  |   if (oldUser !== undefined) { | ||||||
|  |     gateway.client.emit('userUpdate', oldUser, newUser) | ||||||
|  |   } else gateway.client.emit('userUpdateUncached', newUser) | ||||||
|  | } | ||||||
							
								
								
									
										16
									
								
								src/gateway/handlers/webhooksUpdate.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/gateway/handlers/webhooksUpdate.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | ||||||
|  | import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
|  | import { Guild } from '../../structures/guild.ts' | ||||||
|  | import { WebhooksUpdatePayload } from "../../types/gateway.ts" | ||||||
|  | import { GuildTextChannel } from "../../structures/textChannel.ts" | ||||||
|  | 
 | ||||||
|  | export const webhooksUpdate: GatewayEventHandler = async ( | ||||||
|  |   gateway: Gateway, | ||||||
|  |   d: WebhooksUpdatePayload | ||||||
|  | ) => { | ||||||
|  |   const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) | ||||||
|  |   if (guild === undefined) return | ||||||
|  | 
 | ||||||
|  |   const channel: GuildTextChannel | undefined = await guild.channels.get(d.channel_id) as GuildTextChannel | ||||||
|  |   if (channel === undefined) gateway.client.emit('webhooksUpdateUncached', guild, d.channel_id) | ||||||
|  |   else gateway.client.emit('webhooksUpdate', guild, channel) | ||||||
|  | } | ||||||
|  | @ -43,7 +43,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> { | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async fetch (id: string): Promise<Channel> { |   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)) | ||||||
|  | @ -53,7 +53,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> { | ||||||
|           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)) |           resolve((getChannelByType(this.client, data as ChannelPayload, guild) as unknown) as T) | ||||||
|         }) |         }) | ||||||
|         .catch(e => reject(e)) |         .catch(e => reject(e)) | ||||||
|     }) |     }) | ||||||
|  |  | ||||||
|  | @ -20,7 +20,6 @@ export class GatewayCache { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async delete (key: string): Promise<boolean> { |   async delete (key: string): Promise<boolean> { | ||||||
|     console.log(`[GatewayCache] DEL ${key}`) |  | ||||||
|     const result = await this.client.cache.delete(this.cacheName, key) |     const result = await this.client.cache.delete(this.cacheName, key) | ||||||
|     return result |     return result | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -12,6 +12,8 @@ import { | ||||||
| } from '../structures/presence.ts' | } 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 { Application } from "../../mod.ts"
 | ||||||
| 
 | 
 | ||||||
| /** Some Client Options to modify behaviour */ | /** Some Client Options to modify behaviour */ | ||||||
| export interface ClientOptions { | export interface ClientOptions { | ||||||
|  | @ -33,6 +35,17 @@ export interface ClientOptions { | ||||||
|   messageCacheLifetime?: number |   messageCacheLifetime?: number | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export declare interface Client { | ||||||
|  |   on: <U extends string>( | ||||||
|  |     event: U, listener: ClientEvents[U] | ||||||
|  |   ) => this | ||||||
|  | 
 | ||||||
|  |   emit: <U extends string>( | ||||||
|  |     event: U, ...args: Parameters<ClientEvents[U]> | ||||||
|  |   ) => boolean | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Discord Client. |  * Discord Client. | ||||||
|  */ |  */ | ||||||
|  | @ -103,6 +116,9 @@ export class Client extends EventEmitter { | ||||||
|     this.emit('debug', `[${tag}] ${msg}`) |     this.emit('debug', `[${tag}] ${msg}`) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   // TODO(DjDeveloperr): Implement this
 | ||||||
|  |   // fetchApplication(): Promise<Application>
 | ||||||
|  | 
 | ||||||
|   /** |   /** | ||||||
|    * This function is used for connect to discord. |    * This function is used for connect to discord. | ||||||
|    * @param token Your token. This is required. |    * @param token Your token. This is required. | ||||||
|  |  | ||||||
|  | @ -1,4 +1,3 @@ | ||||||
| import { delay } from '../utils/index.ts' |  | ||||||
| import * as baseEndpoints from '../consts/urlsAndVersions.ts' | import * as baseEndpoints from '../consts/urlsAndVersions.ts' | ||||||
| import { Client } from './client.ts' | import { Client } from './client.ts' | ||||||
| import { getBuildInfo } from '../utils/buildInfo.ts' | import { getBuildInfo } from '../utils/buildInfo.ts' | ||||||
|  | @ -45,13 +44,13 @@ export interface RateLimit { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class RESTManager { | export class RESTManager { | ||||||
|   client: Client |   client?: Client | ||||||
|   queues: { [key: string]: QueuedItem[] } = {} |   queues: { [key: string]: QueuedItem[] } = {} | ||||||
|   rateLimits = new Collection<string, RateLimit>() |   rateLimits = new Collection<string, RateLimit>() | ||||||
|   globalRateLimit: boolean = false |   globalRateLimit: boolean = false | ||||||
|   processing: boolean = false |   processing: boolean = false | ||||||
| 
 | 
 | ||||||
|   constructor(client: Client) { |   constructor(client?: Client) { | ||||||
|     this.client = client |     this.client = client | ||||||
|     // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |     // eslint-disable-next-line @typescript-eslint/no-floating-promises
 | ||||||
|     this.handleRateLimits() |     this.handleRateLimits() | ||||||
|  | @ -125,7 +124,7 @@ export class RESTManager { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (Object.keys(this.queues).length !== 0) { |     if (Object.keys(this.queues).length !== 0) { | ||||||
|       await delay(1000) |       // await delay(100)
 | ||||||
|       // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |       // eslint-disable-next-line @typescript-eslint/no-floating-promises
 | ||||||
|       this.processQueue() |       this.processQueue() | ||||||
|       // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |       // eslint-disable-next-line @typescript-eslint/no-floating-promises
 | ||||||
|  | @ -139,11 +138,12 @@ export class RESTManager { | ||||||
|   ): { [key: string]: any } { |   ): { [key: string]: any } { | ||||||
| 
 | 
 | ||||||
|     const headers: RequestHeaders = { |     const headers: RequestHeaders = { | ||||||
|       'Authorization': `Bot ${this.client.token}`, |  | ||||||
|       'User-Agent': `DiscordBot (harmony, https://github.com/harmony-org/harmony)` |       'User-Agent': `DiscordBot (harmony, https://github.com/harmony-org/harmony)` | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.client.token === undefined) delete headers.Authorization |     if (this.client !== undefined) headers.Authorization = `Bot ${this.client.token}` | ||||||
|  | 
 | ||||||
|  |     if (this.client?.token === undefined) delete headers.Authorization | ||||||
| 
 | 
 | ||||||
|     if (method === 'get' || method === 'head' || method === 'delete') body = undefined |     if (method === 'get' || method === 'head' || method === 'delete') body = undefined | ||||||
| 
 | 
 | ||||||
|  | @ -166,7 +166,7 @@ export class RESTManager { | ||||||
|       method: method.toUpperCase() |       method: method.toUpperCase() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.client.bot === false) { |     if (this.client?.bot === false) { | ||||||
|       // This is a selfbot. Use requests similar to Discord Client
 |       // This is a selfbot. Use requests similar to Discord Client
 | ||||||
|       data.headers.authorization = this.client.token as string |       data.headers.authorization = this.client.token as string | ||||||
|       data.headers['accept-language'] = 'en-US' |       data.headers['accept-language'] = 'en-US' | ||||||
|  | @ -259,7 +259,7 @@ export class RESTManager { | ||||||
| 
 | 
 | ||||||
|     if ( |     if ( | ||||||
|       (status >= 200 && status < 400) |       (status >= 200 && status < 400) | ||||||
|       || status === HttpResponseCode.NoContent  |       || status === HttpResponseCode.NoContent | ||||||
|       || status === HttpResponseCode.TooManyRequests |       || status === HttpResponseCode.TooManyRequests | ||||||
|     ) return |     ) return | ||||||
| 
 | 
 | ||||||
|  | @ -290,7 +290,8 @@ export class RESTManager { | ||||||
|     url: string, |     url: string, | ||||||
|     body?: unknown, |     body?: unknown, | ||||||
|     maxRetries = 0, |     maxRetries = 0, | ||||||
|     bucket?: string | null |     bucket?: string | null, | ||||||
|  |     rawResponse?: boolean, | ||||||
|   ): Promise<any> { |   ): Promise<any> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       const onComplete = async (): Promise<undefined | any> => { |       const onComplete = async (): Promise<undefined | any> => { | ||||||
|  | @ -318,7 +319,7 @@ export class RESTManager { | ||||||
|           let urlToUse = |           let urlToUse = | ||||||
|             method === 'get' && query !== '' ? `${url}?${query}` : url |             method === 'get' && query !== '' ? `${url}?${query}` : url | ||||||
| 
 | 
 | ||||||
|           if (this.client.canary === true) { |           if (this.client?.canary === true) { | ||||||
|             const split = urlToUse.split('//') |             const split = urlToUse.split('//') | ||||||
|             urlToUse = split[0] + '//canary.' + split[1] |             urlToUse = split[0] + '//canary.' + split[1] | ||||||
|           } |           } | ||||||
|  | @ -328,7 +329,7 @@ export class RESTManager { | ||||||
|           const response = await fetch(urlToUse, requestData) |           const response = await fetch(urlToUse, requestData) | ||||||
|           const bucketFromHeaders = this.processHeaders(url, response.headers) |           const bucketFromHeaders = this.processHeaders(url, response.headers) | ||||||
| 
 | 
 | ||||||
|           if (response.status === 204) return resolve(undefined) |           if (response.status === 204) return resolve(rawResponse === true ? { response, body: null } : undefined) | ||||||
| 
 | 
 | ||||||
|           const json: any = await response.json() |           const json: any = await response.json() | ||||||
|           await this.handleStatusCode(response, json, requestData) |           await this.handleStatusCode(response, json, requestData) | ||||||
|  | @ -347,7 +348,7 @@ export class RESTManager { | ||||||
|               bucket: bucketFromHeaders |               bucket: bucketFromHeaders | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|           return resolve(json) |           return resolve(rawResponse === true ? { response, body: json } : json) | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|           return reject(error) |           return reject(error) | ||||||
|         } |         } | ||||||
|  | @ -375,23 +376,23 @@ export class RESTManager { | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async get(url: string, body?: unknown): Promise<any> { |   async get(url: string, body?: unknown, maxRetries = 0, bucket?: string | null, rawResponse?: boolean): Promise<any> { | ||||||
|     return await this.make('get', url, body) |     return await this.make('get', url, body, maxRetries, bucket, rawResponse) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async post(url: string, body?: unknown): Promise<any> { |   async post(url: string, body?: unknown, maxRetries = 0, bucket?: string | null, rawResponse?: boolean): Promise<any> { | ||||||
|     return await this.make('post', url, body) |     return await this.make('post', url, body, maxRetries, bucket, rawResponse) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async delete(url: string, body?: unknown): Promise<any> { |   async delete(url: string, body?: unknown, maxRetries = 0, bucket?: string | null, rawResponse?: boolean): Promise<any> { | ||||||
|     return await this.make('delete', url, body) |     return await this.make('delete', url, body, maxRetries, bucket, rawResponse) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async patch(url: string, body?: unknown): Promise<any> { |   async patch(url: string, body?: unknown, maxRetries = 0, bucket?: string | null, rawResponse?: boolean): Promise<any> { | ||||||
|     return await this.make('patch', url, body) |     return await this.make('patch', url, body, maxRetries, bucket, rawResponse) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async put(url: string, body?: unknown): Promise<any> { |   async put(url: string, body?: unknown, maxRetries = 0, bucket?: string | null, rawResponse?: boolean): Promise<any> { | ||||||
|     return await this.make('put', url, body) |     return await this.make('put', url, body, maxRetries, bucket, rawResponse) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/models/voice.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/models/voice.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | ||||||
|  | import { Client } from './client.ts' | ||||||
|  | 
 | ||||||
|  | export class VoiceClient { | ||||||
|  |   client: Client | ||||||
|  | 
 | ||||||
|  |   constructor(client: Client) { | ||||||
|  |     this.client = client | ||||||
|  |      | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										24
									
								
								src/structures/application.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/structures/application.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | ||||||
|  | import { Client } from "../models/client.ts"; | ||||||
|  | import { ApplicationPayload } from "../types/application.ts"; | ||||||
|  | import { Base } from "./base.ts"; | ||||||
|  | import { User } from "./user.ts"; | ||||||
|  | 
 | ||||||
|  | export class Application extends Base { | ||||||
|  |   id: string | ||||||
|  |   name: string | ||||||
|  |   icon: string | ||||||
|  |   description: string | ||||||
|  |   summary: string | ||||||
|  |   bot?: User | ||||||
|  | 
 | ||||||
|  |   constructor(client: Client, data: ApplicationPayload) { | ||||||
|  |     super(client, data) | ||||||
|  | 
 | ||||||
|  |     this.id = data.id | ||||||
|  |     this.name = data.name | ||||||
|  |     this.icon = data.icon | ||||||
|  |     this.description = data.description | ||||||
|  |     this.summary = data.summary | ||||||
|  |     this.bot = data.bot !== undefined ? new User(client, data.bot) : undefined | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -1,224 +1,270 @@ | ||||||
| import { Client } from '../models/client.ts' | import { Client } from '../models/client.ts' | ||||||
| import { GuildFeatures, GuildPayload } from '../types/guild.ts' | import { GuildFeatures, GuildIntegrationPayload, GuildPayload, IntegrationAccountPayload, IntegrationExpireBehavior } from '../types/guild.ts' | ||||||
| import { PresenceUpdatePayload } from '../types/gateway.ts' | import { PresenceUpdatePayload } from '../types/gateway.ts' | ||||||
| import { Base } from './base.ts' | import { Base } from './base.ts' | ||||||
| import { VoiceState } from './voiceState.ts' | import { VoiceState } from './voiceState.ts' | ||||||
| import { RolesManager } from '../managers/roles.ts' | import { RolesManager } from '../managers/roles.ts' | ||||||
| import { GuildChannelsManager } from '../managers/guildChannels.ts' | import { GuildChannelsManager } from '../managers/guildChannels.ts' | ||||||
| import { MembersManager } from '../managers/members.ts' | import { MembersManager } from '../managers/members.ts' | ||||||
| import { Role } from './role.ts' | import { Role } from './role.ts' | ||||||
| import { GuildEmojisManager } from '../managers/guildEmojis.ts' | import { GuildEmojisManager } from '../managers/guildEmojis.ts' | ||||||
| import { Member } from "./member.ts" | import { Member } from "./member.ts" | ||||||
| 
 | import { User } from "./user.ts" | ||||||
| export class Guild extends Base { | import { Application } from "./application.ts" | ||||||
|   id: string | import { GUILD_INTEGRATIONS } from "../types/endpoint.ts" | ||||||
|   name?: string | 
 | ||||||
|   icon?: string | export class Guild extends Base { | ||||||
|   iconHash?: string |   id: string | ||||||
|   splash?: string |   name?: string | ||||||
|   discoverySplash?: string |   icon?: string | ||||||
|   owner?: boolean |   iconHash?: string | ||||||
|   ownerID?: string |   splash?: string | ||||||
|   permissions?: string |   discoverySplash?: string | ||||||
|   region?: string |   owner?: boolean | ||||||
|   afkChannelID?: string |   ownerID?: string | ||||||
|   afkTimeout?: number |   permissions?: string | ||||||
|   widgetEnabled?: boolean |   region?: string | ||||||
|   widgetChannelID?: string |   afkChannelID?: string | ||||||
|   verificationLevel?: string |   afkTimeout?: number | ||||||
|   defaultMessageNotifications?: string |   widgetEnabled?: boolean | ||||||
|   explicitContentFilter?: string |   widgetChannelID?: string | ||||||
|   roles: RolesManager |   verificationLevel?: string | ||||||
|   emojis: GuildEmojisManager |   defaultMessageNotifications?: string | ||||||
|   features?: GuildFeatures[] |   explicitContentFilter?: string | ||||||
|   mfaLevel?: string |   roles: RolesManager | ||||||
|   applicationID?: string |   emojis: GuildEmojisManager | ||||||
|   systemChannelID?: string |   features?: GuildFeatures[] | ||||||
|   systemChannelFlags?: string |   mfaLevel?: string | ||||||
|   rulesChannelID?: string |   applicationID?: string | ||||||
|   joinedAt?: string |   systemChannelID?: string | ||||||
|   large?: boolean |   systemChannelFlags?: string | ||||||
|   unavailable: boolean |   rulesChannelID?: string | ||||||
|   memberCount?: number |   joinedAt?: string | ||||||
|   voiceStates?: VoiceState[] |   large?: boolean | ||||||
|   members: MembersManager |   unavailable: boolean | ||||||
|   channels: GuildChannelsManager |   memberCount?: number | ||||||
|   presences?: PresenceUpdatePayload[] |   voiceStates?: VoiceState[] | ||||||
|   maxPresences?: number |   members: MembersManager | ||||||
|   maxMembers?: number |   channels: GuildChannelsManager | ||||||
|   vanityURLCode?: string |   presences?: PresenceUpdatePayload[] | ||||||
|   description?: string |   maxPresences?: number | ||||||
|   banner?: string |   maxMembers?: number | ||||||
|   premiumTier?: number |   vanityURLCode?: string | ||||||
|   premiumSubscriptionCount?: number |   description?: string | ||||||
|   preferredLocale?: string |   banner?: string | ||||||
|   publicUpdatesChannelID?: string |   premiumTier?: number | ||||||
|   maxVideoChannelUsers?: number |   premiumSubscriptionCount?: number | ||||||
|   approximateNumberCount?: number |   preferredLocale?: string | ||||||
|   approximatePresenceCount?: number |   publicUpdatesChannelID?: string | ||||||
| 
 |   maxVideoChannelUsers?: number | ||||||
|   constructor (client: Client, data: GuildPayload) { |   approximateNumberCount?: number | ||||||
|     super(client, data) |   approximatePresenceCount?: number | ||||||
|     this.id = data.id | 
 | ||||||
|     this.unavailable = data.unavailable |   constructor (client: Client, data: GuildPayload) { | ||||||
|     this.members = new MembersManager(this.client, this) |     super(client, data) | ||||||
|     this.channels = new GuildChannelsManager( |     this.id = data.id | ||||||
|       this.client,  |     this.unavailable = data.unavailable | ||||||
|       this.client.channels,  |     this.members = new MembersManager(this.client, this) | ||||||
|       this |     this.channels = new GuildChannelsManager( | ||||||
|     ) |       this.client,  | ||||||
|     this.roles = new RolesManager(this.client, this) |       this.client.channels,  | ||||||
|     this.emojis = new GuildEmojisManager(this.client, this.client.emojis, this) |       this | ||||||
| 
 |     ) | ||||||
|     if (!this.unavailable) { |     this.roles = new RolesManager(this.client, this) | ||||||
|       this.name = data.name |     this.emojis = new GuildEmojisManager(this.client, this.client.emojis, this) | ||||||
|       this.icon = data.icon | 
 | ||||||
|       this.iconHash = data.icon_hash |     if (!this.unavailable) { | ||||||
|       this.splash = data.splash |       this.name = data.name | ||||||
|       this.discoverySplash = data.discovery_splash |       this.icon = data.icon | ||||||
|       this.owner = data.owner |       this.iconHash = data.icon_hash | ||||||
|       this.ownerID = data.owner_id |       this.splash = data.splash | ||||||
|       this.permissions = data.permissions |       this.discoverySplash = data.discovery_splash | ||||||
|       this.region = data.region |       this.owner = data.owner | ||||||
|       this.afkTimeout = data.afk_timeout |       this.ownerID = data.owner_id | ||||||
|       this.afkChannelID = data.afk_channel_id |       this.permissions = data.permissions | ||||||
|       this.widgetEnabled = data.widget_enabled |       this.region = data.region | ||||||
|       this.widgetChannelID = data.widget_channel_id |       this.afkTimeout = data.afk_timeout | ||||||
|       this.verificationLevel = data.verification_level |       this.afkChannelID = data.afk_channel_id | ||||||
|       this.defaultMessageNotifications = data.default_message_notifications |       this.widgetEnabled = data.widget_enabled | ||||||
|       this.explicitContentFilter = data.explicit_content_filter |       this.widgetChannelID = data.widget_channel_id | ||||||
|       // this.roles = data.roles.map(
 |       this.verificationLevel = data.verification_level | ||||||
|       //   v => cache.get('role', v.id) ?? new Role(client, v)
 |       this.defaultMessageNotifications = data.default_message_notifications | ||||||
|       // )
 |       this.explicitContentFilter = data.explicit_content_filter | ||||||
|       // data.roles.forEach(role => {
 |       // this.roles = data.roles.map(
 | ||||||
|       //   this.roles.set(role.id, new Role(client, role))
 |       //   v => cache.get('role', v.id) ?? new Role(client, v)
 | ||||||
|       // })
 |       // )
 | ||||||
|       // this.emojis = data.emojis.map(
 |       // data.roles.forEach(role => {
 | ||||||
|       //   v => cache.get('emoji', v.id) ?? new Emoji(client, v)
 |       //   this.roles.set(role.id, new Role(client, role))
 | ||||||
|       // )
 |       // })
 | ||||||
|       this.features = data.features |       // this.emojis = data.emojis.map(
 | ||||||
|       this.mfaLevel = data.mfa_level |       //   v => cache.get('emoji', v.id) ?? new Emoji(client, v)
 | ||||||
|       this.systemChannelID = data.system_channel_id |       // )
 | ||||||
|       this.systemChannelFlags = data.system_channel_flags |       this.features = data.features | ||||||
|       this.rulesChannelID = data.rules_channel_id |       this.mfaLevel = data.mfa_level | ||||||
|       this.joinedAt = data.joined_at |       this.systemChannelID = data.system_channel_id | ||||||
|       this.large = data.large |       this.systemChannelFlags = data.system_channel_flags | ||||||
|       this.memberCount = data.member_count |       this.rulesChannelID = data.rules_channel_id | ||||||
|       // TODO: Cache in Gateway Event code
 |       this.joinedAt = data.joined_at | ||||||
|       // this.voiceStates = data.voice_states?.map(
 |       this.large = data.large | ||||||
|       //   v =>
 |       this.memberCount = data.member_count | ||||||
|       //     cache.get('voiceState', `${v.guild_id}:${v.user_id}`) ??
 |       // TODO: Cache in Gateway Event code
 | ||||||
|       //     new VoiceState(client, v)
 |       // this.voiceStates = data.voice_states?.map(
 | ||||||
|       // )
 |       //   v =>
 | ||||||
|       // this.members = data.members?.map(
 |       //     cache.get('voiceState', `${v.guild_id}:${v.user_id}`) ??
 | ||||||
|       //   v =>
 |       //     new VoiceState(client, v)
 | ||||||
|       //     cache.get('member', `${this.id}:${v.user.id}`) ??
 |       // )
 | ||||||
|       //     new Member(client, v)
 |       // this.members = data.members?.map(
 | ||||||
|       // )
 |       //   v =>
 | ||||||
|       // this.channels = data.channels?.map(
 |       //     cache.get('member', `${this.id}:${v.user.id}`) ??
 | ||||||
|       //   v => cache.get('channel', v.id) ?? getChannelByType(this.client, v)
 |       //     new Member(client, v)
 | ||||||
|       // )
 |       // )
 | ||||||
|       this.presences = data.presences |       // this.channels = data.channels?.map(
 | ||||||
|       this.maxPresences = data.max_presences |       //   v => cache.get('channel', v.id) ?? getChannelByType(this.client, v)
 | ||||||
|       this.maxMembers = data.max_members |       // )
 | ||||||
|       this.vanityURLCode = data.vanity_url_code |       this.presences = data.presences | ||||||
|       this.description = data.description |       this.maxPresences = data.max_presences | ||||||
|       this.banner = data.banner |       this.maxMembers = data.max_members | ||||||
|       this.premiumTier = data.premium_tier |       this.vanityURLCode = data.vanity_url_code | ||||||
|       this.premiumSubscriptionCount = data.premium_subscription_count |       this.description = data.description | ||||||
|       this.preferredLocale = data.preferred_locale |       this.banner = data.banner | ||||||
|       this.publicUpdatesChannelID = data.public_updates_channel_id |       this.premiumTier = data.premium_tier | ||||||
|       this.maxVideoChannelUsers = data.max_video_channel_users |       this.premiumSubscriptionCount = data.premium_subscription_count | ||||||
|       this.approximateNumberCount = data.approximate_number_count |       this.preferredLocale = data.preferred_locale | ||||||
|       this.approximatePresenceCount = data.approximate_presence_count |       this.publicUpdatesChannelID = data.public_updates_channel_id | ||||||
|     } |       this.maxVideoChannelUsers = data.max_video_channel_users | ||||||
|   } |       this.approximateNumberCount = data.approximate_number_count | ||||||
| 
 |       this.approximatePresenceCount = data.approximate_presence_count | ||||||
|   protected readFromData (data: GuildPayload): void { |     } | ||||||
|     super.readFromData(data) |   } | ||||||
|     this.id = data.id ?? this.id | 
 | ||||||
|     this.unavailable = data.unavailable ?? this.unavailable |   protected readFromData (data: GuildPayload): void { | ||||||
| 
 |     super.readFromData(data) | ||||||
|     if (!this.unavailable) { |     this.id = data.id ?? this.id | ||||||
|       this.name = data.name ?? this.name |     this.unavailable = data.unavailable ?? this.unavailable | ||||||
|       this.icon = data.icon ?? this.icon | 
 | ||||||
|       this.iconHash = data.icon_hash ?? this.iconHash |     if (!this.unavailable) { | ||||||
|       this.splash = data.splash ?? this.splash |       this.name = data.name ?? this.name | ||||||
|       this.discoverySplash = data.discovery_splash ?? this.discoverySplash |       this.icon = data.icon ?? this.icon | ||||||
|       this.owner = data.owner ?? this.owner |       this.iconHash = data.icon_hash ?? this.iconHash | ||||||
|       this.ownerID = data.owner_id ?? this.ownerID |       this.splash = data.splash ?? this.splash | ||||||
|       this.permissions = data.permissions ?? this.permissions |       this.discoverySplash = data.discovery_splash ?? this.discoverySplash | ||||||
|       this.region = data.region ?? this.region |       this.owner = data.owner ?? this.owner | ||||||
|       this.afkTimeout = data.afk_timeout ?? this.afkTimeout |       this.ownerID = data.owner_id ?? this.ownerID | ||||||
|       this.afkChannelID = data.afk_channel_id ?? this.afkChannelID |       this.permissions = data.permissions ?? this.permissions | ||||||
|       this.widgetEnabled = data.widget_enabled ?? this.widgetEnabled |       this.region = data.region ?? this.region | ||||||
|       this.widgetChannelID = data.widget_channel_id ?? this.widgetChannelID |       this.afkTimeout = data.afk_timeout ?? this.afkTimeout | ||||||
|       this.verificationLevel = data.verification_level ?? this.verificationLevel |       this.afkChannelID = data.afk_channel_id ?? this.afkChannelID | ||||||
|       this.defaultMessageNotifications = |       this.widgetEnabled = data.widget_enabled ?? this.widgetEnabled | ||||||
|         data.default_message_notifications ?? this.defaultMessageNotifications |       this.widgetChannelID = data.widget_channel_id ?? this.widgetChannelID | ||||||
|       this.explicitContentFilter = |       this.verificationLevel = data.verification_level ?? this.verificationLevel | ||||||
|         data.explicit_content_filter ?? this.explicitContentFilter |       this.defaultMessageNotifications = | ||||||
|       // this.roles =
 |         data.default_message_notifications ?? this.defaultMessageNotifications | ||||||
|       //   data.roles.map(
 |       this.explicitContentFilter = | ||||||
|       //     v => cache.get('role', v.id) ?? new Role(this.client, v)
 |         data.explicit_content_filter ?? this.explicitContentFilter | ||||||
|       //   ) ?? this.roles
 |       // this.roles =
 | ||||||
|       // this.emojis =
 |       //   data.roles.map(
 | ||||||
|       //   data.emojis.map(
 |       //     v => cache.get('role', v.id) ?? new Role(this.client, v)
 | ||||||
|       //     v => cache.get('emoji', v.id) ?? new Emoji(this.client, v)
 |       //   ) ?? this.roles
 | ||||||
|       //   ) ?? this.emojis
 |       // this.emojis =
 | ||||||
|       this.features = data.features ?? this.features |       //   data.emojis.map(
 | ||||||
|       this.mfaLevel = data.mfa_level ?? this.mfaLevel |       //     v => cache.get('emoji', v.id) ?? new Emoji(this.client, v)
 | ||||||
|       this.systemChannelID = data.system_channel_id ?? this.systemChannelID |       //   ) ?? this.emojis
 | ||||||
|       this.systemChannelFlags = |       this.features = data.features ?? this.features | ||||||
|         data.system_channel_flags ?? this.systemChannelFlags |       this.mfaLevel = data.mfa_level ?? this.mfaLevel | ||||||
|       this.rulesChannelID = data.rules_channel_id ?? this.rulesChannelID |       this.systemChannelID = data.system_channel_id ?? this.systemChannelID | ||||||
|       this.joinedAt = data.joined_at ?? this.joinedAt |       this.systemChannelFlags = | ||||||
|       this.large = data.large ?? this.large |         data.system_channel_flags ?? this.systemChannelFlags | ||||||
|       this.memberCount = data.member_count ?? this.memberCount |       this.rulesChannelID = data.rules_channel_id ?? this.rulesChannelID | ||||||
|       // this.voiceStates =
 |       this.joinedAt = data.joined_at ?? this.joinedAt | ||||||
|       //   data.voice_states?.map(
 |       this.large = data.large ?? this.large | ||||||
|       //     v =>
 |       this.memberCount = data.member_count ?? this.memberCount | ||||||
|       //       cache.get('voiceState', `${v.guild_id}:${v.user_id}`) ??
 |       // this.voiceStates =
 | ||||||
|       //       new VoiceState(this.client, v)
 |       //   data.voice_states?.map(
 | ||||||
|       //   ) ?? this.voiceStates
 |       //     v =>
 | ||||||
|       // this.members =
 |       //       cache.get('voiceState', `${v.guild_id}:${v.user_id}`) ??
 | ||||||
|       //   data.members?.map(
 |       //       new VoiceState(this.client, v)
 | ||||||
|       //     v =>
 |       //   ) ?? this.voiceStates
 | ||||||
|       //       cache.get('member', `${this.id}:${v.user.id}`) ??
 |       // this.members =
 | ||||||
|       //       new Member(this.client, v)
 |       //   data.members?.map(
 | ||||||
|       //   ) ?? this.members
 |       //     v =>
 | ||||||
|       // this.channels =
 |       //       cache.get('member', `${this.id}:${v.user.id}`) ??
 | ||||||
|       //   data.channels?.map(
 |       //       new Member(this.client, v)
 | ||||||
|       //     v => cache.get('channel', v.id) ?? getChannelByType(this.client, v, this)
 |       //   ) ?? this.members
 | ||||||
|       //   ) ?? this.members
 |       // this.channels =
 | ||||||
|       this.presences = data.presences ?? this.presences |       //   data.channels?.map(
 | ||||||
|       this.maxPresences = data.max_presences ?? this.maxPresences |       //     v => cache.get('channel', v.id) ?? getChannelByType(this.client, v, this)
 | ||||||
|       this.maxMembers = data.max_members ?? this.maxMembers |       //   ) ?? this.members
 | ||||||
|       this.vanityURLCode = data.vanity_url_code ?? this.vanityURLCode |       this.presences = data.presences ?? this.presences | ||||||
|       this.description = data.description ?? this.description |       this.maxPresences = data.max_presences ?? this.maxPresences | ||||||
|       this.banner = data.banner ?? this.banner |       this.maxMembers = data.max_members ?? this.maxMembers | ||||||
|       this.premiumTier = data.premium_tier ?? this.premiumTier |       this.vanityURLCode = data.vanity_url_code ?? this.vanityURLCode | ||||||
|       this.premiumSubscriptionCount = |       this.description = data.description ?? this.description | ||||||
|         data.premium_subscription_count ?? this.premiumSubscriptionCount |       this.banner = data.banner ?? this.banner | ||||||
|       this.preferredLocale = data.preferred_locale ?? this.preferredLocale |       this.premiumTier = data.premium_tier ?? this.premiumTier | ||||||
|       this.publicUpdatesChannelID = |       this.premiumSubscriptionCount = | ||||||
|         data.public_updates_channel_id ?? this.publicUpdatesChannelID |         data.premium_subscription_count ?? this.premiumSubscriptionCount | ||||||
|       this.maxVideoChannelUsers = |       this.preferredLocale = data.preferred_locale ?? this.preferredLocale | ||||||
|         data.max_video_channel_users ?? this.maxVideoChannelUsers |       this.publicUpdatesChannelID = | ||||||
|       this.approximateNumberCount = |         data.public_updates_channel_id ?? this.publicUpdatesChannelID | ||||||
|         data.approximate_number_count ?? this.approximateNumberCount |       this.maxVideoChannelUsers = | ||||||
|       this.approximatePresenceCount = |         data.max_video_channel_users ?? this.maxVideoChannelUsers | ||||||
|         data.approximate_presence_count ?? this.approximatePresenceCount |       this.approximateNumberCount = | ||||||
|     } |         data.approximate_number_count ?? this.approximateNumberCount | ||||||
|   } |       this.approximatePresenceCount = | ||||||
| 
 |         data.approximate_presence_count ?? this.approximatePresenceCount | ||||||
|   async getEveryoneRole (): Promise<Role> { |     } | ||||||
|     return (await this.roles.array().then(arr => arr?.sort((b, a) => a.position - b.position)[0]) as any) as Role |   } | ||||||
|   } | 
 | ||||||
| 
 |   async getEveryoneRole (): Promise<Role> { | ||||||
|   async me(): Promise<Member> { |     return (await this.roles.get(this.id) as unknown) as Role | ||||||
|     const get = await this.members.get(this.client.user?.id as string) |   } | ||||||
|     if (get === undefined) throw new Error('Guild#me is not cached') | 
 | ||||||
|     return get |   async me(): Promise<Member> { | ||||||
|   } |     const get = await this.members.get(this.client.user?.id as string) | ||||||
| } |     if (get === undefined) throw new Error('Guild#me is not cached') | ||||||
|  |     return get | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   async fetchIntegrations(): Promise<GuildIntegration[]> { | ||||||
|  |     const raw = await this.client.rest.get(GUILD_INTEGRATIONS(this.id)) as GuildIntegrationPayload[] | ||||||
|  |     return raw.map(e => new GuildIntegration(this.client, e)) | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export class GuildIntegration extends Base { | ||||||
|  |   id: string | ||||||
|  |   name: string | ||||||
|  |   type: string | ||||||
|  |   enabled: boolean | ||||||
|  |   syncing?: boolean | ||||||
|  |   roleID?: string | ||||||
|  |   enableEmoticons?: boolean | ||||||
|  |   expireBehaviour?: IntegrationExpireBehavior | ||||||
|  |   expireGracePeriod?: number | ||||||
|  |   user?: User | ||||||
|  |   account: IntegrationAccountPayload | ||||||
|  |   syncedAt?: string // Actually a ISO Timestamp, but we parse in constructor'
 | ||||||
|  |   subscriberCount?: number | ||||||
|  |   revoked?: boolean | ||||||
|  |   application?: Application | ||||||
|  | 
 | ||||||
|  |   constructor(client: Client, data: GuildIntegrationPayload) { | ||||||
|  |     super(client, data) | ||||||
|  | 
 | ||||||
|  |     this.id = data.id | ||||||
|  |     this.name= data.name | ||||||
|  |     this.type = data.type | ||||||
|  |     this.enabled = data.enabled | ||||||
|  |     this.syncing = data.syncing | ||||||
|  |     this.roleID = data.role_id | ||||||
|  |     this.enableEmoticons = data.enable_emoticons | ||||||
|  |     this.expireBehaviour = data.expire_behaviour | ||||||
|  |     this.expireGracePeriod = data.expire_grace_period | ||||||
|  |     this.user = data.user !== undefined ? new User(client, data.user) : undefined | ||||||
|  |     this.account = data.account | ||||||
|  |     this.syncedAt = data.synced_at | ||||||
|  |     this.subscriberCount = data.subscriber_count | ||||||
|  |     this.revoked = data.revoked | ||||||
|  |     this.application = data.application !== undefined ? new Application(client, data.application) : undefined | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -7,7 +7,7 @@ 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' | ||||||
| 
 | 
 | ||||||
| type AllMessageOptions = MessageOption | Embed | export type AllMessageOptions = MessageOption | Embed | ||||||
| 
 | 
 | ||||||
| export class TextChannel extends Channel { | export class TextChannel extends Channel { | ||||||
|   lastMessageID?: string |   lastMessageID?: string | ||||||
|  | @ -27,6 +27,12 @@ export class TextChannel extends Channel { | ||||||
|     this.lastPinTimestamp = data.last_pin_timestamp ?? this.lastPinTimestamp |     this.lastPinTimestamp = data.last_pin_timestamp ?? this.lastPinTimestamp | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /** | ||||||
|  |    *  | ||||||
|  |    * @param text Text content of the Message to send. | ||||||
|  |    * @param option Various other Message options. | ||||||
|  |    * @param reply Reference to a Message object to reply-to. | ||||||
|  |    */ | ||||||
|   async send(text?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message): Promise<Message> { |   async send(text?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message): Promise<Message> { | ||||||
|     if (typeof text === "object") { |     if (typeof text === "object") { | ||||||
|       option = text |       option = text | ||||||
|  | @ -44,7 +50,7 @@ export class TextChannel extends Channel { | ||||||
|       embed: option?.embed, |       embed: option?.embed, | ||||||
|       file: option?.file, |       file: option?.file, | ||||||
|       tts: option?.tts, |       tts: option?.tts, | ||||||
|       allowed_mentions: option?.allowedMention |       allowed_mentions: option?.allowedMentions | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (reply !== undefined) { |     if (reply !== undefined) { | ||||||
|  | @ -63,6 +69,12 @@ export class TextChannel extends Channel { | ||||||
|     return res |     return res | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /** | ||||||
|  |    *  | ||||||
|  |    * @param message Message to edit. ID or the Message object itself. | ||||||
|  |    * @param text New text contents of the Message. | ||||||
|  |    * @param option Other options to edit the message. | ||||||
|  |    */ | ||||||
|   async editMessage( |   async editMessage( | ||||||
|     message: Message | string, |     message: Message | string, | ||||||
|     text?: string, |     text?: string, | ||||||
|  | @ -84,9 +96,10 @@ export class TextChannel extends Channel { | ||||||
|       { |       { | ||||||
|         content: text, |         content: text, | ||||||
|         embed: option?.embed !== undefined ? option.embed.toJSON() : undefined, |         embed: option?.embed !== undefined ? option.embed.toJSON() : undefined, | ||||||
|         file: option?.file, |         // Cannot upload new files with Message
 | ||||||
|  |         // file: option?.file,
 | ||||||
|         tts: option?.tts, |         tts: option?.tts, | ||||||
|         allowed_mentions: option?.allowedMention |         allowed_mentions: option?.allowedMentions | ||||||
|       } |       } | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,69 +1,76 @@ | ||||||
| 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 { | ||||||
|   id: string |   id: string | ||||||
|   username: string |   username: string | ||||||
|   discriminator: string |   discriminator: string | ||||||
|   avatar?: string |   avatar?: string | ||||||
|   bot?: boolean |   bot?: boolean | ||||||
|   system?: boolean |   system?: boolean | ||||||
|   mfaEnabled?: boolean |   mfaEnabled?: boolean | ||||||
|   locale?: string |   locale?: string | ||||||
|   verified?: boolean |   verified?: boolean | ||||||
|   email?: string |   email?: string | ||||||
|   flags?: UserFlagsManager |   flags?: UserFlagsManager | ||||||
|   premiumType?: 0 | 1 | 2 |   /**  | ||||||
|   publicFlags?: UserFlagsManager |    * Nitro type of the User.  | ||||||
| 
 |    *  | ||||||
|   get tag (): string { |    * 0 = No Nitro | ||||||
|     return `${this.username}#${this.discriminator}` |    * 1 = Classic Nitro | ||||||
|   } |    * 2 = Regular Nitro | ||||||
| 
 |    */ | ||||||
|   get nickMention (): string { |   premiumType?: 0 | 1 | 2 | ||||||
|     return `<@!${this.id}>` |   publicFlags?: UserFlagsManager | ||||||
|   } | 
 | ||||||
| 
 |   get tag (): string { | ||||||
|   get mention (): string { |     return `${this.username}#${this.discriminator}` | ||||||
|     return `<@${this.id}>` |   } | ||||||
|   } | 
 | ||||||
| 
 |   get nickMention (): string { | ||||||
|   constructor (client: Client, data: UserPayload) { |     return `<@!${this.id}>` | ||||||
|     super(client, data) |   } | ||||||
|     this.id = data.id | 
 | ||||||
|     this.username = data.username |   get mention (): string { | ||||||
|     this.discriminator = data.discriminator |     return `<@${this.id}>` | ||||||
|     this.avatar = data.avatar |   } | ||||||
|     this.bot = data.bot | 
 | ||||||
|     this.system = data.system |   constructor (client: Client, data: UserPayload) { | ||||||
|     this.mfaEnabled = data.mfa_enabled |     super(client, data) | ||||||
|     this.locale = data.locale |     this.id = data.id | ||||||
|     this.verified = data.verified |     this.username = data.username | ||||||
|     this.email = data.email |     this.discriminator = data.discriminator | ||||||
|     this.flags = new UserFlagsManager(data.flags) |     this.avatar = data.avatar | ||||||
|     this.premiumType = data.premium_type |     this.bot = data.bot | ||||||
|     this.publicFlags = new UserFlagsManager(data.public_flags) |     this.system = data.system | ||||||
|   } |     this.mfaEnabled = data.mfa_enabled | ||||||
| 
 |     this.locale = data.locale | ||||||
|   protected readFromData (data: UserPayload): void { |     this.verified = data.verified | ||||||
|     super.readFromData(data) |     this.email = data.email | ||||||
|     this.username = data.username ?? this.username |     this.flags = new UserFlagsManager(data.flags) | ||||||
|     this.discriminator = data.discriminator ?? this.discriminator |     this.premiumType = data.premium_type | ||||||
|     this.avatar = data.avatar ?? this.avatar |     this.publicFlags = new UserFlagsManager(data.public_flags) | ||||||
|     this.bot = data.bot ?? this.bot |   } | ||||||
|     this.system = data.system ?? this.system | 
 | ||||||
|     this.mfaEnabled = data.mfa_enabled ?? this.mfaEnabled |   protected readFromData (data: UserPayload): void { | ||||||
|     this.locale = data.locale ?? this.locale |     super.readFromData(data) | ||||||
|     this.verified = data.verified ?? this.verified |     this.username = data.username ?? this.username | ||||||
|     this.email = data.email ?? this.email |     this.discriminator = data.discriminator ?? this.discriminator | ||||||
|     this.flags = new UserFlagsManager(data.flags) ?? this.flags |     this.avatar = data.avatar ?? this.avatar | ||||||
|     this.premiumType = data.premium_type ?? this.premiumType |     this.bot = data.bot ?? this.bot | ||||||
|     this.publicFlags = new UserFlagsManager(data.public_flags) ?? this.publicFlags |     this.system = data.system ?? this.system | ||||||
|   } |     this.mfaEnabled = data.mfa_enabled ?? this.mfaEnabled | ||||||
| 
 |     this.locale = data.locale ?? this.locale | ||||||
|   toString (): string { |     this.verified = data.verified ?? this.verified | ||||||
|     return this.mention |     this.email = data.email ?? this.email | ||||||
|   } |     this.flags = new UserFlagsManager(data.flags) ?? this.flags | ||||||
| } |     this.premiumType = data.premium_type ?? this.premiumType | ||||||
|  |     this.publicFlags = new UserFlagsManager(data.public_flags) ?? this.publicFlags | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   toString (): string { | ||||||
|  |     return this.mention | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -1,23 +1,158 @@ | ||||||
| import { Client } from '../models/client.ts' | import { DISCORD_API_URL, DISCORD_API_VERSION } from "../consts/urlsAndVersions.ts" | ||||||
| import { UserPayload } from '../types/user.ts' | import { Client } from '../models/client.ts' | ||||||
| import { WebhookPayload } from '../types/webhook.ts' | import { RESTManager } from "../models/rest.ts" | ||||||
| import { Base } from './base.ts' | import { MessageOption } from "../types/channel.ts" | ||||||
| 
 | import { UserPayload } from '../types/user.ts' | ||||||
| export class Webhook extends Base { | import { WebhookPayload } from '../types/webhook.ts' | ||||||
|   id: string | import { Embed } from "./embed.ts" | ||||||
|   type: 1 | 2 | import { Message } from "./message.ts" | ||||||
|   guildID?: string | import { TextChannel } from "./textChannel.ts" | ||||||
|   channelID: string | import { User } from "./user.ts" | ||||||
|   user?: UserPayload | import { fetchAuto } from 'https://raw.githubusercontent.com/DjDeveloperr/fetch-base64/main/mod.ts' | ||||||
|   name?: string | 
 | ||||||
|   avatar?: string | export interface WebhookMessageOptions extends MessageOption { | ||||||
|   token?: string |   embeds?: Embed[] | ||||||
|   applicationID?: string |   name?: string | ||||||
| 
 |   avatar?: string | ||||||
|   constructor (client: Client, data: WebhookPayload) { | } | ||||||
|     super(client) | 
 | ||||||
|     this.id = data.id | export type AllWebhookMessageOptions = string | WebhookMessageOptions | ||||||
|     this.type = data.type | 
 | ||||||
|     this.channelID = data.channel_id | export interface WebhookEditOptions { | ||||||
|   } |   /** New name to set for Webhook. */ | ||||||
| } |   name?: string | ||||||
|  |   /** New avatar to set for Webhook. URL of image or base64 encoded data. */ | ||||||
|  |   avatar?: string | ||||||
|  |   /** New channel for Webhook. Requires authentication. */ | ||||||
|  |   channelID?: string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** Webhook follows different way of instantiation */ | ||||||
|  | export class Webhook { | ||||||
|  |   client?: Client | ||||||
|  |   id: string | ||||||
|  |   type: 1 | 2 | ||||||
|  |   guildID?: string | ||||||
|  |   channelID: string | ||||||
|  |   user?: User | ||||||
|  |   userRaw?: UserPayload | ||||||
|  |   name?: string | ||||||
|  |   avatar?: string | ||||||
|  |   token?: string | ||||||
|  |   applicationID?: string | ||||||
|  |   rest: RESTManager | ||||||
|  | 
 | ||||||
|  |   get url(): string { | ||||||
|  |     return `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${this.id}/${this.token}` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   constructor(data: WebhookPayload, client?: Client, rest?: RESTManager) { | ||||||
|  |     this.id = data.id | ||||||
|  |     this.type = data.type | ||||||
|  |     this.channelID = data.channel_id | ||||||
|  |     this.guildID = data.guild_id | ||||||
|  |     this.user = data.user === undefined || client === undefined ? undefined : new User(client, data.user) | ||||||
|  |     if (data.user !== undefined && client === undefined) this.userRaw = data.user | ||||||
|  |     this.name = data.name | ||||||
|  |     this.avatar = data.avatar | ||||||
|  |     this.token = data.token | ||||||
|  |     this.applicationID = data.application_id | ||||||
|  | 
 | ||||||
|  |     if (rest !== undefined) this.rest = rest | ||||||
|  |     else if (client !== undefined) this.rest = client.rest | ||||||
|  |     else this.rest = new RESTManager() | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   private fromPayload(data: WebhookPayload): Webhook { | ||||||
|  |     this.id = data.id | ||||||
|  |     this.type = data.type | ||||||
|  |     this.channelID = data.channel_id | ||||||
|  |     this.guildID = data.guild_id | ||||||
|  |     this.user = data.user === undefined || this.client === undefined ? undefined : new User(this.client, data.user) | ||||||
|  |     if (data.user !== undefined && this.client === undefined) this.userRaw = data.user | ||||||
|  |     this.name = data.name | ||||||
|  |     this.avatar = data.avatar | ||||||
|  |     this.token = data.token | ||||||
|  |     this.applicationID = data.application_id | ||||||
|  | 
 | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Send a Message through Webhook. */ | ||||||
|  |   async send(text?: string | AllWebhookMessageOptions, option?: AllWebhookMessageOptions): Promise<Message> { | ||||||
|  |     if (typeof text === "object") { | ||||||
|  |       option = text | ||||||
|  |       text = undefined | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (text === undefined && option === undefined) { | ||||||
|  |       throw new Error('Either text or option is necessary.') | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (option instanceof Embed) option = { | ||||||
|  |       embeds: [ option ], | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const payload: any = { | ||||||
|  |       content: text, | ||||||
|  |       embeds: (option as WebhookMessageOptions)?.embed !== undefined ? [ (option as WebhookMessageOptions).embed ] : ((option as WebhookMessageOptions)?.embeds !== undefined ? (option as WebhookMessageOptions).embeds : undefined), | ||||||
|  |       file: (option as WebhookMessageOptions)?.file, | ||||||
|  |       tts: (option as WebhookMessageOptions)?.tts, | ||||||
|  |       allowed_mentions: (option as WebhookMessageOptions)?.allowedMentions | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if ((option as WebhookMessageOptions).name !== undefined) { | ||||||
|  |       payload.username = (option as WebhookMessageOptions)?.name | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if ((option as WebhookMessageOptions).avatar !== undefined) { | ||||||
|  |       payload.avatar = (option as WebhookMessageOptions)?.avatar | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (payload.embeds !== undefined && payload.embeds instanceof Array && payload.embeds.length > 10) throw new Error(`Cannot send more than 10 embeds through Webhook`) | ||||||
|  | 
 | ||||||
|  |     const resp = await this.rest.post(this.url + '?wait=true', payload) | ||||||
|  | 
 | ||||||
|  |     const res = new Message(this.client as Client, resp, (this as unknown) as TextChannel, (this as unknown) as User) | ||||||
|  |     await res.mentions.fromPayload(resp) | ||||||
|  |     return res | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Create a Webhook object from URL | ||||||
|  |    * @param url URL of the Webhook | ||||||
|  |    * @param client Client (bot) object, if any. | ||||||
|  |   */ | ||||||
|  |   static async fromURL(url: string | URL, client?: Client): Promise<Webhook> { | ||||||
|  |     const rest = client !== undefined ? client.rest : new RESTManager() | ||||||
|  | 
 | ||||||
|  |     const raw = await rest.get(typeof url === 'string' ? url : url.toString()) | ||||||
|  |     if (typeof raw !== 'object') throw new Error(`Failed to load Webhook from URL: ${url}`) | ||||||
|  | 
 | ||||||
|  |     const webhook = new Webhook(raw, client, rest) | ||||||
|  |     return webhook | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * Edit the Webhook name, avatar, or channel (requires authentication). | ||||||
|  |    * @param options Options to edit the Webhook. | ||||||
|  |    */ | ||||||
|  |   async edit(options: WebhookEditOptions): Promise<Webhook> { | ||||||
|  |     if (options.channelID !== undefined && this.rest.client === undefined) throw new Error('Authentication is required for editing Webhook Channel') | ||||||
|  |     if (options.avatar !== undefined && (options.avatar.startsWith('http:') || options.avatar.startsWith('https:'))) { | ||||||
|  |       options.avatar = await fetchAuto(options.avatar) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const data = await this.rest.patch(this.url, options) | ||||||
|  |     this.fromPayload(data) | ||||||
|  | 
 | ||||||
|  |     return this | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   /** Delete the Webhook. */ | ||||||
|  |   async delete(): Promise<boolean> { | ||||||
|  |     const resp = await this.rest.delete(this.url, undefined, 0, undefined, true) | ||||||
|  |     if (resp.response.status !== 204) return false | ||||||
|  |     else return true | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										212
									
								
								src/test/cmd.ts
									
										
									
									
									
								
							
							
						
						
									
										212
									
								
								src/test/cmd.ts
									
										
									
									
									
								
							|  | @ -1,103 +1,109 @@ | ||||||
| import { Command, CommandClient, Intents } from '../../mod.ts' | import { Command, CommandClient, Intents, GuildChannel, CommandContext, Extension } from '../../mod.ts' | ||||||
| import { GuildChannel } from "../managers/guildChannels.ts" | import { TOKEN } from './config.ts' | ||||||
| import { CommandContext } from "../models/command.ts" | 
 | ||||||
| import { Extension } from "../models/extensions.ts" | const client = new CommandClient({ | ||||||
| import { Member } from "../structures/member.ts" |   prefix: ["pls", "!"], | ||||||
| import { Message } from "../structures/message.ts" |   spacesAfterPrefix: true, | ||||||
| import { Role } from "../structures/role.ts" |   mentionPrefix: true | ||||||
| import { MessageDeletePayload } from "../types/gateway.ts" | }) | ||||||
| import { TOKEN } from './config.ts' | 
 | ||||||
| 
 | client.on('debug', console.log) | ||||||
| const client = new CommandClient({ | 
 | ||||||
|   prefix: ["pls", "!"], | client.on('ready', () => { | ||||||
|   spacesAfterPrefix: true, |   console.log(`[Login] Logged in as ${client.user?.tag}!`) | ||||||
|   mentionPrefix: true | }) | ||||||
| }) | 
 | ||||||
| 
 | client.on('messageDelete', (msg) => { | ||||||
| client.on('debug', console.log) |   console.log(`Message Deleted: ${msg.id}, ${msg.author.tag}, ${msg.content}`) | ||||||
| 
 | }) | ||||||
| client.on('ready', () => { | 
 | ||||||
|   console.log(`[Login] Logged in as ${client.user?.tag}!`) | client.on('messageUpdate', (before, after) => { | ||||||
| }) |   console.log('Message Update') | ||||||
| 
 |   console.log(`Before: ${before.author.tag}: ${before.content}`) | ||||||
| client.on('messageDelete', (msg: Message) => { |   console.log(`After: ${after.author.tag}: ${after.content}`) | ||||||
|   console.log(`Message Deleted: ${msg.id}, ${msg.author.tag}, ${msg.content}`) | }) | ||||||
| }) | 
 | ||||||
| 
 | client.on('messageUpdateUncached', (msg) => { | ||||||
| client.on('messageDeleteUncached', (d: MessageDeletePayload) => { |   console.log(`Message: ${msg.author.tag}: ${msg.content}`) | ||||||
|   console.log(`Uncached Message Deleted: ${d.id} in ${d.channel_id}`) | }) | ||||||
| }) | 
 | ||||||
| 
 | client.on('guildMemberAdd', (member) => { | ||||||
| client.on('messageUpdate', (before: Message, after: Message) => { |   console.log(`Member Join: ${member.user.tag}`) | ||||||
|   console.log('Message Update') | }) | ||||||
|   console.log(`Before: ${before.author.tag}: ${before.content}`) | 
 | ||||||
|   console.log(`After: ${after.author.tag}: ${after.content}`) | client.on('guildMemberRemove', (member) => { | ||||||
| }) |   console.log(`Member Leave: ${member.user.tag}`) | ||||||
| 
 | }) | ||||||
| client.on('messageUpdateUncached', (msg: Message) => { | 
 | ||||||
|   console.log(`Message: ${msg.author.tag}: ${msg.content}`) | client.on('guildRoleCreate', (role) => { | ||||||
| }) |   console.log(`Role Create: ${role.name}`) | ||||||
| 
 | }) | ||||||
| client.on('guildMemberAdd', (member: Member) => { | 
 | ||||||
|   console.log(`Member Join: ${member.user.tag}`) | client.on('guildRoleDelete', (role) => { | ||||||
| }) |   console.log(`Role Delete: ${role.name}`) | ||||||
| 
 | }) | ||||||
| client.on('guildMemberRemove', (member: Member) => { | 
 | ||||||
|   console.log(`Member Leave: ${member.user.tag}`) | client.on('guildRoleUpdate', (role, after) => { | ||||||
| }) |   console.log(`Role Update: ${role.name}, ${after.name}`) | ||||||
| 
 | }) | ||||||
| client.on('guildRoleCreate', (role: Role) => { | 
 | ||||||
|   console.log(`Role Create: ${role.name}`) | client.on('guildIntegrationsUpdate', (guild) => { | ||||||
| }) |   console.log(`Guild Integrations Update: ${guild.name}`) | ||||||
| 
 | }) | ||||||
| client.on('guildRoleDelete', (role: Role) => { | 
 | ||||||
|   console.log(`Role Delete: ${role.name}`) | client.on('webhooksUpdate', (guild, channel) => { | ||||||
| }) |   console.log(`Webhooks Updated in #${channel.name} from ${guild.name}`) | ||||||
| 
 | }) | ||||||
| client.on('guildRoleUpdate', (role: Role, after: Role) => { | 
 | ||||||
|   console.log(`Role Update: ${role.name}, ${after.name}`) | client.on("commandError", console.error) | ||||||
| }) | 
 | ||||||
| 
 | class ChannelLog extends Extension { | ||||||
| // client.on('messageCreate', msg => console.log(`${msg.author.tag}: ${msg.content}`))
 | 
 | ||||||
| 
 |   onChannelCreate(ext: Extension, channel: GuildChannel): void { | ||||||
| client.on("commandError", console.error) |     console.log(`Channel Created: ${channel.name}`) | ||||||
| 
 |   } | ||||||
| class ChannelLog extends Extension { | 
 | ||||||
| 
 |   load(): void { | ||||||
|   onChannelCreate(ext: Extension, channel: GuildChannel): void { |     this.listen('channelCreate', this.onChannelCreate) | ||||||
|     console.log(`Channel Created: ${channel.name}`) | 
 | ||||||
|   } |     class Pong extends Command { | ||||||
| 
 |       name = 'Pong' | ||||||
|   load(): void { | 
 | ||||||
|     this.listen('channelCreate', this.onChannelCreate) |       execute(ctx: CommandContext): any { | ||||||
| 
 |         ctx.message.reply('Ping!') | ||||||
|     class Pong extends Command { |       } | ||||||
|       name = 'Pong' |     } | ||||||
| 
 | 
 | ||||||
|       execute(ctx: CommandContext): any { |     this.commands.add(Pong) | ||||||
|         ctx.message.reply('Ping!') |   } | ||||||
|       } | } | ||||||
|     } | 
 | ||||||
| 
 | client.extensions.load(ChannelLog) | ||||||
|     this.commands.add(Pong) | 
 | ||||||
|   } | client.on('messageDeleteBulk', (channel, messages, uncached) => { | ||||||
| } |   console.log(`=== Message Delete Bulk ===\nMessages: ${messages.map(m => m.id).join(', ')}\nUncached: ${[...uncached.values()].join(', ')}`) | ||||||
| 
 | }) | ||||||
| client.extensions.load(ChannelLog) | 
 | ||||||
| 
 | client.on('channelUpdate', (before, after) => { | ||||||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises
 |   console.log(`Channel Update: ${(before as GuildChannel).name}, ${(after as GuildChannel).name}`) | ||||||
| ;(async() => { | }) | ||||||
|   const files = Deno.readDirSync('./src/test/cmds') | 
 | ||||||
| 
 | client.on('typingStart', (user, channel, at, guildData) => { | ||||||
|   for (const file of files) { |   console.log(`${user.tag} started typing in ${channel.id} at ${at}${guildData !== undefined ? `\nGuild: ${guildData.guild.name}` : ''}`) | ||||||
|     const module = await import(`./cmds/${file.name}`) | }) | ||||||
|     // eslint-disable-next-line new-cap
 | 
 | ||||||
|     const cmd = new module.default() | // client.on('raw', (evt: string) => console.log(`EVENT: ${evt}`))
 | ||||||
|     client.commands.add(cmd) | 
 | ||||||
|     console.log(`Loaded command ${cmd.name}!`) | const files = Deno.readDirSync('./src/test/cmds') | ||||||
|   } | 
 | ||||||
| 
 | for (const file of files) { | ||||||
|   console.log(`Loaded ${client.commands.count} commands!`) |   const module = await import(`./cmds/${file.name}`) | ||||||
| 
 |   // eslint-disable-next-line new-cap
 | ||||||
|   client.connect(TOKEN, Intents.All) |   const cmd = new module.default() | ||||||
| })() |   client.commands.add(cmd) | ||||||
|  |   console.log(`Loaded command ${cmd.name}!`) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | console.log(`Loaded ${client.commands.count} commands!`) | ||||||
|  | 
 | ||||||
|  | client.connect(TOKEN, Intents.create(['GUILD_MEMBERS', 'GUILD_PRESENCES'])) | ||||||
							
								
								
									
										9
									
								
								src/test/hook.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/test/hook.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | ||||||
|  | import { Webhook } from '../../mod.ts' | ||||||
|  | import { WEBHOOK } from "./config.ts" | ||||||
|  | 
 | ||||||
|  | const webhook = await Webhook.fromURL(WEBHOOK) | ||||||
|  | console.log('Fetched webhook!') | ||||||
|  | 
 | ||||||
|  | webhook.send('Hello World', { | ||||||
|  |   name: 'OwO' | ||||||
|  | }).then(() => 'Sent message!') | ||||||
							
								
								
									
										10
									
								
								src/types/application.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/types/application.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | ||||||
|  | import { UserPayload } from "./user.ts"; | ||||||
|  | 
 | ||||||
|  | export interface ApplicationPayload { | ||||||
|  |   id: string | ||||||
|  |   name: string | ||||||
|  |   icon: string | ||||||
|  |   description: string | ||||||
|  |   summary: string | ||||||
|  |   bot?: UserPayload | ||||||
|  | } | ||||||
|  | @ -102,7 +102,7 @@ export interface MessageOption { | ||||||
|   tts?: boolean |   tts?: boolean | ||||||
|   embed?: Embed |   embed?: Embed | ||||||
|   file?: Attachment |   file?: Attachment | ||||||
|   allowedMention?: { |   allowedMentions?: { | ||||||
|     parse: 'everyone' | 'users' | 'roles' |     parse: 'everyone' | 'users' | 'roles' | ||||||
|     roles: string[] |     roles: string[] | ||||||
|     users: string[] |     users: string[] | ||||||
|  |  | ||||||
|  | @ -1,5 +1,7 @@ | ||||||
| // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
 | // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
 | ||||||
| // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
 | // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
 | ||||||
|  | import { Guild } from "../structures/guild.ts" | ||||||
|  | import { Member } from "../structures/member.ts" | ||||||
| import { EmojiPayload } from './emoji.ts' | import { EmojiPayload } from './emoji.ts' | ||||||
| import { MemberPayload } from './guild.ts' | import { MemberPayload } from './guild.ts' | ||||||
| import { | import { | ||||||
|  | @ -320,3 +322,16 @@ export interface WebhooksUpdatePayload { | ||||||
|   guild_id: string |   guild_id: string | ||||||
|   channel_id: string |   channel_id: string | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export interface TypingStartPayload { | ||||||
|  |   channel_id: string | ||||||
|  |   user_id: string | ||||||
|  |   guild_id?: string | ||||||
|  |   timestamp: number | ||||||
|  |   member?: MemberPayload | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface TypingStartGuildData { | ||||||
|  |   guild: Guild | ||||||
|  |   member: Member | ||||||
|  | } | ||||||
|  | @ -1,114 +1,143 @@ | ||||||
| import { ChannelPayload } from './channel.ts' | import { ApplicationPayload } from "./application.ts" | ||||||
| import { EmojiPayload } from './emoji.ts' | import { ChannelPayload } from './channel.ts' | ||||||
| import { PresenceUpdatePayload } from './gateway.ts' | import { EmojiPayload } from './emoji.ts' | ||||||
| import { RolePayload } from './role.ts' | import { PresenceUpdatePayload } from './gateway.ts' | ||||||
| import { UserPayload } from './user.ts' | import { RolePayload } from './role.ts' | ||||||
| import { VoiceStatePayload } from './voice.ts' | import { UserPayload } from './user.ts' | ||||||
| 
 | import { VoiceStatePayload } from './voice.ts' | ||||||
| export interface GuildPayload { | 
 | ||||||
|   id: string | export interface GuildPayload { | ||||||
|   name: string |   id: string | ||||||
|   icon?: string |   name: string | ||||||
|   icon_hash?: string |   icon?: string | ||||||
|   splash?: string |   icon_hash?: string | ||||||
|   discovery_splash?: string |   splash?: string | ||||||
|   owner?: boolean |   discovery_splash?: string | ||||||
|   owner_id: string |   owner?: boolean | ||||||
|   permissions?: string |   owner_id: string | ||||||
|   region: string |   permissions?: string | ||||||
|   afk_channel_id?: string |   region: string | ||||||
|   afk_timeout: number |   afk_channel_id?: string | ||||||
|   widget_enabled?: boolean |   afk_timeout: number | ||||||
|   widget_channel_id?: string |   widget_enabled?: boolean | ||||||
|   verification_level: string |   widget_channel_id?: string | ||||||
|   default_message_notifications: string |   verification_level: string | ||||||
|   explicit_content_filter: string |   default_message_notifications: string | ||||||
|   roles: RolePayload[] |   explicit_content_filter: string | ||||||
|   emojis: EmojiPayload[] |   roles: RolePayload[] | ||||||
|   features: GuildFeatures[] |   emojis: EmojiPayload[] | ||||||
|   mfa_level: string |   features: GuildFeatures[] | ||||||
|   application_id?: string |   mfa_level: string | ||||||
|   system_channel_id?: string |   application_id?: string | ||||||
|   system_channel_flags: string |   system_channel_id?: string | ||||||
|   rules_channel_id?: string |   system_channel_flags: string | ||||||
|   joined_at?: string |   rules_channel_id?: string | ||||||
|   large?: boolean |   joined_at?: string | ||||||
|   unavailable: boolean |   large?: boolean | ||||||
|   member_count?: number |   unavailable: boolean | ||||||
|   voice_states?: VoiceStatePayload[] |   member_count?: number | ||||||
|   members?: MemberPayload[] |   voice_states?: VoiceStatePayload[] | ||||||
|   channels?: ChannelPayload[] |   members?: MemberPayload[] | ||||||
|   presences?: PresenceUpdatePayload[] |   channels?: ChannelPayload[] | ||||||
|   max_presences?: number |   presences?: PresenceUpdatePayload[] | ||||||
|   max_members?: number |   max_presences?: number | ||||||
|   vanity_url_code?: string |   max_members?: number | ||||||
|   description?: string |   vanity_url_code?: string | ||||||
|   banner?: string |   description?: string | ||||||
|   premium_tier: number |   banner?: string | ||||||
|   premium_subscription_count?: number |   premium_tier: number | ||||||
|   preferred_locale: string |   premium_subscription_count?: number | ||||||
|   public_updates_channel_id?: string |   preferred_locale: string | ||||||
|   max_video_channel_users?: number |   public_updates_channel_id?: string | ||||||
|   approximate_number_count?: number |   max_video_channel_users?: number | ||||||
|   approximate_presence_count?: number |   approximate_number_count?: number | ||||||
| } |   approximate_presence_count?: number | ||||||
| 
 | } | ||||||
| export interface MemberPayload { | 
 | ||||||
|   user: UserPayload | export interface MemberPayload { | ||||||
|   nick?: string |   user: UserPayload | ||||||
|   roles: string[] |   nick?: string | ||||||
|   joined_at: string |   roles: string[] | ||||||
|   premium_since?: string |   joined_at: string | ||||||
|   deaf: boolean |   premium_since?: string | ||||||
|   mute: boolean |   deaf: boolean | ||||||
| } |   mute: boolean | ||||||
| 
 | } | ||||||
| export enum MessageNotification { | 
 | ||||||
|   ALL_MESSAGES = 0, | export enum MessageNotification { | ||||||
|   ONLY_MENTIONS = 1 |   ALL_MESSAGES = 0, | ||||||
| } |   ONLY_MENTIONS = 1 | ||||||
| 
 | } | ||||||
| export enum ContentFilter { | 
 | ||||||
|   DISABLED = 0, | export enum ContentFilter { | ||||||
|   MEMBERS_WITHOUT_ROLES = 1, |   DISABLED = 0, | ||||||
|   ALL_MEMBERS = 3 |   MEMBERS_WITHOUT_ROLES = 1, | ||||||
| } |   ALL_MEMBERS = 3 | ||||||
| 
 | } | ||||||
| export enum MFA { | 
 | ||||||
|   NONE = 0, | export enum MFA { | ||||||
|   ELEVATED = 1 |   NONE = 0, | ||||||
| } |   ELEVATED = 1 | ||||||
| 
 | } | ||||||
| export enum Verification { | 
 | ||||||
|   NONE = 0, | export enum Verification { | ||||||
|   LOW = 1, |   NONE = 0, | ||||||
|   MEDIUM = 2, |   LOW = 1, | ||||||
|   HIGH = 3, |   MEDIUM = 2, | ||||||
|   VERY_HIGH = 4 |   HIGH = 3, | ||||||
| } |   VERY_HIGH = 4 | ||||||
| 
 | } | ||||||
| export enum PremiumTier { | 
 | ||||||
|   NONE = 0, | export enum PremiumTier { | ||||||
|   TIER_1 = 1, |   NONE = 0, | ||||||
|   TIER_2 = 2, |   TIER_1 = 1, | ||||||
|   TIER_3 = 3 |   TIER_2 = 2, | ||||||
| } |   TIER_3 = 3 | ||||||
| 
 | } | ||||||
| export enum SystemChannelFlags { | 
 | ||||||
|   SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0, | export enum SystemChannelFlags { | ||||||
|   SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1 |   SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0, | ||||||
| } |   SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1 | ||||||
| 
 | } | ||||||
| export type GuildFeatures = | 
 | ||||||
|   | 'INVITE_SPLASH' | export type GuildFeatures = | ||||||
|   | 'VIP_REGIONS' |   | 'INVITE_SPLASH' | ||||||
|   | 'VANITY_URL' |   | 'VIP_REGIONS' | ||||||
|   | 'VERIFIED' |   | 'VANITY_URL' | ||||||
|   | 'PARTNERED' |   | 'VERIFIED' | ||||||
|   | 'PUBLIC' |   | 'PARTNERED' | ||||||
|   | 'COMMERCE' |   | 'PUBLIC' | ||||||
|   | 'NEWS' |   | 'COMMERCE' | ||||||
|   | 'DISCOVERABLE' |   | 'NEWS' | ||||||
|   | 'FEATURABLE' |   | 'DISCOVERABLE' | ||||||
|   | 'ANIMATED_ICON' |   | 'FEATURABLE' | ||||||
|   | 'BANNER' |   | 'ANIMATED_ICON' | ||||||
|  |   | 'BANNER' | ||||||
|  | 
 | ||||||
|  | export enum IntegrationExpireBehavior { | ||||||
|  |   REMOVE_ROLE = 0, | ||||||
|  |   KICK = 1 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface IntegrationAccountPayload { | ||||||
|  |   id: string | ||||||
|  |   name: string | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export interface GuildIntegrationPayload { | ||||||
|  |   id: string | ||||||
|  |   name: string | ||||||
|  |   type: string | ||||||
|  |   enabled: boolean | ||||||
|  |   syncing?: boolean | ||||||
|  |   role_id?: string | ||||||
|  |   enable_emoticons?: boolean | ||||||
|  |   expire_behaviour?: IntegrationExpireBehavior | ||||||
|  |   expire_grace_period?: number | ||||||
|  |   user?: UserPayload | ||||||
|  |   account: IntegrationAccountPayload | ||||||
|  |   synced_at?: string // Actually a ISO Timestamp, but we parse in constructor'
 | ||||||
|  |   subscriber_count?: number | ||||||
|  |   revoked?: boolean | ||||||
|  |   application?: ApplicationPayload | ||||||
|  | } | ||||||
|  | @ -1,36 +1,59 @@ | ||||||
| import { GatewayIntents } from '../types/gateway.ts' | import { GatewayIntents } from '../types/gateway.ts' | ||||||
| 
 | 
 | ||||||
| // eslint-disable-next-line @typescript-eslint/no-extraneous-class
 | export type PriviligedIntents = 'GUILD_MEMBERS' | 'GUILD_PRESENCES' | ||||||
| export class Intents { | 
 | ||||||
|   static All: number[] = [ | // eslint-disable-next-line @typescript-eslint/no-extraneous-class
 | ||||||
|     GatewayIntents.GUILD_MEMBERS, | export class Intents { | ||||||
|     GatewayIntents.GUILD_PRESENCES, |   static NonPriviliged: number[] = [ | ||||||
|     GatewayIntents.GUILD_MESSAGES, |     GatewayIntents.GUILD_MESSAGES, | ||||||
|     GatewayIntents.DIRECT_MESSAGES, |     GatewayIntents.DIRECT_MESSAGES, | ||||||
|     GatewayIntents.DIRECT_MESSAGE_REACTIONS, |     GatewayIntents.DIRECT_MESSAGE_REACTIONS, | ||||||
|     GatewayIntents.DIRECT_MESSAGE_TYPING, |     GatewayIntents.DIRECT_MESSAGE_TYPING, | ||||||
|     GatewayIntents.GUILDS, |     GatewayIntents.GUILDS, | ||||||
|     GatewayIntents.GUILD_BANS, |     GatewayIntents.GUILD_BANS, | ||||||
|     GatewayIntents.GUILD_EMOJIS, |     GatewayIntents.GUILD_EMOJIS, | ||||||
|     GatewayIntents.GUILD_INTEGRATIONS, |     GatewayIntents.GUILD_INTEGRATIONS, | ||||||
|     GatewayIntents.GUILD_INVITES, |     GatewayIntents.GUILD_INVITES, | ||||||
|     GatewayIntents.GUILD_MESSAGE_REACTIONS, |     GatewayIntents.GUILD_MESSAGE_REACTIONS, | ||||||
|     GatewayIntents.GUILD_MESSAGE_TYPING, |     GatewayIntents.GUILD_MESSAGE_TYPING, | ||||||
|     GatewayIntents.GUILD_VOICE_STATES, |     GatewayIntents.GUILD_VOICE_STATES, | ||||||
|     GatewayIntents.GUILD_WEBHOOKS |     GatewayIntents.GUILD_WEBHOOKS | ||||||
|   ] |   ] | ||||||
| 
 | 
 | ||||||
|   static Presence: number[] = [ |   static All: number[] = [ | ||||||
|     GatewayIntents.GUILD_PRESENCES, |     GatewayIntents.GUILD_MEMBERS, | ||||||
|     GatewayIntents.GUILDS |     GatewayIntents.GUILD_PRESENCES, | ||||||
|   ] |     ...Intents.NonPriviliged | ||||||
| 
 |   ] | ||||||
|   static GuildMembers: number[] = [ | 
 | ||||||
|     GatewayIntents.GUILD_MEMBERS, |   static Presence: number[] = [ | ||||||
|     GatewayIntents.GUILDS, |     GatewayIntents.GUILD_PRESENCES, | ||||||
|     GatewayIntents.GUILD_BANS, |     ...Intents.NonPriviliged | ||||||
|     GatewayIntents.GUILD_VOICE_STATES |   ] | ||||||
|   ] | 
 | ||||||
| 
 |   static GuildMembers: number[] = [ | ||||||
|   static None: number[] = [] |     GatewayIntents.GUILD_MEMBERS, | ||||||
| } |     ...Intents.NonPriviliged | ||||||
|  |   ] | ||||||
|  | 
 | ||||||
|  |   static None: number[] = [ | ||||||
|  |     ...Intents.NonPriviliged | ||||||
|  |   ] | ||||||
|  | 
 | ||||||
|  |   static create(priviliged?: PriviligedIntents[], disable?: number[]): number[] { | ||||||
|  |     let intents: number[] = [ | ||||||
|  |       ...Intents.NonPriviliged | ||||||
|  |     ] | ||||||
|  |      | ||||||
|  |     if (priviliged !== undefined && priviliged.length !== 0) { | ||||||
|  |       if (priviliged.includes('GUILD_MEMBERS')) intents.push(GatewayIntents.GUILD_MEMBERS) | ||||||
|  |       if (priviliged.includes('GUILD_PRESENCES')) intents.push(GatewayIntents.GUILD_PRESENCES) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (disable !== undefined) { | ||||||
|  |       intents = intents.filter(intent => !disable.includes(intent)) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return intents | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue