2018-12-30 01:20:24 +01:00
const { Command } = require ( 'discord-akairo' ) ;
2019-07-08 22:10:14 +02:00
const Tag = require ( '../../models' ) . Tag ;
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' ,
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' ,
2019-01-02 08:09:45 +01:00
} ,
2019-09-13 18:51:02 +02:00
{
id : 'remove' ,
match : 'flag' ,
flag : '--remove'
2019-11-20 18:15:24 +01:00
} ,
2020-02-22 23:13:12 +01:00
{
id : 'reset' ,
match : 'flag' ,
flag : '--reset'
} ,
2019-11-20 18:15:24 +01:00
{
id : 'response' ,
type : 'string' ,
match : 'rest' ,
2019-01-02 08:09:45 +01:00
}
] ,
2020-03-19 23:24:31 +01:00
channel : 'guild' ,
2019-01-02 08:09:45 +01:00
description : {
2020-02-22 23:13:12 +01:00
content : 'Create custom autoresponse (--remove to delete a tag, --reset to delete EVERY tag on the server) [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-09-13 18:51:02 +02:00
examples : [ '"do you know da wea" Fuck off dead meme' , 'hello Hello [author], how are you today?' , 'hello --remove' ]
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-07-08 22:10:14 +02:00
const tag = await Tag . findOne ( { where : { trigger : args . trigger , serverID : message . guild . id } } ) ;
2019-11-25 22:03:50 +01:00
const ownerID = this . client . ownerID ;
2020-02-22 23:13:12 +01:00
if ( args . reset ) {
if ( message . member . hasPermission ( 'ADMINISTRATOR' ) ) {
message . channel . send ( 'Are you sure you want to delete EVERY tag? There is no way to recover them. y/n' ) ;
const filter = m => m . content && m . author . id == message . author . id ;
return message . channel . awaitMessages ( filter , { time : 5000 , max : 1 , errors : [ 'time' ] } )
. then ( async messages => {
let messageContent = messages . map ( messages => messages . content . toLowerCase ( ) ) ;
2020-05-08 01:26:09 +02:00
if ( messageContent [ 0 ] === 'y' || messageContent [ 0 ] === 'yes' ) {
2020-02-22 23:13:12 +01:00
Tag . destroy ( { where : { serverID : message . guild . id } } ) ;
return message . channel . send ( 'Tags have been reset.' ) ;
} else {
return message . channel . send ( 'Not reseting.' ) ;
}
} )
. catch ( err => {
console . error ( err ) ;
return message . channel . send ( 'Took too long to answer. didin\'t update anything.' ) ;
} ) ;
} else {
return message . channel . send ( 'Only person with the `ADMINISTRATOR` rank can reset tags.' ) ;
}
}
2018-12-18 17:02:05 +01:00
2019-09-13 18:51:02 +02:00
if ( args . remove ) {
if ( tag ) {
if ( tag . get ( 'ownerID' ) == message . author . id || message . member . hasPermission ( 'ADMINISTRATOR' ) || message . author . id == ownerID ) {
Tag . destroy ( { where : { trigger : args . trigger , serverID : message . guild . id } } ) ;
return message . channel . send ( 'successfully deleted the following tag: ' + args . trigger ) ;
} else {
2019-12-10 20:06:58 +01:00
return message . channel . send ( ` You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${ this . client . commandHandler . prefix [ 0 ] } tag ${ args . trigger } --remove ` ) ;
2019-09-13 18:51:02 +02:00
}
} else {
return message . channel . send ( 'Did not find the specified tag, are you sure it exist?' ) ;
}
}
2020-02-22 23:13:12 +01:00
if ( ! args . trigger ) return message . channel . send ( 'Please provide a trigger in order to create a tag.' ) ;
if ( ! args . response ) return message . channel . send ( 'Please provide the response for that tag' ) ;
2019-11-20 18:15:24 +01:00
2019-07-08 22:10:14 +02:00
if ( ! tag ) {
2019-07-09 02:19:44 +02:00
const body = { trigger : args . trigger , response : args . response , ownerID : message . author . id , serverID : message . guild . id } ;
2019-07-17 01:17:03 +02:00
await Tag . create ( body ) ;
2019-07-12 06:06:17 +02:00
return message . channel . send ( ` tag have been set to ${ args . trigger } : ${ args . response } ` ) ;
2019-09-13 18:51:02 +02:00
} else if ( tag . get ( 'ownerID' ) == message . author . id || message . member . hasPermission ( 'ADMINISTRATOR' ) || message . author . id == ownerID ) {
2019-07-12 06:06:17 +02:00
message . channel . send ( 'This tag already exist, do you want to update it? y/n' ) ;
const filter = m => m . content && m . author . id == message . author . id ;
message . channel . awaitMessages ( filter , { time : 5000 , max : 1 , errors : [ 'time' ] } )
2019-07-17 01:17:03 +02:00
. then ( async messages => {
2020-01-19 14:12:56 +01:00
let messageContent = messages . map ( messages => messages . content . toLowerCase ( ) ) ;
2020-05-08 01:26:09 +02:00
if ( messageContent [ 0 ] === 'y' || messageContent [ 0 ] === 'yes' ) {
2019-07-12 06:06:17 +02:00
const body = { trigger : args . trigger , response : args . response , ownerID : message . author . id , serverID : message . guild . id } ;
2019-07-17 01:17:03 +02:00
await Tag . update ( body , { where : { trigger : args . trigger , serverID : message . guild . id } } ) ;
2019-07-12 06:06:17 +02:00
return message . channel . send ( ` tag have been set to ${ args . trigger } : ${ args . response } ` ) ;
2019-07-20 22:34:12 +02:00
} else {
return message . channel . send ( 'Not updating.' ) ;
2019-07-12 06:06:17 +02:00
}
} )
2019-07-17 01:18:20 +02:00
. catch ( err => {
console . error ( err ) ;
2019-07-12 06:06:17 +02:00
return message . channel . send ( 'Took too long to answer. didin\'t update anything.' ) ;
} ) ;
2019-09-13 18:51:02 +02:00
} else {
2019-12-10 20:06:58 +01:00
return message . channel . send ( ` You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${ this . client . commandHandler . prefix [ 0 ] } tag ${ args . trigger } --remove ` ) ;
2019-07-08 22:10:14 +02:00
}
2019-01-02 08:09:45 +01:00
}
2018-12-30 01:20:24 +01:00
}
module . exports = TagCommand ;