11const Discord = require ( "discord.js" ) ;
2- const { config } = require ( "../config.js" ) ;
2+ const {
3+ config
4+ } = require ( "../config.js" ) ;
35const chalk = require ( "chalk" ) ;
46const fs = require ( "fs" ) ;
57
@@ -73,15 +75,11 @@ module.exports = message => {
7375 */
7476
7577 // this one will filter the mentioned users
76- const AFKandMentioned = message . mentions . users . filter ( user => {
77- return user . id in AFKdata ;
78- } ) ;
78+ const AFKandMentioned = message . mentions . users . filter ( user => user . id in AFKdata ) ;
7979 // WHEN SOMEONE IS MENTIONED AND THE MENTIONED AFK IS TRUE
8080 if ( AFKandMentioned . size ) {
8181 // get the mentioned & afk user's reason
82- const reason = AFKandMentioned . map ( user => {
83- return AFKdata [ user . id ] ;
84- } ) ;
82+ const reason = AFKandMentioned . map ( user => AFKdata [ user . id ] } ) ;
8583
8684 // miku tryna remember whats your reason
8785 const afkSaid = [
@@ -93,9 +91,7 @@ module.exports = message => {
9391 . setAuthor ( "User AFK" )
9492 . setColor ( "#1a9ca8" )
9593 . setDescription ( `${ afkSaid } \n\`\`\`${ reason } \`\`\`` )
96- . setFooter (
97- `${ message . author . username } , they are AFK at the moment. Please try again later!.`
98- ) ;
94+ . setFooter ( `${ message . author . username } , they are AFK at the moment. Please try again later!.` ) ;
9995 message . channel . send ( { embed } ) ;
10096 }
10197 /* end-AFK */
@@ -122,22 +118,11 @@ module.exports = message => {
122118 ] . random ( ) ;
123119
124120 // what to do when miku is mentioned
125- if (
126- message . content . startsWith ( `<@${ config . botID } >` ) ||
127- message . content . startsWith ( `<@!${ config . botID } >` )
128- ) {
129- message . channel . send ( `${ hello } ${ emojis } ` ) ;
130- }
121+ if ( message . content . startsWith ( `<@${ config . botID } >` ) || message . content . startsWith ( `<@!${ config . botID } >` ) ) message . channel . send ( `${ hello } ${ emojis } ` ) ;
131122 // if it does not starts with guild's custom prefix or default prefix or it's a bot, do nothing
132- if (
133- ( ! message . content . startsWith ( DB [ message . guild . id ] . prefix ) &&
134- ! message . content . startsWith ( config . prefix ) ) ||
135- message . author . bot
136- )
137- return ;
123+ if ( ( ! message . content . startsWith ( DB [ message . guild . id ] . prefix ) && ! message . content . startsWith ( config . prefix ) ) || message . author . bot ) return ;
138124 } else if ( message . channel . type == "dm" ) {
139- if ( bot . commandsConf . get ( command ) )
140- return message . channel . send ( "You cannot run that command in a DM!" ) ;
125+ if ( bot . commandsConf . get ( command ) ) return message . channel . send ( "You cannot run that command in a DM!" ) ;
141126 if ( ! message . content . startsWith ( config . prefix ) ) return ;
142127 }
143128 /* end-IF ITS NOT A DM */
@@ -153,16 +138,32 @@ module.exports = message => {
153138 // RUN COMMAND/ALIASES
154139 try {
155140 // VARIABLES
156- let theCmd , find , cd ;
141+ let theCmd , find , cd , userperm , botperm ;
157142 if ( bot . commands . has ( command ) ) {
158143 find = bot . commands . get ( command ) ; // find the command
159144 theCmd = find . help . name ; // find command's name
160145 cd = find . conf . cooldown * 1000 ; // find the cooldown and then make it second
146+ userperm = find . conf . userPerm ;
147+ botperm = find . conf . botPerm ;
148+ userperm [ 0 ] . length == 0 ? ( userperm = "SEND_MESSAGES" ) : "" ;
149+ botperm [ 0 ] . length == 0 ? ( botperm = "SEND_MESSAGES" ) : "" ;
161150 } else if ( bot . aliases . has ( command ) ) {
162151 find = bot . commands . get ( bot . aliases . get ( command ) ) ;
163152 theCmd = find . help . name ;
164153 cd = find . conf . cooldown * 1000 ;
154+ userperm = find . conf . userPerm ;
155+ botperm = find . conf . botPerm ;
156+ userperm [ 0 ] . length == 0 ? ( userperm = "SEND_MESSAGES" ) : "" ;
157+ botperm [ 0 ] . length == 0 ? ( botperm = "SEND_MESSAGES" ) : "" ;
165158 }
159+
160+ // if miku has no permission to send
161+ if ( ! message . guild . me . hasPermission ( "SEND_MESSAGES" ) ) return ;
162+ // if user has no permission for specific command
163+ if ( ! message . member . hasPermission ( userperm ) || ! message . channel . permissionsFor ( message . member ) . has ( userperm ) ) return message . channel . send ( `❌ | You don't have any right to run that command!\n_missing ${ userperm } permission(s)_` ) ;
164+ // if miku has no permission for specific command
165+ if ( ! message . guild . me . hasPermission ( botperm ) || ! message . channel . permissionsFor ( bot . user ) . has ( botperm ) ) return message . channel . send ( `❌ | Lacks one or more of these permission(s) : \`${ botperm . join ( ", " ) } \`` ) ;
166+
166167 // what miku will say if you're on cooldown
167168 const cooldowns = [
168169 `O//w//O I-I-I\'m Getting Dizzy!\n_(cooling down)_` ,
@@ -196,9 +197,7 @@ guild ID : ${message.guild.id}
196197
197198 // +1 total commands ran
198199 const total = totalCommands . total + 1 ;
199- totalCommands = {
200- total : total
201- } ;
200+ totalCommands = { total : total } ;
202201 writeFile ( "./assets/totalCmd" , totalCommands ) ;
203202
204203 if ( ! talkedRecently [ message . author . id ] )
0 commit comments