2018-10-19 23:39:42 +02:00
const { Command } = require ( 'discord.js-commando' ) ;
const blacklist = require ( '../../json/blacklist.json' ) ;
const fs = require ( 'fs' ) ;
2018-10-21 20:48:38 +02:00
module . exports = class AutoresponseCommand extends Command {
2018-10-19 23:39:42 +02:00
constructor ( client ) {
super ( client , {
name : 'autoresponse' ,
group : 'admin' ,
memberName : 'autoresponse' ,
2018-11-03 13:03:12 +01:00
userPermissions : [ 'ADMINISTRATOR' ] ,
2018-11-20 19:33:04 +01:00
description : ` Can disable autoresponse in the channel (you can add "ALL" like this "haha enable/disable all" to enable/disable in every channel (EXPERIMENTAL)) ` ,
2018-10-19 23:39:42 +02:00
args : [
{
key : 'text' ,
2018-10-21 20:46:57 +02:00
prompt : 'Disable or enable?' ,
2018-10-19 23:39:42 +02:00
type : 'string' ,
2018-11-20 19:33:04 +01:00
oneOf : [ 'disable' , 'enable' , 'disable all' , 'enable all' ] ,
} ,
{
2018-11-20 19:41:30 +01:00
key : 'all' ,
2018-11-20 19:33:04 +01:00
prompt : 'Disable or enable in every channel? (EXPERIMENTAL)' ,
type : 'string' ,
oneOf : [ 'all' , '' ] ,
default : ''
2018-10-19 23:39:42 +02:00
}
]
} ) ;
}
2018-11-20 19:33:04 +01:00
async run ( message , { text , all } ) {
2018-10-19 23:39:42 +02:00
if ( blacklist [ message . author . id ] )
return message . channel . send ( "You are blacklisted" )
2018-10-20 16:00:39 +02:00
let autoresponse = { }
let json = JSON . stringify ( autoresponse )
2018-10-19 23:39:42 +02:00
2018-11-20 19:33:04 +01:00
if ( all == 'all' ) {
const guild = this . client . guilds . get ( message . guild . id ) ;
2018-12-06 23:01:40 +01:00
fs . readFile ( './json/autoresponse.json' , 'utf8' , function readFileCallback ( err , data ) {
2018-11-20 19:33:04 +01:00
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 , '' )
2018-12-06 23:01:40 +01:00
fs . writeFile ( './json/autoresponse.json' , json , 'utf8' , function ( err ) {
2018-11-20 19:33:04 +01:00
if ( err ) {
return console . log ( err ) ;
}
} ) } } ) ;
return message . say ( 'Auto response have been disable/enable on every channel' )
} else if ( text == 'disable' || 'enable' ) {
2018-12-06 23:01:40 +01:00
fs . readFile ( './json/autoresponse.json' , 'utf8' , function readFileCallback ( err , data ) {
2018-10-19 23:39:42 +02:00
if ( err ) {
console . log ( err ) ;
} else {
2018-10-20 16:00:39 +02:00
autoresponse = JSON . parse ( data ) ; //now it an object
autoresponse [ message . channel . id ] = text
json = JSON . stringify ( autoresponse ) ; //convert it back to json
2018-12-06 23:01:40 +01:00
fs . writeFile ( './json/autoresponse.json' , json , 'utf8' , function ( err ) {
2018-10-19 23:39:42 +02:00
if ( err ) {
return console . log ( err ) ;
}
} ) } } ) ;
2018-11-20 19:33:04 +01:00
return message . say ( ` Autoresponse have been ${ text } d ` ) ;
}
2018-10-19 23:39:42 +02:00
}
} ;