@@ -45,90 +45,91 @@ if (cus !== null) {
45
45
}
46
46
47
47
exports . helpHandle = function ( msg , suffix ) {
48
- var msgArray = [ ]
49
- var msgArraytwo = [ ]
50
- var cmdone = [ ]
48
+ var sorts = {
49
+ 0 : [
50
+ '[Available commands]\n'
51
+ ]
52
+ }
53
+ let counter = 0
51
54
if ( ! suffix ) {
52
55
for ( var index in commands ) {
53
- if ( commands [ index ] . hidden || commands [ index ] . level === 'master' ) {
54
- continue
55
- } else {
56
- cmdone . push ( commands [ index ] . name + ' = "' + commands [ index ] . help + '"' )
56
+ if ( ! commands [ index ] . hidden && commands [ index ] . level !== 'master' ) {
57
+ if ( sorts [ counter ] . join ( '\n' ) . length > 1750 ) {
58
+ counter ++
59
+ sorts [ counter ] = [ ]
60
+ }
61
+ sorts [ counter ] . push ( index + ' = "' + commands [ index ] . help + '"' )
57
62
}
58
63
}
59
- var cmdtwo = cmdone . splice ( 0 , cmdone . length / 2 )
60
- msgArray . push ( '**Available commands:** \n' )
61
- msgArray . push ( '```ini' )
62
- msgArray . push ( cmdone . sort ( ) . join ( '\n' ) + '\n' )
63
- msgArray . push ( '```' )
64
- msgArraytwo . push ( '```ini' )
65
- msgArraytwo . push ( cmdtwo . sort ( ) . join ( '\n' ) + '\n' )
66
- msgArraytwo . push ( '```' )
67
- msgArraytwo . push ( 'If you want more information on the commands, check the command reference at http://docs.thesharks.xyz/commands.' )
68
- msgArraytwo . push ( 'For further questions, join our server: https://discord.gg/wildbot' )
69
- msgArraytwo . push ( 'Like what we do? Consider supporting my developer at Patreon! <https://www.patreon.com/Dougley>' )
64
+ var misc = [
65
+ 'If you want more information on the commands, check the command reference at http://docs.thesharks.xyz/commands.' ,
66
+ 'For further questions, join our server: discord.gg/wildbot' ,
67
+ 'Like what we do? Consider supporting my developer at Patreon! <https://www.patreon.com/Dougley>'
68
+ ]
70
69
msg . author . openDM ( ) . then ( ( y ) => {
71
70
if ( ! msg . isPrivate ) {
72
71
msg . channel . sendMessage ( 'Help is underway ' + msg . author . mention + '!' )
73
72
}
74
- y . sendMessage ( msgArray . join ( '\n' ) )
75
- y . sendMessage ( msgArraytwo . join ( '\n' ) )
73
+ for ( var r in sorts ) {
74
+ y . sendMessage ( `\`\`\`ini\n${ sorts [ r ] . sort ( ) . join ( '\n' ) } \n\`\`\`` ) // FIXME: The entire commands array should sort instead of the sorts one
75
+ }
76
+ y . sendMessage ( misc . join ( '\n' ) )
76
77
} ) . catch ( ( e ) => {
77
78
Logger . error ( e )
78
79
msg . channel . sendMessage ( 'Well, this is awkward, something went wrong while trying to PM you. Do you have them enabled on this server?' )
79
80
} )
80
81
} else if ( suffix ) {
81
82
if ( commands [ suffix ] || alias [ suffix ] ) {
82
- var comad
83
- if ( alias [ suffix ] ) {
84
- comad = alias [ suffix ]
85
- } else {
86
- comad = commands [ suffix ]
87
- }
88
- if ( comad . level === 'master' && require ( '../config.json' ) . permissions . master . indexOf ( msg . author . id ) === - 1 ) {
89
- msg . reply ( 'this command is not for you to use, therefor I will not tell you how to use it.' )
90
- } else {
91
- msgArray = [ ]
92
- msgArray . push ( 'Command name `' + comad . name + '`' )
93
- msgArray . push ( 'What this does: `' + comad . help + '`\n' )
94
- msgArray . push ( 'Example:' )
95
- if ( comad . hasOwnProperty ( 'usage' ) ) {
96
- msgArray . push ( '```' + `${ require ( '../config.json' ) . settings . prefix } ${ comad . name } ${ comad . usage } ` + '```' )
97
- } else {
98
- msgArray . push ( '```' + `${ require ( '../config.json' ) . settings . prefix } ${ comad . name } ` + '```' )
99
- }
100
- msgArray . push ( `**Required access level**: ${ comad . level } ` )
101
- if ( comad . hasOwnProperty ( 'aliases' ) ) {
102
- msgArray . push ( `**Aliases for this command**: ${ comad . aliases . join ( ', ' ) } .` )
103
- }
104
- if ( comad . hasOwnProperty ( 'hidden' ) ) {
105
- msgArray . push ( '*Shh, this is a secret command.*' )
106
- }
107
- if ( comad . hasOwnProperty ( 'timeout' ) ) {
108
- msgArray . push ( `*This command has a timeout of ${ comad . timeout } seconds.*` )
109
- }
110
- if ( comad . hasOwnProperty ( 'nsfw' ) ) {
111
- msgArray . push ( '*This command is NSFW.*' )
83
+ var c = ( commands [ suffix ] ) ? commands [ suffix ] : alias [ suffix ]
84
+ var attributes = [ ]
85
+ var name
86
+ for ( var x in commands ) {
87
+ if ( commands [ x ] === c ) {
88
+ name = x
89
+ break
112
90
}
113
- if ( comad . hasOwnProperty ( 'noDM' ) ) {
114
- msgArray . push ( '*This command cannot be used in DM.*' )
115
- }
116
- if ( comad . name === 'meme' ) {
117
- var str = '**Currently available memes:\n**'
118
- var meme = require ( './commands/memes.json' )
119
- for ( var m in meme ) {
120
- str += m + ', '
91
+ }
92
+ var def = [
93
+ `Command name: \`${ name } \`` ,
94
+ `What this does: \`${ c . help } \`` ,
95
+ 'Example:' ,
96
+ '```' ,
97
+ `${ ( c . usage ) ? config . settings . prefix + name + ' ' + c . usage : config . settings . prefix + name } ` ,
98
+ '```' ,
99
+ `**Required access level**: ${ c . level } ` ,
100
+ `${ ( c . aliases ) ? '**Aliases for this command**: ' + c . aliases . join ( ', ' ) + '\n' : '' } `
101
+ ]
102
+ for ( var attribute in c ) {
103
+ switch ( attribute ) {
104
+ case 'noDM' : {
105
+ if ( c [ attribute ] === true ) attributes . push ( '*This command cannot be used in DMs.*' )
106
+ break
107
+ }
108
+ case 'hidden' : {
109
+ if ( c [ attribute ] === true ) attributes . push ( '*This is a hidden command.*' )
110
+ break
111
+ }
112
+ case 'nsfw' : {
113
+ if ( c [ attribute ] === true ) attributes . push ( '*This command is NSFW*' )
114
+ break
121
115
}
122
- msgArray . push ( str . substring ( 0 , str . length - 2 ) )
116
+ case 'timeout' : {
117
+ attributes . push ( `*This command has a timeout of ${ c . timeout } seconds*` )
118
+ break
119
+ }
120
+ }
121
+ }
122
+ if ( name === 'meme' ) {
123
+ var str = '\n**Currently available memes:\n**'
124
+ var meme = require ( './commands/memes.json' )
125
+ for ( var m in meme ) {
126
+ str += m + ', '
123
127
}
124
- msg . author . openDM ( ) . then ( ( y ) => {
125
- y . sendMessage ( msgArray . join ( '\n' ) )
126
- } ) . catch ( ( e ) => {
127
- Logger . error ( e )
128
- bugsnag . notify ( e )
129
- msg . channel . sendMessage ( 'Whoops, try again.' )
130
- } )
128
+ attributes . push ( str )
131
129
}
130
+ msg . author . openDM ( ) . then ( ( y ) => {
131
+ y . sendMessage ( def . join ( '\n' ) + attributes . join ( '\n' ) )
132
+ } )
132
133
} else {
133
134
msg . channel . sendMessage ( `There is no **${ suffix } ** command!` )
134
135
}
0 commit comments