(interaction, client)
| 6 | |
| 7 | import { InteractionHelper } from '../../../utils/interactionHelper.js'; |
| 8 | export async function handleList(interaction, client) { |
| 9 | const guild = interaction.guild; |
| 10 | |
| 11 | try { |
| 12 | await InteractionHelper.safeDefer(interaction); |
| 13 | } catch (error) { |
| 14 | logger.error("Failed to defer reply:", error); |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | if (!interaction.member.permissions.has(PermissionFlagsBits.ManageChannels)) { |
| 19 | await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'You need **Manage Channels** permission to view counters.' }).catch(logger.error); |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | try { |
| 24 | const counters = await getServerCounters(client, guild.id); |
| 25 | const stats = await getGuildCounterStats(guild); |
| 26 | |
| 27 | const validCounters = []; |
| 28 | const orphanedCounters = []; |
| 29 | |
| 30 | for (const counter of counters) { |
| 31 | const channel = guild.channels.cache.get(counter.channelId); |
| 32 | if (channel) { |
| 33 | validCounters.push(counter); |
| 34 | } else { |
| 35 | orphanedCounters.push(counter); |
| 36 | logger.info(`Removing orphaned counter ${counter.id} (type: ${counter.type}, deleted channel: ${counter.channelId}) from guild ${guild.id}`); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (orphanedCounters.length > 0) { |
| 41 | await saveServerCounters(client, guild.id, validCounters); |
| 42 | logger.info(`Cleaned up ${orphanedCounters.length} orphaned counter(s) from guild ${guild.id}`); |
| 43 | } |
| 44 | |
| 45 | if (validCounters.length === 0) { |
| 46 | const embed = createEmbed({ |
| 47 | title: "Server Counters", |
| 48 | description: "No counters have been set up for this server yet.\n\nUse `/counter create` to set up your first counter!", |
| 49 | color: getColor('warning') |
| 50 | }); |
| 51 | |
| 52 | embed.addFields({ |
| 53 | name: "**Available Counter Types**", |
| 54 | value: "**Members + Bots** - Total server members\n **Members Only** - Human members only\n **Bots Only** - Bot members only", |
| 55 | inline: false |
| 56 | }); |
| 57 | |
| 58 | embed.addFields({ |
| 59 | name: "**Usage Examples**", |
| 60 | value: "`/counter create type:members channel_type:voice category:Stats`\n`/counter create type:bots channel_type:text category:Server Info`\n`/counter list`", |
| 61 | inline: false |
| 62 | }); |
| 63 | |
| 64 | embed.setFooter({ |
| 65 | text: "Counter System • Automatic updates every 15 minutes" |
no test coverage detected