2019-10-28 20:21:06 +00:00
const database = require ( "../utils/database.js" ) ;
2019-09-29 03:32:43 +00:00
const client = require ( "../utils/client.js" ) ;
const paginator = require ( "../utils/pagination/pagination.js" ) ;
const { random } = require ( "../utils/misc.js" ) ;
exports . run = async ( message , args ) => {
2019-12-06 18:47:40 +00:00
if ( args . length === 0 ) return ` ${ message . author . mention } , you need to specify the name of the tag you want to view! ` ;
2019-11-05 15:52:46 +00:00
const guild = ( await database . guilds . find ( { id : message . channel . guild . id } ) . exec ( ) ) [ 0 ] ;
2019-10-28 20:21:06 +00:00
const tags = guild . tags ;
2019-09-29 03:32:43 +00:00
const blacklist = [ "add" , "edit" , "remove" , "delete" , "list" , "random" ] ;
switch ( args [ 0 ] . toLowerCase ( ) ) {
case "add" :
if ( args [ 1 ] === undefined ) return ` ${ message . author . mention } , you need to provide the name of the tag you want to add! ` ;
2019-11-23 23:23:28 +00:00
if ( blacklist . includes ( args [ 1 ] . toLowerCase ( ) ) ) return ` ${ message . author . mention } , you can't make a tag with that name! ` ;
2019-11-05 15:52:46 +00:00
if ( tags . has ( args [ 1 ] . toLowerCase ( ) ) ) return ` ${ message . author . mention } , this tag already exists! ` ;
2019-11-30 15:48:05 +00:00
var result = await setTag ( args . slice ( 2 ) . join ( " " ) , args [ 1 ] . toLowerCase ( ) , message , guild ) ;
if ( result ) return result ;
2019-09-29 03:32:43 +00:00
return ` ${ message . author . mention } , the tag \` ${ args [ 1 ] . toLowerCase ( ) } \` has been added! ` ;
case "delete" :
case "remove" :
if ( args [ 1 ] === undefined ) return ` ${ message . author . mention } , you need to provide the name of the tag you want to delete! ` ;
2019-11-05 15:52:46 +00:00
if ( ! tags . has ( args [ 1 ] . toLowerCase ( ) ) ) return ` ${ message . author . mention } , this tag doesn't exist! ` ;
2020-01-27 13:41:13 +00:00
if ( tags . get ( args [ 1 ] . toLowerCase ( ) ) . author !== message . author . id && message . author . id !== process . env . OWNER ) return ` ${ message . author . mention } , you don't own this tag! ` ;
2019-10-28 20:21:06 +00:00
tags . set ( args [ 1 ] . toLowerCase ( ) , undefined ) ;
await guild . save ( ) ;
2019-09-29 03:32:43 +00:00
return ` ${ message . author . mention } , the tag \` ${ args [ 1 ] . toLowerCase ( ) } \` has been deleted! ` ;
case "edit" :
if ( args [ 1 ] === undefined ) return ` ${ message . author . mention } , you need to provide the name of the tag you want to edit! ` ;
2019-11-05 15:52:46 +00:00
if ( ! tags . has ( args [ 1 ] . toLowerCase ( ) ) ) return ` ${ message . author . mention } , this tag doesn't exist! ` ;
2019-11-13 00:09:06 +00:00
if ( tags . get ( args [ 1 ] . toLowerCase ( ) ) . author !== message . author . id && tags . get ( args [ 1 ] . toLowerCase ( ) ) . author !== process . env . OWNER ) return ` ${ message . author . mention } , you don't own this tag! ` ;
2019-10-28 20:21:06 +00:00
await setTag ( args . slice ( 2 ) . join ( " " ) , args [ 1 ] . toLowerCase ( ) , message , guild ) ;
2019-09-29 03:32:43 +00:00
return ` ${ message . author . mention } , the tag \` ${ args [ 1 ] . toLowerCase ( ) } \` has been edited! ` ;
2020-01-27 13:41:13 +00:00
case "own" :
case "owner" :
if ( args [ 1 ] === undefined ) return ` ${ message . author . mention } , you need to provide the name of the tag you want to check the owner of! ` ;
if ( ! tags . has ( args [ 1 ] . toLowerCase ( ) ) ) return ` ${ message . author . mention } , this tag doesn't exist! ` ;
return ` ${ message . author . mention } , this tag is owned by ** ${ client . users . get ( tags . get ( args [ 1 ] . toLowerCase ( ) ) . author ) . username } # ${ client . users . get ( tags . get ( args [ 1 ] . toLowerCase ( ) ) . author ) . discriminator } ** ( \` ${ tags . get ( args [ 1 ] . toLowerCase ( ) ) . author } \` ). ` ;
2019-09-29 03:32:43 +00:00
case "list" :
if ( ! message . channel . guild . members . get ( client . user . id ) . permission . has ( "addReactions" ) && ! message . channel . permissionsOf ( client . user . id ) . has ( "addReactions" ) ) return ` ${ message . author . mention } , I don't have the \` Add Reactions \` permission! ` ;
if ( ! message . channel . guild . members . get ( client . user . id ) . permission . has ( "embedLinks" ) && ! message . channel . permissionsOf ( client . user . id ) . has ( "embedLinks" ) ) return ` ${ message . author . mention } , I don't have the \` Embed Links \` permission! ` ;
var pageSize = 15 ;
var embeds = [ ] ;
2020-03-10 22:24:57 +00:00
var groups = [ ... tags . keys ( ) ] . map ( ( item , index ) => {
return index % pageSize === 0 ? [ ... tags . keys ( ) ] . slice ( index , index + pageSize ) : null ;
2019-11-05 15:52:46 +00:00
} ) . filter ( ( item ) => {
return item ;
2019-09-29 03:32:43 +00:00
} ) ;
for ( const [ i , value ] of groups . entries ( ) ) {
embeds . push ( {
"embed" : {
"title" : "Tag List" ,
"color" : 16711680 ,
"footer" : {
"text" : ` Page ${ i + 1 } of ${ groups . length } `
} ,
"description" : value . join ( "\n" ) ,
2019-12-19 16:36:33 +00:00
"fields" : process . env . NODE _ENV === "development" ? [ { "name" : "Note" , "value" : "Tags created in this version of esmBot will not carry over to the final release." } ] : null ,
2019-09-29 03:32:43 +00:00
"author" : {
"name" : message . author . username ,
"icon_url" : message . author . avatarURL
}
}
} ) ;
}
if ( embeds . length === 0 ) return ` ${ message . author . mention } , I couldn't find any tags! ` ;
return paginator ( message , embeds ) ;
case "random" :
2020-03-10 22:24:57 +00:00
return random ( [ ... tags ] ) [ 1 ] . content ;
2019-09-29 03:32:43 +00:00
default :
2019-11-05 15:52:46 +00:00
if ( ! tags . has ( args [ 0 ] . toLowerCase ( ) ) ) return ` ${ message . author . mention } , this tag doesn't exist! ` ;
return tags . get ( args [ 0 ] . toLowerCase ( ) ) . content ;
2019-09-29 03:32:43 +00:00
}
} ;
2019-10-28 20:21:06 +00:00
const setTag = async ( content , name , message , guild ) => {
2019-11-30 15:48:05 +00:00
if ( ( ! content || content . length === 0 ) && message . attachments . length === 0 ) return ` ${ message . author . mention } , you need to provide the content of the tag! ` ;
if ( message . attachments . length !== 0 && content ) {
2019-10-28 20:21:06 +00:00
guild . tags . set ( name , { content : ` ${ content } ${ message . attachments [ 0 ] . url } ` , author : message . author . id } ) ;
2019-11-30 15:48:05 +00:00
await guild . save ( ) ;
} else if ( message . attachments . length !== 0 ) {
guild . tags . set ( name , { content : message . attachments [ 0 ] . url , author : message . author . id } ) ;
await guild . save ( ) ;
2019-09-29 03:32:43 +00:00
} else {
2019-10-28 20:21:06 +00:00
guild . tags . set ( name , { content : content , author : message . author . id } ) ;
2019-11-30 15:48:05 +00:00
await guild . save ( ) ;
2019-09-29 03:32:43 +00:00
}
2019-11-30 15:48:05 +00:00
return ;
2019-09-29 03:32:43 +00:00
} ;
2019-12-02 20:47:22 +00:00
exports . aliases = [ "t" , "tag" , "ta" ] ;
exports . category = 3 ;
2019-12-06 00:15:28 +00:00
exports . help = {
default : "Gets a tag" ,
add : "Adds a tag" ,
delete : "Deletes a tag" ,
edit : "Edits a tag" ,
list : "Lists all tags in the server" ,
random : "Gets a random tag"
} ;
exports . params = {
default : "[name]" ,
add : "[name] [content]" ,
delete : "[name]" ,
edit : "[name] [content]"
2019-12-10 15:53:43 +00:00
} ;