2018-12-30 01:20:24 +01:00
const { Command } = require ( 'discord-akairo' ) ;
2018-12-18 17:02:05 +01:00
const fs = require ( 'fs' ) ;
2018-12-25 19:17:07 +01:00
2018-12-30 01:20:24 +01:00
class TagCommand extends Command {
2019-01-02 08:09:45 +01:00
constructor ( ) {
super ( 'tag' , {
aliases : [ 'tag' ] ,
category : 'admin' ,
split : 'quoted' ,
2019-01-12 17:00:36 +01:00
userPermissions : [ 'MANAGE_MESSAGES' ] ,
2019-01-02 08:09:45 +01:00
args : [
{
id : 'trigger' ,
2019-06-23 03:41:59 +02:00
type : 'string' ,
prompt : {
start : 'What word or sentence should trigger it?' ,
}
2019-01-02 08:09:45 +01:00
} ,
{
id : 'response' ,
2019-02-08 19:06:12 +01:00
type : 'string' ,
2019-06-23 03:41:59 +02:00
match : 'rest' ,
prompt : {
start : 'What word or sentence should the response be?' ,
}
2019-01-02 08:09:45 +01:00
}
] ,
channelRestriction : 'guild' ,
description : {
2019-04-06 18:53:40 +02:00
content : 'Create custom autoresponse [Click here to see the complete list of "tag"](https://cdn.discordapp.com/attachments/502198809355354133/561043193949585418/unknown.png) (Need "" if the trigger contains spaces)' ,
2019-01-02 08:09:45 +01:00
usage : '[trigger] [response]' ,
2019-04-06 18:53:40 +02:00
examples : [ '"do you know da wea" Fuck off dead meme' , 'hello Hello [author], how are you today?' ]
2019-01-02 08:09:45 +01:00
}
} ) ;
}
2018-12-18 17:02:05 +01:00
2019-01-02 08:09:45 +01:00
async exec ( message , args ) {
2019-06-20 02:49:11 +02:00
if ( args . trigger == null || args . response == null ) return ;
2019-01-02 08:09:45 +01:00
let trigger = args . trigger ;
let response = args . response ;
2018-12-18 17:02:05 +01:00
2019-01-02 08:09:45 +01:00
trigger = trigger . toLowerCase ( ) ;
2018-12-18 17:02:05 +01:00
2019-01-02 08:09:45 +01:00
let customresponse = { } ;
let json = JSON . stringify ( customresponse ) ;
2018-12-18 17:02:05 +01:00
2019-01-02 08:09:45 +01:00
fs . readFile ( ` ./tag/ ${ message . guild . id } .json ` , 'utf8' , function readFileCallback ( err , data ) {
if ( err ) {
2019-01-02 18:45:53 +01:00
fs . writeFile ( ` ./tag/ ${ message . guild . id } .json ` , ` {" ${ trigger } ":" ${ response } "} ` , function ( err ) {
2019-01-02 08:09:45 +01:00
if ( err ) {
2019-01-02 18:45:53 +01:00
2019-01-02 08:09:45 +01:00
console . log ( err ) ;
}
} ) ;
} else {
customresponse = JSON . parse ( data ) ; //now it an object
customresponse [ trigger ] = response ;
json = JSON . stringify ( customresponse ) ; //convert it back to json
fs . writeFile ( ` ./tag/ ${ message . guild . id } .json ` , json , 'utf8' , function ( err ) {
if ( err ) {
return console . log ( err ) ;
}
} ) ;
}
} ) ;
2019-01-02 04:35:34 +01:00
2019-01-02 18:45:53 +01:00
2019-01-02 08:09:45 +01:00
return message . channel . send ( ` autoresponse have been set to ${ trigger } : ${ response } ` ) ;
}
2018-12-30 01:20:24 +01:00
}
module . exports = TagCommand ;