Make guild delete and remove delete function from BaseManager
This commit is contained in:
		
							parent
							
								
									19e2020e38
								
							
						
					
					
						commit
						78ae0bbb56
					
				
					 11 changed files with 34 additions and 16 deletions
				
			
		|  | @ -12,7 +12,7 @@ export const guildMemberRemove: GatewayEventHandler = async ( | |||
|   if (guild === undefined) return | ||||
| 
 | ||||
|   const member = await guild.members.get(d.user.id) | ||||
|   await guild.members.delete(d.user.id) | ||||
|   await guild.members._delete(d.user.id) | ||||
| 
 | ||||
|   if (member !== undefined) gateway.client.emit('guildMemberRemove', member) | ||||
|   else { | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ export const messageDeleteBulk: GatewayEventHandler = async ( | |||
|     if (message === undefined) uncached.add(id) | ||||
|     else { | ||||
|       messages.set(id, message) | ||||
|       await channel.messages.delete(id) | ||||
|       await channel.messages._delete(id) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -31,7 +31,7 @@ export const messageReactionRemove: GatewayEventHandler = async ( | |||
|   const reaction = await message.reactions.get(emojiID) | ||||
|   if (reaction === undefined) return | ||||
| 
 | ||||
|   reaction.users.delete(d.user_id) | ||||
|   reaction.users._delete(d.user_id) | ||||
| 
 | ||||
|   gateway.client.emit('messageReactionRemove', reaction, user) | ||||
| } | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ export const voiceStateUpdate: GatewayEventHandler = async ( | |||
|       return gateway.client.emit('voiceStateRemoveUncached', { guild, member }) | ||||
|     } | ||||
|     // No longer in the channel, so delete
 | ||||
|     await guild.voiceStates.delete(d.user_id) | ||||
|     await guild.voiceStates._delete(d.user_id) | ||||
|     gateway.client.emit( | ||||
|       'voiceStateRemove', | ||||
|       (voiceState as unknown) as VoiceState | ||||
|  |  | |||
|  | @ -41,11 +41,6 @@ export class BaseManager<T, T2> { | |||
|     return this.client.cache.delete(this.cacheName, key) | ||||
|   } | ||||
| 
 | ||||
|   /** Alias to _delete (cache) for compatibility purposes */ | ||||
|   async delete(key: string): Promise<boolean> { | ||||
|     return await this._delete(key) | ||||
|   } | ||||
| 
 | ||||
|   /** Gets an Array of values from Cache */ | ||||
|   async array(): Promise<T2[]> { | ||||
|     let arr = await (this.client.cache.array(this.cacheName) as T[]) | ||||
|  |  | |||
|  | @ -57,7 +57,7 @@ export class GuildChannelsManager extends BaseChildManager< | |||
|   async flush(): Promise<boolean> { | ||||
|     const arr = await this.array() | ||||
|     for (const elem of arr) { | ||||
|       this.parent.delete(elem.id) | ||||
|       this.parent._delete(elem.id) | ||||
|     } | ||||
|     return true | ||||
|   } | ||||
|  |  | |||
|  | @ -88,7 +88,7 @@ export class GuildEmojisManager extends BaseChildManager<EmojiPayload, Emoji> { | |||
|     const arr = await this.array() | ||||
|     for (const elem of arr) { | ||||
|       const emojiID = elem.id !== null ? elem.id : elem.name | ||||
|       this.parent.delete(emojiID as string) | ||||
|       this.parent._delete(emojiID as string) | ||||
|     } | ||||
|     return true | ||||
|   } | ||||
|  |  | |||
|  | @ -137,17 +137,17 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | |||
|   } | ||||
| 
 | ||||
|   async edit( | ||||
|     guildID: string, | ||||
|     guild: Guild | string, | ||||
|     options: GuildModifyOptions, | ||||
|     asRaw: false | ||||
|   ): Promise<Guild> | ||||
|   async edit( | ||||
|     guildID: string, | ||||
|     guild: Guild | string, | ||||
|     options: GuildModifyOptions, | ||||
|     asRaw: true | ||||
|   ): Promise<GuildPayload> | ||||
|   async edit( | ||||
|     guildID: string, | ||||
|     guild: Guild | string, | ||||
|     options: GuildModifyOptions, | ||||
|     asRaw: boolean = false | ||||
|   ): Promise<Guild | GuildPayload> { | ||||
|  | @ -175,6 +175,9 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | |||
|     ) { | ||||
|       options.banner = await fetchAuto(options.banner) | ||||
|     } | ||||
|     if (guild instanceof Guild) { | ||||
|       guild = guild.id | ||||
|     } | ||||
| 
 | ||||
|     const body: GuildModifyPayload = { | ||||
|       name: options.name, | ||||
|  | @ -184,6 +187,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | |||
|       explicit_content_filter: options.explicitContentFilter, | ||||
|       afk_channel_id: options.afkChannelID, | ||||
|       afk_timeout: options.afkTimeout, | ||||
|       owner_id: options.ownerID, | ||||
|       icon: options.icon, | ||||
|       splash: options.splash, | ||||
|       banner: options.banner, | ||||
|  | @ -194,7 +198,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | |||
|     } | ||||
| 
 | ||||
|     const result: GuildPayload = await this.client.rest.patch( | ||||
|       GUILD(guildID), | ||||
|       GUILD(guild), | ||||
|       body | ||||
|     ) | ||||
| 
 | ||||
|  | @ -205,4 +209,15 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> { | |||
|       return result | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   async delete(guild: Guild | string): Promise<Guild | undefined> { | ||||
|     if (guild instanceof Guild) { | ||||
|       guild = guild.id | ||||
|     } | ||||
| 
 | ||||
|     const oldGuild = await this.get(guild) | ||||
| 
 | ||||
|     await this.client.rest.delete(GUILD(guild)) | ||||
|     return oldGuild | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -42,7 +42,7 @@ export class MemberRolesManager extends BaseChildManager<RolePayload, Role> { | |||
|   async flush(): Promise<boolean> { | ||||
|     const arr = await this.array() | ||||
|     for (const elem of arr) { | ||||
|       this.parent.delete(elem.id) | ||||
|       this.parent._delete(elem.id) | ||||
|     } | ||||
|     return true | ||||
|   } | ||||
|  |  | |||
|  | @ -342,6 +342,12 @@ export class Guild extends Base { | |||
| 
 | ||||
|     return new Guild(this.client, result) | ||||
|   } | ||||
| 
 | ||||
|   async delete(): Promise<Guild> { | ||||
|     const result = await this.client.guilds.delete(this.id) | ||||
| 
 | ||||
|     return result === undefined ? this : result | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export class GuildIntegration extends Base { | ||||
|  |  | |||
|  | @ -241,6 +241,7 @@ export interface GuildModifyPayload { | |||
|   afk_channel_id?: string | null | ||||
|   afk_timeout?: number | ||||
|   icon?: string | null | ||||
|   owner_id?: string | ||||
|   splash?: string | null | ||||
|   banner?: string | null | ||||
|   system_channel_id?: string | null | ||||
|  | @ -258,6 +259,7 @@ export interface GuildModifyOptions { | |||
|   afkChannelID?: string | null | ||||
|   afkTimeout?: number | ||||
|   icon?: string | null | ||||
|   ownerID?: string | ||||
|   splash?: string | null | ||||
|   banner?: string | null | ||||
|   systemChannelID?: string | null | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue