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" ;
2022-05-01 19:36:52 +00:00
const blacklist = [ "create" , "add" , "edit" , "remove" , "delete" , "list" , "random" , "own" , "owner" ] ;
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 {
2022-05-01 19:36:52 +00:00
// todo: attempt to not make this file the worst thing that human eyes have ever seen
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
async run ( ) {
2022-03-31 05:42:03 +00:00
if ( ! this . channel . guild ) return "This command only works in servers!" ;
2022-05-01 19:36:52 +00:00
const cmd = this . type === "classic" ? ( this . args [ 0 ] ? ? "" ) . toLowerCase ( ) : this . optionsArray [ 0 ] . name ;
if ( ! cmd || ! cmd . trim ( ) ) return "You need to provide the name of the tag you want to view!" ;
const tagName = this . type === "classic" ? this . args . slice ( 1 ) [ 0 ] : ( this . optionsArray [ 0 ] . options [ 0 ] ? ? { } ) . value ;
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
2022-05-01 19:36:52 +00:00
if ( cmd === "create" || cmd === "add" ) {
if ( ! tagName || ! tagName . trim ( ) ) return "You need to provide the name of the tag you want to add!" ;
if ( blacklist . includes ( tagName ) ) return "You can't make a tag with that name!" ;
const getResult = await database . getTag ( this . channel . guild . id , tagName ) ;
2021-08-14 13:00:16 +00:00
if ( getResult ) return "This tag already exists!" ;
2022-05-01 19:36:52 +00:00
const result = await database . setTag ( tagName , { content : this . type === "classic" ? this . args . slice ( 2 ) . join ( " " ) : this . optionsArray [ 0 ] . options [ 1 ] . value , author : this . member . id } , this . channel . guild ) ;
2021-08-14 13:00:16 +00:00
if ( result ) return result ;
2022-05-01 19:36:52 +00:00
return ` The tag \` ${ tagName } \` has been added! ` ;
} else if ( cmd === "delete" || cmd === "remove" ) {
if ( ! tagName || ! tagName . trim ( ) ) return "You need to provide the name of the tag you want to delete!" ;
const getResult = await database . getTag ( this . channel . guild . id , tagName ) ;
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-04-05 03:05:28 +00:00
if ( getResult . author !== this . author . id && ! this . member . permissions . has ( "manageMessages" ) && ! owners . includes ( this . author . id ) ) return "You don't own this tag!" ;
2022-05-01 19:36:52 +00:00
await database . removeTag ( tagName , this . channel . guild ) ;
return ` The tag \` ${ tagName } \` has been deleted! ` ;
} else if ( cmd === "edit" ) {
if ( ! tagName || ! tagName . trim ( ) ) return "You need to provide the name of the tag you want to edit!" ;
const getResult = await database . getTag ( this . channel . guild . id , tagName ) ;
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-04-05 03:05:28 +00:00
if ( getResult . author !== this . author . id && ! this . member . permissions . has ( "manageMessages" ) && ! owners . includes ( this . author . id ) ) return "You don't own this tag!" ;
2022-05-01 19:36:52 +00:00
await database . editTag ( tagName , { content : this . type === "classic" ? this . args . slice ( 2 ) . join ( " " ) : this . optionsArray [ 0 ] . options [ 1 ] . value , author : this . member . id } , this . channel . guild ) ;
return ` The tag \` ${ tagName } \` has been edited! ` ;
} else if ( cmd === "own" || cmd === "owner" ) {
if ( ! tagName || ! tagName . trim ( ) ) return "You need to provide the name of the tag you want to check the owner of!" ;
const getResult = await database . getTag ( this . channel . guild . id , tagName ) ;
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 } \` ). ` ;
}
2022-05-01 19:36:52 +00:00
} else if ( cmd === "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 {
2022-05-01 19:36:52 +00:00
let getResult ;
if ( cmd === "random" ) {
const tagList = await database . getTags ( this . channel . guild . id ) ;
getResult = tagList [ random ( Object . keys ( tagList ) ) ] ;
} else {
getResult = await database . getTag ( this . channel . guild . id , this . type === "classic" ? cmd : tagName ) ;
}
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
}
}
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]" ]
} ;
2022-05-01 19:36:52 +00:00
static subArgs = [ {
name : "name" ,
type : 3 ,
description : "The name of the tag" ,
required : true
} , {
name : "content" ,
type : 3 ,
description : "The content of the tag" ,
required : true
} ] ;
static flags = [ {
name : "add" ,
type : 1 ,
description : "Adds a new tag" ,
options : this . subArgs
} , {
name : "delete" ,
type : 1 ,
description : "Deletes a tag" ,
options : [ this . subArgs [ 0 ] ]
} , {
name : "edit" ,
type : 1 ,
description : "Edits an existing tag" ,
options : this . subArgs
} , {
name : "get" ,
type : 1 ,
description : "Gets a tag" ,
options : [ this . subArgs [ 0 ] ]
} , {
name : "list" ,
type : 1 ,
description : "Lists every tag in this server"
} , {
name : "owner" ,
type : 1 ,
description : "Gets the owner of a tag" ,
options : [ this . subArgs [ 0 ] ]
} , {
name : "random" ,
type : 1 ,
description : "Gets a random tag"
} ] ;
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-12-13 23:09:05 +00:00
export default TagsCommand ;