2020-04-10 02:40:52 +00:00
const db = require ( "../utils/database.js" ) ;
exports . run = async ( message , args ) => {
2020-09-01 22:10:19 +00:00
if ( ! message . channel . guild ) return ` ${ message . author . mention } , this command only works in servers! ` ;
2021-01-28 04:57:13 +00:00
if ( ! message . member . permissions . has ( "administrator" ) && message . member . id !== process . env . OWNER ) return ` ${ message . author . mention } , you need to be an administrator to enable/disable me! ` ;
2020-04-10 02:40:52 +00:00
if ( args . length === 0 ) return ` ${ message . author . mention } , you need to provide whether I should be enabled or disabled in this channel! ` ;
if ( args [ 0 ] !== "disable" && args [ 0 ] !== "enable" ) return ` ${ message . author . mention } , that's not a valid option! ` ;
2020-12-18 02:32:19 +00:00
const guildDB = await db . getGuild ( message . channel . guild . id ) ;
2020-04-10 02:40:52 +00:00
if ( args [ 0 ] . toLowerCase ( ) === "disable" ) {
2020-12-18 02:32:19 +00:00
let channel ;
2020-04-10 02:40:52 +00:00
if ( args [ 1 ] && args [ 1 ] . match ( /^<?[@#]?[&!]?\d+>?$/ ) && args [ 1 ] >= 21154535154122752 ) {
2021-01-18 20:11:28 +00:00
const id = args [ 1 ] . replaceAll ( "@" , "" ) . replaceAll ( "#" , "" ) . replaceAll ( "!" , "" ) . replaceAll ( "&" , "" ) . replaceAll ( "<" , "" ) . replaceAll ( ">" , "" ) ;
2020-12-18 02:32:19 +00:00
if ( guildDB . disabled . includes ( id ) ) return ` ${ message . author . mention } , I'm already disabled in this channel! ` ;
channel = message . channel . guild . channels . get ( id ) ;
2020-04-10 02:40:52 +00:00
} else {
2020-12-18 02:32:19 +00:00
if ( guildDB . disabled . includes ( message . channel . id ) ) return ` ${ message . author . mention } , I'm already disabled in this channel! ` ;
channel = message . channel ;
2020-04-10 02:40:52 +00:00
}
2020-12-18 02:32:19 +00:00
await db . disableChannel ( channel ) ;
2020-07-27 00:52:13 +00:00
return ` ${ message . author . mention } , I have been disabled in this channel. To re-enable me, just run \` ${ guildDB . prefix } channel enable \` . ` ;
2020-04-10 02:40:52 +00:00
} else if ( args [ 0 ] . toLowerCase ( ) === "enable" ) {
2020-12-18 02:32:19 +00:00
let channel ;
2020-04-10 02:40:52 +00:00
if ( args [ 1 ] && args [ 1 ] . match ( /^<?[@#]?[&!]?\d+>?$/ ) && args [ 1 ] >= 21154535154122752 ) {
2021-01-18 20:11:28 +00:00
const id = args [ 1 ] . replaceAll ( "@" , "" ) . replaceAll ( "#" , "" ) . replaceAll ( "!" , "" ) . replaceAll ( "&" , "" ) . replaceAll ( "<" , "" ) . replaceAll ( ">" , "" ) ;
2020-12-18 02:32:19 +00:00
if ( ! guildDB . disabled . includes ( id ) ) return ` ${ message . author . mention } , I'm not disabled in that channel! ` ;
channel = message . channel . guild . channels . get ( id ) ;
2020-04-10 02:40:52 +00:00
} else {
2020-12-18 02:32:19 +00:00
if ( ! guildDB . disabled . includes ( message . channel . id ) ) return ` ${ message . author . mention } , I'm not disabled in this channel! ` ;
channel = message . channel ;
2020-04-10 02:40:52 +00:00
}
2020-12-18 02:32:19 +00:00
await db . enableChannel ( channel ) ;
2020-04-10 02:40:52 +00:00
return ` ${ message . author . mention } , I have been re-enabled in this channel. ` ;
}
} ;
exports . category = 1 ;
exports . help = "Enables/disables me in a channel" ;
exports . params = "[enable/disable] {id}" ;