diff --git a/packages/core/src/Structures/Client.ts b/packages/core/src/Structures/Client.ts index 33b301f2..2347b2a2 100644 --- a/packages/core/src/Structures/Client.ts +++ b/packages/core/src/Structures/Client.ts @@ -408,11 +408,14 @@ export class Client extends EventEmitter { }); if ("permission_overwrites" in channel && channel.permission_overwrites !== undefined) { + const lists = channel.permission_overwrites.map(x => x.id); await this.store.delete(schema.channelsOverwrite).where( - and( - eq(schema.channelsOverwrite.channelId, channel.id), - notInArray(schema.channelsOverwrite.userOrRole, channel.permission_overwrites.map(x => x.id)) - ) + lists.length > 0 + ? and( + eq(schema.channelsOverwrite.channelId, channel.id), + notInArray(schema.channelsOverwrite.userOrRole, lists) + ) + : eq(schema.channelsOverwrite.channelId, channel.id) ); if (channel.permission_overwrites.length > 0) { diff --git a/services/kanao-cache/src/Listeners/Caches/Channels/ChannelUpdateListener.ts b/services/kanao-cache/src/Listeners/Caches/Channels/ChannelUpdateListener.ts index 08946443..5753d23a 100644 --- a/services/kanao-cache/src/Listeners/Caches/Channels/ChannelUpdateListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/Channels/ChannelUpdateListener.ts @@ -38,11 +38,14 @@ export class ChannelUpdateListener extends Listener { }); if ("permission_overwrites" in payload.data.d && payload.data.d.permission_overwrites !== undefined) { + const lists = payload.data.d.permission_overwrites.map(x => x.id); await this.container.client.drizzle.delete(channelsOverwrite).where( - and( - eq(channelsOverwrite.channelId, payload.data.d.id), - notInArray(channelsOverwrite.userOrRole, payload.data.d.permission_overwrites.map(x => x.id)) - ) + lists.length > 0 + ? and( + eq(channelsOverwrite.channelId, payload.data.d.id), + notInArray(channelsOverwrite.userOrRole, lists) + ) + : eq(channelsOverwrite.channelId, payload.data.d.id) ); if (payload.data.d.permission_overwrites.length > 0) { diff --git a/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMemberUpdateListener.ts b/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMemberUpdateListener.ts index 7d10f813..ba8230dc 100644 --- a/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMemberUpdateListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMemberUpdateListener.ts @@ -68,11 +68,14 @@ export class GuildMemberUpdateListener extends Listener { } }); + const lists = payload.data.d.roles; await this.container.client.drizzle.delete(memberRoles).where( - and( - eq(memberRoles.memberId, payload.data.d.user.id), - notInArray(memberRoles.roleId, payload.data.d.roles) - ) + lists.length > 0 + ? and( + eq(memberRoles.memberId, payload.data.d.user.id), + notInArray(memberRoles.roleId, lists) + ) + : eq(memberRoles.memberId, payload.data.d.user.id) ); if (payload.data.d.roles.length > 0) { diff --git a/services/kanao-cache/src/Listeners/Caches/Guilds/GuildCreateListener.ts b/services/kanao-cache/src/Listeners/Caches/Guilds/GuildCreateListener.ts index 741bc10b..5e87f495 100644 --- a/services/kanao-cache/src/Listeners/Caches/Guilds/GuildCreateListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/Guilds/GuildCreateListener.ts @@ -241,11 +241,14 @@ export class GuildCreateListener extends Listener { "permission_overwrites" in ch && ch.permission_overwrites !== undefined ) { + const lists = ch.permission_overwrites.map(x => x.id); await this.container.client.drizzle.delete(channelsOverwrite).where( - and( - eq(channelsOverwrite.channelId, ch.id), - notInArray(channelsOverwrite.userOrRole, ch.permission_overwrites.map(x => x.id)) - ) + lists.length > 0 + ? and( + eq(channelsOverwrite.channelId, ch.id), + notInArray(channelsOverwrite.userOrRole, lists) + ) + : eq(channelsOverwrite.channelId, ch.id) ); if (ch.permission_overwrites.length > 0) {