@ -8,25 +8,50 @@ module.exports = class AutoresponseCommand extends Command {
group : 'admin' ,
group : 'admin' ,
memberName : 'autoresponse' ,
memberName : 'autoresponse' ,
userPermissions : [ 'ADMINISTRATOR' ] ,
userPermissions : [ 'ADMINISTRATOR' ] ,
description : ` Can disable autoresponse in the channel ` ,
description : ` Can disable autoresponse in the channel (you can add "ALL" like this "haha enable/disable all" to enable/disable in every channel (EXPERIMENTAL)) ` ,
args : [
args : [
{
{
key : 'text' ,
key : 'text' ,
prompt : 'Disable or enable?' ,
prompt : 'Disable or enable?' ,
type : 'string' ,
type : 'string' ,
oneOf : [ 'disable' , 'enable' ] ,
oneOf : [ 'disable' , 'enable' , 'disable all' , 'enable all' ] ,
} ,
{
key : 'testt' ,
prompt : 'Disable or enable in every channel? (EXPERIMENTAL)' ,
type : 'string' ,
oneOf : [ 'all' , '' ] ,
default : ''
}
}
]
]
} ) ;
} ) ;
}
}
async run ( message , { text } ) {
async run ( message , { text , all } ) {
if ( blacklist [ message . author . id ] )
if ( blacklist [ message . author . id ] )
return message . channel . send ( "You are blacklisted" )
return message . channel . send ( "You are blacklisted" )
let autoresponse = { }
let autoresponse = { }
let json = JSON . stringify ( autoresponse )
let json = JSON . stringify ( autoresponse )
if ( all == 'all' ) {
const guild = this . client . guilds . get ( message . guild . id ) ;
fs . readFile ( 'json/autoresponse.json' , 'utf8' , function readFileCallback ( err , data ) {
if ( err ) {
console . log ( err ) ;
} else {
autoresponse = JSON . parse ( data ) ; //now it an object
guild . channels . forEach ( channel => autoresponse [ channel ] = text )
json = JSON . stringify ( autoresponse ) ; //convert it back to json
json = json . replace ( /[<#>]/g , '' )
fs . writeFile ( 'json/autoresponse.json' , json , 'utf8' , function ( err ) {
if ( err ) {
return console . log ( err ) ;
}
} ) } } ) ;
return message . say ( 'Auto response have been disable/enable on every channel' )
} else if ( text == 'disable' || 'enable' ) {
fs . readFile ( 'json/autoresponse.json' , 'utf8' , function readFileCallback ( err , data ) {
fs . readFile ( 'json/autoresponse.json' , 'utf8' , function readFileCallback ( err , data ) {
if ( err ) {
if ( err ) {
console . log ( err ) ;
console . log ( err ) ;
@ -40,6 +65,7 @@ module.exports = class AutoresponseCommand extends Command {
}
}
} ) } } ) ;
} ) } } ) ;
message . say ( ` Autoresponse have been ${ text } d ` ) ;
return message . say ( ` Autoresponse have been ${ text } d ` ) ;
}
}
}
} ;
} ;