2021-08-19 14:19:14 +00:00
import database from "../../utils/database.js" ;
import paginator from "../../utils/pagination/pagination.js" ;
import { random } from "../../utils/misc.js" ;
import Command from "../../classes/command.js" ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
class TagsCommand extends Command {
// todo: find a way to split this into subcommands
async run ( ) {
2022-03-31 05:42:03 +00:00
if ( ! this . channel . guild ) return "This command only works in servers!" ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
2021-05-11 16:12:01 +00:00
if ( this . args . length === 0 ) return "You need to provide the name of the tag you want to view!" ;
2021-08-13 03:28:09 +00:00
const blacklist = [ "create" , "add" , "edit" , "remove" , "delete" , "list" , "random" , "own" , "owner" ] ;
2021-08-14 13:00:16 +00:00
if ( this . args [ 0 ] . toLowerCase ( ) === "create" || this . args [ 0 ] . toLowerCase ( ) === "add" ) {
if ( this . args [ 1 ] === undefined ) return "You need to provide the name of the tag you want to add!" ;
if ( blacklist . includes ( this . args [ 1 ] . toLowerCase ( ) ) ) return "You can't make a tag with that name!" ;
2022-03-31 05:42:03 +00:00
const getResult = await database . getTag ( this . channel . guild . id , this . args [ 1 ] . toLowerCase ( ) ) ;
2021-08-14 13:00:16 +00:00
if ( getResult ) return "This tag already exists!" ;
const result = await this . setTag ( this . args . slice ( 2 ) . join ( " " ) , this . args [ 1 ] . toLowerCase ( ) , this . message ) ;
if ( result ) return result ;
return ` The tag \` ${ this . args [ 1 ] . toLowerCase ( ) } \` has been added! ` ;
} else if ( this . args [ 0 ] . toLowerCase ( ) === "delete" || this . args [ 0 ] . toLowerCase ( ) === "remove" ) {
if ( this . args [ 1 ] === undefined ) return "You need to provide the name of the tag you want to delete!" ;
2022-03-31 05:42:03 +00:00
const getResult = await database . getTag ( this . channel . guild . id , this . args [ 1 ] . toLowerCase ( ) ) ;
2021-08-14 13:00:16 +00:00
if ( ! getResult ) return "This tag doesn't exist!" ;
2021-11-03 00:43:37 +00:00
const owners = process . env . OWNER . split ( "," ) ;
2022-03-31 05:42:03 +00:00
if ( getResult . author !== this . author . id && ! this . message . member . permissions . has ( "manageMessages" ) && ! owners . includes ( this . author . id ) ) return "You don't own this tag!" ;
await database . removeTag ( this . args [ 1 ] . toLowerCase ( ) , this . channel . guild ) ;
2021-08-14 13:00:16 +00:00
return ` The tag \` ${ this . args [ 1 ] . toLowerCase ( ) } \` has been deleted! ` ;
} else if ( this . args [ 0 ] . toLowerCase ( ) === "edit" ) {
if ( this . args [ 1 ] === undefined ) return "You need to provide the name of the tag you want to edit!" ;
2022-03-31 05:42:03 +00:00
const getResult = await database . getTag ( this . channel . guild . id , this . args [ 1 ] . toLowerCase ( ) ) ;
2021-08-14 13:00:16 +00:00
if ( ! getResult ) return "This tag doesn't exist!" ;
2021-11-03 00:43:37 +00:00
const owners = process . env . OWNER . split ( "," ) ;
2022-03-31 05:42:03 +00:00
if ( getResult . author !== this . author . id && ! this . message . member . permissions . has ( "manageMessages" ) && ! owners . includes ( this . author . id ) ) return "You don't own this tag!" ;
2021-08-14 13:00:16 +00:00
await this . setTag ( this . args . slice ( 2 ) . join ( " " ) , this . args [ 1 ] . toLowerCase ( ) , this . message , true ) ;
return ` The tag \` ${ this . args [ 1 ] . toLowerCase ( ) } \` has been edited! ` ;
} else if ( this . args [ 0 ] . toLowerCase ( ) === "own" || this . args [ 0 ] . toLowerCase ( ) === "owner" ) {
if ( this . args [ 1 ] === undefined ) return "You need to provide the name of the tag you want to check the owner of!" ;
2022-03-31 05:42:03 +00:00
const getResult = await database . getTag ( this . channel . guild . id , this . args [ 1 ] . toLowerCase ( ) ) ;
2021-08-14 13:00:16 +00:00
if ( ! getResult ) return "This tag doesn't exist!" ;
const user = await this . ipc . fetchUser ( getResult . author ) ;
2021-12-13 23:09:05 +00:00
if ( ! user ) {
try {
const restUser = await this . client . getRESTUser ( getResult . author ) ;
return ` This tag is owned by ** ${ restUser . username } # ${ restUser . discriminator } ** ( \` ${ getResult . author } \` ). ` ;
} catch {
return ` I couldn't find exactly who owns this tag, but I was able to get their ID: \` ${ getResult . author } \` ` ;
}
} else {
return ` This tag is owned by ** ${ user . username } # ${ user . discriminator } ** ( \` ${ getResult . author } \` ). ` ;
}
2021-08-14 13:00:16 +00:00
} else if ( this . args [ 0 ] . toLowerCase ( ) === "list" ) {
2022-03-31 05:42:03 +00:00
if ( ! this . channel . permissionsOf ( this . client . user . id ) . has ( "embedLinks" ) ) return "I don't have the `Embed Links` permission!" ;
const tagList = await database . getTags ( this . channel . guild . id ) ;
2021-08-14 13:00:16 +00:00
const embeds = [ ] ;
const groups = Object . keys ( tagList ) . map ( ( item , index ) => {
return index % 15 === 0 ? Object . keys ( tagList ) . slice ( index , index + 15 ) : null ;
} ) . filter ( ( item ) => {
return item ;
} ) ;
for ( const [ i , value ] of groups . entries ( ) ) {
embeds . push ( {
2021-11-10 04:09:10 +00:00
embeds : [ {
title : "Tag List" ,
color : 16711680 ,
footer : {
text : ` Page ${ i + 1 } of ${ groups . length } `
2021-08-14 13:00:16 +00:00
} ,
2021-11-10 04:09:10 +00:00
description : value . join ( "\n" ) ,
author : {
2022-03-31 05:42:03 +00:00
name : this . author . username ,
icon _url : this . author . avatarURL
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
}
2021-11-10 04:09:10 +00:00
} ]
2021-08-14 13:00:16 +00:00
} ) ;
}
if ( embeds . length === 0 ) return "I couldn't find any tags!" ;
2022-03-31 19:53:22 +00:00
return paginator ( this . client , { type : this . type , message : this . message , interaction : this . interaction , channel : this . channel , author : this . author } , embeds ) ;
2021-08-14 13:00:16 +00:00
} else if ( this . args [ 0 ] . toLowerCase ( ) === "random" ) {
2022-03-31 05:42:03 +00:00
const tagList = await database . getTags ( this . channel . guild . id ) ;
2021-08-14 13:00:16 +00:00
return tagList [ random ( Object . keys ( tagList ) ) ] . content ;
} else {
2022-03-31 05:42:03 +00:00
const getResult = await database . getTag ( this . channel . guild . id , this . args [ 0 ] . toLowerCase ( ) ) ;
2021-08-14 13:00:16 +00:00
if ( ! getResult ) return "This tag doesn't exist!" ;
2021-11-22 04:10:36 +00:00
if ( getResult . content . length > 2000 ) {
return {
embeds : [ {
2021-11-22 05:27:08 +00:00
color : 16711680 ,
description : getResult . content
2021-11-22 04:10:36 +00:00
} ] ,
} ;
}
2021-08-14 13:00:16 +00:00
return getResult . content ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
}
}
2021-08-11 01:25:29 +00:00
async setTag ( content , name , message , edit = false ) {
2021-05-11 16:12:01 +00:00
if ( ( ! content || content . length === 0 ) && message . attachments . length === 0 ) return "You need to provide the content of the tag!" ;
2021-11-22 04:10:36 +00:00
if ( content && content . length > 4096 ) return "Your tag content is too long!" ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
if ( message . attachments . length !== 0 && content ) {
2021-08-13 03:28:09 +00:00
await database [ edit ? "editTag" : "setTag" ] ( name , { content : ` ${ content } ${ message . attachments [ 0 ] . url } ` , author : message . author . id } , message . channel . guild ) ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
} else if ( message . attachments . length !== 0 ) {
2021-08-13 03:28:09 +00:00
await database [ edit ? "editTag" : "setTag" ] ( name , { content : message . attachments [ 0 ] . url , author : message . author . id } , message . channel . guild ) ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
} else {
2021-08-13 03:28:09 +00:00
await database [ edit ? "editTag" : "setTag" ] ( name , { content : content , author : message . author . id } , message . channel . guild ) ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
}
return ;
}
2022-03-31 05:42:03 +00:00
/ * s t a t i c d e s c r i p t i o n = {
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
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" ,
2021-08-13 03:28:09 +00:00
owner : "Gets the owner of a tag"
2022-03-31 05:42:03 +00:00
} ; * /
static description = "Manage tags" ;
Class commands, improved sharding, and many other changes (#88)
* Load commands recursively
* Sort commands
* Missed a couple of spots
* missed even more spots apparently
* Ported commands in "fun" category to new class-based format, added babel eslint plugin
* Ported general commands, removed old/unneeded stuff, replaced moment with day, many more fixes I lost track of
* Missed a spot
* Removed unnecessary abort-controller package, add deprecation warning for mongo database
* Added imagereload, clarified premature end message
* Fixed docker-compose path issue, added total bot uptime to stats, more fixes for various parts
* Converted image commands into classes, fixed reload, ignore another WS event, cleaned up command handler and image runner
* Converted music/soundboard commands to class format
* Cleanup unnecessary logs
* awful tag command class port
* I literally somehow just learned that you can leave out the constructor in classes
* Pass client directly to commands/events, cleaned up command handler
* Migrated bot to eris-sharder, fixed some error handling stuff
* Remove unused modules
* Fixed type returning
* Switched back to Eris stable
* Some fixes and cleanup
* might wanna correct this
* Implement image command ratelimiting
* Added Bot token prefix, added imagestats, added running endpoint to API
2021-04-12 16:16:12 +00:00
static aliases = [ "t" , "tag" , "ta" ] ;
static arguments = {
default : [ "[name]" ] ,
add : [ "[name]" , "[content]" ] ,
delete : [ "[name]" ] ,
edit : [ "[name]" , "[content]" ] ,
owner : [ "[name]" ]
} ;
}
2021-12-13 23:09:05 +00:00
export default TagsCommand ;