made requested changes
This commit is contained in:
		
							parent
							
								
									4fc5734ccc
								
							
						
					
					
						commit
						e01d10dd66
					
				
					 5 changed files with 23 additions and 8 deletions
				
			
		|  | @ -2,7 +2,6 @@ import { Gateway, GatewayEventHandler } from '../index.ts' | ||||||
| import { Guild } from '../../structures/guild.ts' | import { Guild } from '../../structures/guild.ts' | ||||||
| import { InviteCreatePayload } from '../../types/gateway.ts' | import { InviteCreatePayload } from '../../types/gateway.ts' | ||||||
| import { ChannelPayload, GuildPayload, InvitePayload } from '../../../mod.ts' | import { ChannelPayload, GuildPayload, InvitePayload } from '../../../mod.ts' | ||||||
| import getChannelByType from '../../utils/getChannelByType.ts' |  | ||||||
| 
 | 
 | ||||||
| export const inviteCreate: GatewayEventHandler = async ( | export const inviteCreate: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  | @ -29,13 +28,12 @@ export const inviteCreate: GatewayEventHandler = async ( | ||||||
|     code: d.code, |     code: d.code, | ||||||
|     guild: cachedGuild, |     guild: cachedGuild, | ||||||
|     // had to use `as ChannelPayload` because the _get method returned `ChannelPayload | undefined` which errored
 |     // had to use `as ChannelPayload` because the _get method returned `ChannelPayload | undefined` which errored
 | ||||||
|     channel: cachedChannel as ChannelPayload, |     channel: (cachedChannel as unknown) as ChannelPayload, | ||||||
|     inviter: d.inviter, |     inviter: d.inviter, | ||||||
|     target_user: d.target_user, |     target_user: d.target_user, | ||||||
|     target_user_type: d.target_user_type, |     target_user_type: d.target_user_type, | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
 |  | ||||||
|   await guild.invites.set(d.code, dataConverted) |   await guild.invites.set(d.code, dataConverted) | ||||||
|   const invite = await guild.invites.get(d.code) |   const invite = await guild.invites.get(d.code) | ||||||
|   gateway.client.emit('inviteCreate', invite) |   gateway.client.emit('inviteCreate', invite) | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| 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 { InviteDeletePayload } from '../../types/gateway.ts' | import { InviteDeletePayload } from '../../types/gateway.ts' | ||||||
|  | import { PartialInvitePayload } from '../../types/invite.ts' | ||||||
|  | import { Channel } from '../../../mod.ts' | ||||||
| 
 | 
 | ||||||
| export const inviteDelete: GatewayEventHandler = async ( | export const inviteDelete: GatewayEventHandler = async ( | ||||||
|   gateway: Gateway, |   gateway: Gateway, | ||||||
|  | @ -13,10 +15,17 @@ export const inviteDelete: GatewayEventHandler = async ( | ||||||
|   if (guild === undefined) return |   if (guild === undefined) return | ||||||
| 
 | 
 | ||||||
|   const cachedInvite = await guild.invites.get(d.code) |   const cachedInvite = await guild.invites.get(d.code) | ||||||
|  |   const cachedChannel = await gateway.client.channels.get(d.channel_id) | ||||||
|  |   const cachedGuild = await gateway.client.guilds.get(d.guild_id!) | ||||||
| 
 | 
 | ||||||
|   // Should not happen but here we go
 |   // TODO(DjDeveloperr): Make it support self-bots and make Guild not always defined
 | ||||||
|   if (cachedInvite === undefined) { |   if (cachedInvite === undefined) { | ||||||
|     return gateway.client.emit('inviteDeleteUncached', cachedInvite) |     const uncachedInvite: PartialInvitePayload = { | ||||||
|  |       guild: (cachedGuild as unknown) as Guild, | ||||||
|  |       channel: (cachedChannel as unknown) as Channel, | ||||||
|  |       code: d.code, | ||||||
|  |     } | ||||||
|  |     return gateway.client.emit('inviteDeleteUncached', uncachedInvite) | ||||||
|   } else { |   } else { | ||||||
|     await guild.invites.delete(d.code) |     await guild.invites.delete(d.code) | ||||||
|     gateway.client.emit('inviteDelete', cachedInvite) |     gateway.client.emit('inviteDelete', cachedInvite) | ||||||
|  |  | ||||||
|  | @ -23,9 +23,10 @@ export class InviteManager extends BaseManager<InvitePayload, Invite> { | ||||||
|     return await new Promise((resolve, reject) => { |     return await new Promise((resolve, reject) => { | ||||||
|       this.client.rest |       this.client.rest | ||||||
|         .get(GUILD_INVITES(this.guild.id)) |         .get(GUILD_INVITES(this.guild.id)) | ||||||
|         .then((data) => { |         .then(async (data) => { | ||||||
|           this.set(id, data as InvitePayload) |           this.set(id, data as InvitePayload) | ||||||
|           resolve(new Invite(this.client, data as InvitePayload)) |           const newInvite = await this.get(data.code) | ||||||
|  |           resolve(newInvite) | ||||||
|         }) |         }) | ||||||
|         .catch((e) => reject(e)) |         .catch((e) => reject(e)) | ||||||
|     }) |     }) | ||||||
|  |  | ||||||
|  | @ -72,7 +72,7 @@ client.on('inviteDelete', (invite: Invite) => { | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| client.on('inviteDeleteUncached', (invite: Invite) => { | client.on('inviteDeleteUncached', (invite: Invite) => { | ||||||
|   console.log(`Invite deleted uncached: ${invite}`) |   console.log(invite) | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| client.on('commandError', console.error) | client.on('commandError', console.error) | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
|  | import { Channel, Guild } from "../../mod.ts" | ||||||
| import { ChannelPayload } from './channel.ts' | import { ChannelPayload } from './channel.ts' | ||||||
| import { GuildPayload } from './guild.ts' | import { GuildPayload } from './guild.ts' | ||||||
| import { UserPayload } from './user.ts' | import { UserPayload } from './user.ts' | ||||||
|  | @ -12,3 +13,9 @@ export interface InvitePayload { | ||||||
|   approximate_presence_count?: number |   approximate_presence_count?: number | ||||||
|   approximate_member_count?: number |   approximate_member_count?: number | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export interface PartialInvitePayload { | ||||||
|  |   code: string | ||||||
|  |   channel: Channel | ||||||
|  |   guild?: Guild | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue