@@ -45,7 +45,257 @@ export default new Command({
4545 requiredPermissions : { user : [ ] , bot : [ ] } ,
4646 } ,
4747 LegacyRun : async ( manager , message , args , prefixUsed , commandData ) => {
48- const lang = manager . configs . lang ;
48+ const subCommand = args [ 0 ] ;
49+ const lang = manager . configs . lang ,
50+ commandsConfig = manager . configs . commands ;
51+ const slashCommands = manager . slashCommands ,
52+ legacyCommands = manager . commands ;
53+
54+ switch ( subCommand ) {
55+ case "category" : {
56+ const type = args [ 1 ] || "general" ;
57+ const slashCommandsList = [
58+ ...( await manager . application . commands . fetch ( ) ) . toJSON ( ) ,
59+ ...( await message . guild . commands . fetch ( ) ) . toJSON ( ) ,
60+ ] ,
61+ sortedCommands = legacyCommands
62+ . filter (
63+ ( cmd ) => cmd . commandData . Type ?. toLowerCase ( ) == type . toLowerCase ( )
64+ )
65+ ?. toJSON ( ) ;
66+
67+ const format = Object . entries (
68+ lang . General . Help . AutoCompleteCategory
69+ ) . find ( ( [ key ] ) => key . toLowerCase ( ) == type . toLowerCase ( ) ) ;
70+ const valueToUse = format && format [ 0 ] ? format [ 1 ] : type ;
71+
72+ if ( ! sortedCommands . length )
73+ return message . reply (
74+ Utils . setupMessage ( {
75+ configPath : lang . General . Help . NoCommandsInCategory ,
76+ variables : [
77+ ...Utils . userVariables ( message . member , "user" ) ,
78+ { searchFor : / { t y p e } / g, replaceWith : type } ,
79+ ] ,
80+ } )
81+ ) ;
82+
83+ const messages = [ ] ,
84+ maxPages = Math . ceil ( sortedCommands . length / 10 ) ,
85+ pageIndex = 0 ;
86+ if ( maxPages == 1 ) {
87+ message . reply (
88+ Utils . setupMessage ( {
89+ configPath : lang . General . Help . CommandList ,
90+ variables : [
91+ ...Utils . userVariables ( message . member , "user" ) ,
92+ { searchFor : / { m a x - p a g e } / g, replaceWith : maxPages } ,
93+ { searchFor : / { c u r r e n t - p a g e } / g, replaceWith : 1 } ,
94+ { searchFor : / { c a t e g o r y } / g, replaceWith : valueToUse } ,
95+ {
96+ searchFor : / { d a t a } / g,
97+ replaceWith : sortedCommands
98+ . map ( ( cmd , i ) => {
99+ const slashCmd = slashCommandsList . find (
100+ ( x ) => x . name == cmd . commandData . Name
101+ ) ;
102+ return [
103+ `\`${ i + 1 } ]\` **${ Utils . capitalizeFirstLetter (
104+ cmd . commandData . Name
105+ ) } ** - ${ cmd . commandData . Description } `,
106+ getOptions ( slashCmd ) ,
107+ ]
108+ . filter ( ( x ) => x )
109+ . join ( "\n" ) ;
110+ } )
111+ . join ( "\n\n" ) ,
112+ } ,
113+ ] ,
114+ } )
115+ ) ;
116+ } else {
117+ for ( let i = 0 ; i < maxPages ; i ++ ) {
118+ const cmds = Utils . paginateArray ( sortedCommands , 10 , i + 1 ) ;
119+ messages . push (
120+ Utils . setupMessage ( {
121+ configPath : lang . General . Help . CommandList ,
122+ variables : [
123+ ...Utils . userVariables ( message . member , "user" ) ,
124+ { searchFor : / { m a x - p a g e } / g, replaceWith : maxPages } ,
125+ { searchFor : / { c u r r e n t - p a g e } / g, replaceWith : i + 1 } ,
126+ { searchFor : / { c a t e g o r y } / g, replaceWith : valueToUse } ,
127+ {
128+ searchFor : / { d a t a } / g,
129+ replaceWith : cmds
130+ . map ( ( cmd , i ) => {
131+ const slashCmd = slashCommandsList . find (
132+ ( x ) => x . name == cmd . commandData . Name
133+ ) ;
134+ return [
135+ `\`${ i + 1 } ]\` **${ Utils . capitalizeFirstLetter (
136+ cmd . commandData . Name
137+ ) } ** - ${ cmd . commandData . Description } `,
138+ getOptions ( slashCmd ) ,
139+ ]
140+ . filter ( ( x ) => x )
141+ . join ( "\n" ) ;
142+ } )
143+ . join ( "\n\n" ) ,
144+ } ,
145+ ] ,
146+ } )
147+ ) ;
148+ }
149+
150+ const getRow = ( disabled ) =>
151+ new Discord . ActionRowBuilder ( ) . addComponents ( [
152+ new Discord . ButtonBuilder ( {
153+ customId : "bryanbot_help_next" ,
154+ style : 1 ,
155+ emoji : "⏮" ,
156+ } ) . setDisabled ( disabled ? disabled : pageIndex == 0 ) ,
157+ new Discord . ButtonBuilder ( {
158+ customId : "bryanbot_help_last" ,
159+ style : 1 ,
160+ emoji : "⏭" ,
161+ } ) . setDisabled (
162+ disabled ? disabled : pageIndex == messages . length - 1
163+ ) ,
164+ ] ) ;
165+ let queueMSG = { ...messages [ pageIndex ] , components : [ getRow ( ) ] } ;
166+
167+ message . reply ( queueMSG ) . then ( async ( msg ) => {
168+ const collector = await msg . createMessageComponentCollector ( {
169+ filter : ( i ) => i . user . id == message . author . id ,
170+ time : 2 * 60 * 1000 ,
171+ componentType : "BUTTON" ,
172+ } ) ;
173+ collector . on ( "collect" , async ( interaction ) => {
174+ if (
175+ ! [ "bryanbot_help_next" , "bryanbot_help_last" ] . includes (
176+ interaction . customId
177+ )
178+ )
179+ return ;
180+
181+ if (
182+ interaction . customId == "bryanbot_help_last" &&
183+ pageIndex > 0
184+ ) {
185+ -- pageIndex ;
186+ } else if (
187+ interaction . customId == "bryanbot_help_next" &&
188+ pageIndex < maxPages - 1
189+ ) {
190+ ++ pageIndex ;
191+ }
192+
193+ interaction . update ( {
194+ ...messages [ pageIndex ] ,
195+ components : [ getRow ( ) ] ,
196+ } ) ;
197+ } ) ;
198+
199+ collector . on ( "end" , async ( ) =>
200+ msg . edit ( { ...messages [ pageIndex ] , components : [ getRow ( true ) ] } )
201+ ) ;
202+ } ) ;
203+ }
204+
205+ break ;
206+ }
207+ case "command" : {
208+ const command = args [ 1 ] || "help" ;
209+
210+ const legacyCommand = legacyCommands . get ( command ) ,
211+ slashCommandsList = [
212+ ...( await manager . application . commands . fetch ( ) ) . toJSON ( ) ,
213+ ...( await message . guild . commands . fetch ( ) ) . toJSON ( ) ,
214+ ] ;
215+
216+ const slashCommandApplication = slashCommandsList . find (
217+ ( cmd ) => cmd . name === command
218+ ) ;
219+
220+ if ( ! legacyCommand )
221+ return message . reply (
222+ Utils . setupMessage ( {
223+ configPath : lang . General . Help . CommandNotFound ,
224+ variables : Utils . userVariables ( message . member , "user" ) ,
225+ } )
226+ ) ;
227+
228+ const commandData = legacyCommand . commandData ;
229+ if ( ! Array . isArray ( commandData . Permission ) )
230+ commandData . Permission = [ commandData . Permission ] ;
231+ const commandVariables = [
232+ { searchFor : / { p r e f i x U s e d } / g, replaceWith : "/" } ,
233+ { searchFor : / { c m d - n a m e } / g, replaceWith : commandData . Name } ,
234+ { searchFor : / { c m d - t y p e } / g, replaceWith : commandData . Type } ,
235+ { searchFor : / { c m d - u s a g e } / g, replaceWith : commandData . Usage } ,
236+ {
237+ searchFor : / { c m d - c o o l d o w n } / g,
238+ replaceWith : commandData . Cooldown ? ms ( commandData . Cooldown ) : "❎" ,
239+ } ,
240+ {
241+ searchFor : / { c m d - d e s c r i p t i o n } / g,
242+ replaceWith : commandData . Description ,
243+ } ,
244+ {
245+ searchFor : / { c m d - d m O n l y } / g,
246+ replaceWith : legacyCommand . commandConfig . dmOnly ? "✅" : "❎" ,
247+ } ,
248+ {
249+ searchFor : / { c m d - g u i l d O n l y } / g,
250+ replaceWith : legacyCommand . commandConfig . guildOnly ? "✅" : "❎" ,
251+ } ,
252+ {
253+ searchFor : / { c m d - i s S l a s h C o m m a n d } / g,
254+ replaceWith : Array . isArray ( commandData . Arguments ) ? "✅" : "❎" ,
255+ } ,
256+ {
257+ searchFor : / { c m d - s l a s h M e n t i o n s } / g,
258+ replaceWith : slashCommandApplication
259+ ? getOptions ( slashCommandApplication )
260+ : "❎" ,
261+ } ,
262+ {
263+ searchFor : / { c m d - p e r m i s s i o n } / g,
264+ replaceWith : commandData . Permission . map ( ( role ) => {
265+ if ( role === "@everyone" ) return `@everyone` ;
266+
267+ const guildRole = Utils . findRole ( message . guild , role , true ) ;
268+ if ( guildRole ) return guildRole . toString ( ) ;
269+ } ) . join ( ", " ) ,
270+ } ,
271+ ] ;
272+
273+ message . reply (
274+ Utils . setupMessage ( {
275+ configPath : lang . General . Help . CommandInfo ,
276+ variables : [
277+ ...Utils . userVariables ( message . member , "user" ) ,
278+ ...commandVariables ,
279+ ] ,
280+ } )
281+ ) ;
282+ break ;
283+ }
284+ default : {
285+ message . reply (
286+ Utils . setupMessage ( {
287+ configPath : lang . General . Help . InvalidUsage ,
288+ variables : [
289+ ...Utils . botVariables ( manager ) ,
290+ ...Utils . guildVariables ( message . guild ) ,
291+ ...Utils . userVariables ( message . member ) ,
292+ ...Utils . channelVariables ( message . channel ) ,
293+ { searchFor : / { p r e f i x U s e d } / , replaceWith : prefixUsed } ,
294+ ] ,
295+ } )
296+ ) ;
297+ }
298+ }
49299 } ,
50300 InteractionRun : async ( manager , interaction , commandData ) => {
51301 const subCommand = interaction . options . getSubcommand ( ) ;
0 commit comments