Make guild delete and remove delete function from BaseManager

This commit is contained in:
Helloyunho 2021-01-16 23:22:13 +09:00
parent 19e2020e38
commit 78ae0bbb56
11 changed files with 34 additions and 16 deletions

View file

@ -12,7 +12,7 @@ export const guildMemberRemove: GatewayEventHandler = async (
if (guild === undefined) return if (guild === undefined) return
const member = await guild.members.get(d.user.id) 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) if (member !== undefined) gateway.client.emit('guildMemberRemove', member)
else { else {

View file

@ -25,7 +25,7 @@ export const messageDeleteBulk: GatewayEventHandler = async (
if (message === undefined) uncached.add(id) if (message === undefined) uncached.add(id)
else { else {
messages.set(id, message) messages.set(id, message)
await channel.messages.delete(id) await channel.messages._delete(id)
} }
} }

View file

@ -31,7 +31,7 @@ export const messageReactionRemove: GatewayEventHandler = async (
const reaction = await message.reactions.get(emojiID) const reaction = await message.reactions.get(emojiID)
if (reaction === undefined) return if (reaction === undefined) return
reaction.users.delete(d.user_id) reaction.users._delete(d.user_id)
gateway.client.emit('messageReactionRemove', reaction, user) gateway.client.emit('messageReactionRemove', reaction, user)
} }

View file

@ -24,7 +24,7 @@ export const voiceStateUpdate: GatewayEventHandler = async (
return gateway.client.emit('voiceStateRemoveUncached', { guild, member }) return gateway.client.emit('voiceStateRemoveUncached', { guild, member })
} }
// No longer in the channel, so delete // No longer in the channel, so delete
await guild.voiceStates.delete(d.user_id) await guild.voiceStates._delete(d.user_id)
gateway.client.emit( gateway.client.emit(
'voiceStateRemove', 'voiceStateRemove',
(voiceState as unknown) as VoiceState (voiceState as unknown) as VoiceState

View file

@ -41,11 +41,6 @@ export class BaseManager<T, T2> {
return this.client.cache.delete(this.cacheName, key) 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 */ /** Gets an Array of values from Cache */
async array(): Promise<T2[]> { async array(): Promise<T2[]> {
let arr = await (this.client.cache.array(this.cacheName) as T[]) let arr = await (this.client.cache.array(this.cacheName) as T[])

View file

@ -57,7 +57,7 @@ export class GuildChannelsManager extends BaseChildManager<
async flush(): Promise<boolean> { async flush(): Promise<boolean> {
const arr = await this.array() const arr = await this.array()
for (const elem of arr) { for (const elem of arr) {
this.parent.delete(elem.id) this.parent._delete(elem.id)
} }
return true return true
} }

View file

@ -88,7 +88,7 @@ export class GuildEmojisManager extends BaseChildManager<EmojiPayload, Emoji> {
const arr = await this.array() const arr = await this.array()
for (const elem of arr) { for (const elem of arr) {
const emojiID = elem.id !== null ? elem.id : elem.name const emojiID = elem.id !== null ? elem.id : elem.name
this.parent.delete(emojiID as string) this.parent._delete(emojiID as string)
} }
return true return true
} }

View file

@ -137,17 +137,17 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
} }
async edit( async edit(
guildID: string, guild: Guild | string,
options: GuildModifyOptions, options: GuildModifyOptions,
asRaw: false asRaw: false
): Promise<Guild> ): Promise<Guild>
async edit( async edit(
guildID: string, guild: Guild | string,
options: GuildModifyOptions, options: GuildModifyOptions,
asRaw: true asRaw: true
): Promise<GuildPayload> ): Promise<GuildPayload>
async edit( async edit(
guildID: string, guild: Guild | string,
options: GuildModifyOptions, options: GuildModifyOptions,
asRaw: boolean = false asRaw: boolean = false
): Promise<Guild | GuildPayload> { ): Promise<Guild | GuildPayload> {
@ -175,6 +175,9 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
) { ) {
options.banner = await fetchAuto(options.banner) options.banner = await fetchAuto(options.banner)
} }
if (guild instanceof Guild) {
guild = guild.id
}
const body: GuildModifyPayload = { const body: GuildModifyPayload = {
name: options.name, name: options.name,
@ -184,6 +187,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
explicit_content_filter: options.explicitContentFilter, explicit_content_filter: options.explicitContentFilter,
afk_channel_id: options.afkChannelID, afk_channel_id: options.afkChannelID,
afk_timeout: options.afkTimeout, afk_timeout: options.afkTimeout,
owner_id: options.ownerID,
icon: options.icon, icon: options.icon,
splash: options.splash, splash: options.splash,
banner: options.banner, banner: options.banner,
@ -194,7 +198,7 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
} }
const result: GuildPayload = await this.client.rest.patch( const result: GuildPayload = await this.client.rest.patch(
GUILD(guildID), GUILD(guild),
body body
) )
@ -205,4 +209,15 @@ export class GuildManager extends BaseManager<GuildPayload, Guild> {
return result 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
}
} }

View file

@ -42,7 +42,7 @@ export class MemberRolesManager extends BaseChildManager<RolePayload, Role> {
async flush(): Promise<boolean> { async flush(): Promise<boolean> {
const arr = await this.array() const arr = await this.array()
for (const elem of arr) { for (const elem of arr) {
this.parent.delete(elem.id) this.parent._delete(elem.id)
} }
return true return true
} }

View file

@ -342,6 +342,12 @@ export class Guild extends Base {
return new Guild(this.client, result) 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 { export class GuildIntegration extends Base {

View file

@ -241,6 +241,7 @@ export interface GuildModifyPayload {
afk_channel_id?: string | null afk_channel_id?: string | null
afk_timeout?: number afk_timeout?: number
icon?: string | null icon?: string | null
owner_id?: string
splash?: string | null splash?: string | null
banner?: string | null banner?: string | null
system_channel_id?: string | null system_channel_id?: string | null
@ -258,6 +259,7 @@ export interface GuildModifyOptions {
afkChannelID?: string | null afkChannelID?: string | null
afkTimeout?: number afkTimeout?: number
icon?: string | null icon?: string | null
ownerID?: string
splash?: string | null splash?: string | null
banner?: string | null banner?: string | null
systemChannelID?: string | null systemChannelID?: string | null