| 8 | } |
| 9 | |
| 10 | async run(channel) { |
| 11 | if (!channel.guild) return; |
| 12 | |
| 13 | let executor; |
| 14 | if (channel.guild.me.hasPermission('VIEW_AUDIT_LOG')) { |
| 15 | const auditLog = await channel.guild.fetchAuditLogs(); |
| 16 | const logEntry = await auditLog.entries.first(); |
| 17 | |
| 18 | if (logEntry.action === 'CHANNEL_DELETE') executor = logEntry ? logEntry.executor : undefined; |
| 19 | } |
| 20 | |
| 21 | if (channel.guild.settings.get('channels.log') && channel.guild.settings.get('logs.events.channelDelete')) await this.serverLog(channel, executor); |
| 22 | |
| 23 | // Config checks |
| 24 | // Checks server and client configs to see if the deleted channel has been configured anywhere. If it has, resets or removes it. |
| 25 | if (channel.id === channel.guild.settings.get('channels.log')) await channel.guild.settings.reset('channels.log'); |
| 26 | if (channel.id === channel.guild.settings.get('greetings.welcomeChannel')) await channel.guild.settings.reset('greetings.welcomeChannel'); |
| 27 | if (channel.id === channel.guild.settings.get('greetings.dismissChannel')) await channel.guild.settings.reset('greetings.dismissChannel'); |
| 28 | if (channel.id === channel.guild.settings.get('boards.starboard.starboardChannel')) await channel.guild.settings.reset('boards.starboard.starboardChannel'); |
| 29 | if (channel.id === channel.guild.settings.get('boards.pinboard.pinboardChannel')) await channel.guild.settings.reset('boards.pinboard.pinboardChannel'); |
| 30 | if (channel.id === channel.guild.settings.get('twitch.twitchNotifsChannel')) await channel.guild.settings.reset('twitch.twitchNotifsChannel'); |
| 31 | |
| 32 | // Reset won't work for arrays of channel IDs, and we can't use update() with a deleted channel. |
| 33 | if (channel.guild.settings.get('boards.starboard.starboardIgnoredChannels').includes(channel.id)) { |
| 34 | // Capture old list of channels |
| 35 | const oldList = channel.guild.settings.get('boards.starboard.starboardIgnoredChannels'); |
| 36 | |
| 37 | // Reset current list |
| 38 | await channel.guild.settings.reset('boards.starboard.starboardIgnoredChannels'); |
| 39 | |
| 40 | // Declare new list without the deleted channel and re-add the other ones |
| 41 | const newList = oldList.filter(chnl => chnl !== channel.id); |
| 42 | for (let i = 0; i < newList.length; i++) { |
| 43 | await channel.guild.settings.sync(); |
| 44 | await channel.guild.settings.update('boards.starboard.starboardIgnoredChannels', newList[i]); |
| 45 | } |
| 46 | } |
| 47 | if (channel.guild.settings.get('boards.pinboard.pinboardIgnoredChannels').includes(channel.id)) { |
| 48 | // Capture old list of channels |
| 49 | const oldList = channel.guild.settings.get('boards.pinboard.pinboardIgnoredChannels'); |
| 50 | |
| 51 | // Reset current list |
| 52 | await channel.guild.settings.reset('boards.pinboard.pinboardIgnoredChannels'); |
| 53 | |
| 54 | // Declare new list without the deleted channel and re-add the other ones |
| 55 | const newList = oldList.filter(chnl => chnl !== channel.id); |
| 56 | for (let i = 0; i < newList.length; i++) { |
| 57 | await channel.guild.settings.sync(); |
| 58 | await channel.guild.settings.update('boards.pinboard.pinboardIgnoredChannels', newList[i]); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Add check for the global log channel, just in case. |
| 63 | if (channel.id === this.client.settings.get('channels.globalLog')) await this.client.settings.reset('channels.globalLog'); |
| 64 | |
| 65 | return; |
| 66 | } |
| 67 | |