1
1
import { container } from "@sapphire/framework" ;
2
- import { inlineCodeBlock , isNullishOrEmpty } from "@sapphire/utilities" ;
3
- import { ChannelType , PermissionFlagsBits , StageChannel , VoiceChannel , type AuditLogEvent , type Collection , type Guild , type GuildBasedChannel , type GuildChannel , type Message } from "discord.js" ;
2
+ import { inlineCodeBlock } from "@sapphire/utilities" ;
3
+ import { PermissionFlagsBits , StageChannel , VoiceChannel , type AuditLogEvent , type Guild , type Message } from "discord.js" ;
4
4
5
5
/**
6
6
* Get the executor user from the last audit log entry of specific type
@@ -117,57 +117,3 @@ export function getPermissionString(permission: string) {
117
117
default : return undefined ;
118
118
}
119
119
}
120
-
121
- // These are just here for the sorting function below
122
- const textChannelTypes = [ ChannelType . GuildText , ChannelType . GuildAnnouncement , ChannelType . GuildForum ] ;
123
- // const voiceChannelTypes = [ChannelType.GuildVoice, ChannelType.GuildStageVoice];
124
-
125
- /**
126
- * Sorts a collection of GuildBasedChannels into the order they'd be displayed in the Discord client
127
- * @param inputChannels The collection of channels you want to be sorted client-style
128
- */
129
- export function clientStyleChannelSort ( inputChannels : Collection < string , GuildBasedChannel > ) {
130
- // First, make sure we don't have any threads--they don't have position properties
131
- const allChannels = inputChannels . filter ( ( channel ) => channel . type !== ChannelType . PrivateThread && channel . type !== ChannelType . PublicThread ) ;
132
- // Now that we know we have the right channels, just ignore me constantly reassigning types to them...
133
- const levelZero = allChannels . clone ( ) . filter ( ( channel ) => ! channel . parentId ) ;
134
- const levelOne : { parentID : string , children : Collection < string , GuildBasedChannel > } [ ] = [ ] ;
135
-
136
- levelZero . forEach ( ( l0Channel ) => {
137
- // Now we'll build collections of nested channels and group them by their parent
138
- const l1Channels = allChannels . clone ( ) . filter ( ( l1Channel ) => l1Channel . parentId === l0Channel . id ) ;
139
- // Now we'll run our three-way sort on these channels
140
- // Special Channels (eg: Forums/Stages) can only exist in categories
141
- // They can also freely mix with their respective types (Forums w/ Text, Stages w/ Voice)
142
- // So we do a slightly different sort for child channels than for parent/non-nested ones
143
- l1Channels . sort ( ( a , b ) => {
144
- const chA = a as any as GuildChannel ;
145
- const chB = b as any as GuildChannel ;
146
- const chATypeScore = textChannelTypes . includes ( chA . type ) ? 1 : 0 ;
147
- const chBTypeScore = textChannelTypes . includes ( chA . type ) ? 1 : 0 ;
148
- return chATypeScore - chBTypeScore || chA . rawPosition - chB . rawPosition || chA . createdTimestamp - chB . createdTimestamp ;
149
- } ) ;
150
- levelOne . push ( { parentID : l0Channel . id , children : l1Channels } ) ;
151
- } ) ;
152
-
153
- // And we'll run our more strict three-way sort on the parent/non-nested channels
154
- levelZero . sort ( ( a , b ) => {
155
- const chA = a as any as GuildChannel ;
156
- const chB = b as any as GuildChannel ;
157
- return chA . type - chB . type || chA . rawPosition - chB . rawPosition || chA . createdTimestamp - chB . createdTimestamp
158
- } ) ;
159
-
160
- const sortedChannels : GuildChannel [ ] = [ ] ;
161
-
162
- // Now that everything's sorted, we're just pushing every channel into an array in order
163
- levelZero . forEach ( ( channel ) => {
164
- sortedChannels . push ( channel as any as GuildChannel ) ;
165
- const childrenContainer = levelOne . find ( ( obj ) => obj . parentID === channel . id ) ;
166
- if ( isNullishOrEmpty ( childrenContainer ) || ! childrenContainer ?. children . size ) return ;
167
- childrenContainer . children . forEach ( ( childChannel ) => {
168
- sortedChannels . push ( childChannel as any as GuildChannel ) ;
169
- } ) ;
170
- } ) ;
171
-
172
- return sortedChannels ;
173
- }
0 commit comments