This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactored CLI Services - Clean up configs file
- Loading branch information
Showing
24 changed files
with
320 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
/.gitignore | ||
/.github | ||
|
||
# VSCode | ||
/.vscode | ||
|
||
# Config files | ||
/tsconfig.json | ||
/jest.config.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"files.exclude": { | ||
"node_modules": true, | ||
"docs": true, | ||
"dist" : true, | ||
"coverage" : true | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { green, red, yellow } from "chalk"; | ||
|
||
import CommandsAPIService from "../../services/commands-api"; | ||
import MakeCommandService from "../../services/make-command"; | ||
import CommandsMap from "../../structures/commands-map"; | ||
import { InteractionsHandler } from "../../structures/interactions-handler"; | ||
|
||
import CLICommand from "../structures/cli-command"; | ||
|
||
/** | ||
* Compare the local branch and the database branch. | ||
* @param local Map of local commands | ||
* @param database Map of database commands | ||
*/ | ||
export function compareCommands(local: CommandsMap, database: CommandsMap) { | ||
const localOnly = local.rawData.map(command => command.name).filter(name => !database.get(name)); | ||
const databaseOnly = database.rawData.map(command => command.name).filter(name => !local.get(name)); | ||
const modified = local.rawData.filter(command => database.get(command.name)).filter(command => JSON.stringify(command) != JSON.stringify(database.get(command.name)!.rawData)).map(command => command.name); | ||
return {localOnly, databaseOnly, modified}; | ||
} | ||
|
||
module.exports = class extends CLICommand { | ||
name = "compareCommand"; | ||
aliases = ["cc"]; | ||
description = "Compare local commands with Discord commands."; | ||
usage = "npx djsc cc"; | ||
|
||
async execute(args?: string[]) { | ||
// get commands | ||
const commandDatas = await CommandsAPIService.getCommands(this.client.appID, this.client.botToken); | ||
const databaseCommands = await MakeCommandService.makeApplicationCommands(commandDatas); | ||
const localCommands = new InteractionsHandler(); | ||
|
||
// compare commands | ||
const { localOnly, databaseOnly, modified } = compareCommands(localCommands.commands, databaseCommands); | ||
if(localOnly.length === 0 && databaseOnly.length === 0 && modified.length === 0) return console.log(green("Commands in sync.")); | ||
console.log("Commands not in sync. Please sync using sync command or manually post and delete."); | ||
console.log(green(`+ Exists locally but not on Discord`)); | ||
console.log(red("- Exists on Discord but not locally")); | ||
console.log(yellow("! Exists on both but of different properties\n")); | ||
for(let command of localOnly) console.log(green(`+ ${command}`)); | ||
for(let command of databaseOnly) console.log(red(`- ${command}`)); | ||
for(let command of modified) console.log(yellow(`! ${command}`)); | ||
console.log("\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { green, red } from "chalk"; | ||
|
||
import CommandsAPIService from "../../services/commands-api"; | ||
|
||
import CLICommand from "../structures/cli-command"; | ||
|
||
module.exports = class extends CLICommand { | ||
name = "deleteCommand"; | ||
aliases = ["dc"]; | ||
description = "Delete a specific command from Discord by name"; | ||
usage = "npx djsc dc <commandName>"; | ||
|
||
async execute(args?: string[]) { | ||
// check if command name is given | ||
const commandName = args?.[0]; | ||
if(!commandName) return console.log(red("Name of command to delete not given. Please use `npx djsc help` for help. \n")); | ||
|
||
// get command | ||
const commandDatas = await CommandsAPIService.getCommands(this.client.appID, this.client.botToken); | ||
const command = commandDatas.find(data => data.name == commandName); | ||
if(!command) return console.log(red(`No command found with the name: ${commandName} \n`)); | ||
|
||
// delete command | ||
await CommandsAPIService.deleteCommand(this.client.appID, this.client.botToken, command.id); | ||
console.log(green(`Deleted command with name: ${commandName}\n`)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { red } from "chalk"; | ||
|
||
import CommandsAPIService from "../../services/commands-api"; | ||
import MakeCommandService from "../../services/make-command"; | ||
|
||
import CLICommand from "../structures/cli-command"; | ||
|
||
module.exports = class extends CLICommand { | ||
name = "getCommand"; | ||
aliases = ["gc"]; | ||
description = "Get and print all bot commands from Discord. Add command name as argument to get a specific command."; | ||
usage = "npx djsc gc <commandName>"; | ||
|
||
async execute(args?: string[]) { | ||
const commandName = args?.[0]; | ||
const commandDatas = await CommandsAPIService.getCommands(this.client.appID, this.client.botToken); | ||
const commandsMap = await MakeCommandService.makeApplicationCommands(commandDatas); | ||
|
||
if(commandName) { | ||
const command = commandsMap.getCommand([args?.[0] || "", args?.[1] || "", args?.[2] || ""]); | ||
if(!command) console.log(red(`No command found with the name: ${commandName}\n`)); | ||
console.log(command.rawData); | ||
} else { | ||
console.log(commandsMap.rawData); | ||
} | ||
|
||
console.log("\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import clear from "clear"; | ||
import figlet from "figlet"; | ||
import { blue, green } from "chalk"; | ||
|
||
import CLICommand from "../structures/cli-command"; | ||
|
||
module.exports = class extends CLICommand { | ||
name = "help"; | ||
description = "View usage and other documentation"; | ||
usage = "npx djsc help"; | ||
|
||
execute(args?: string[]) { | ||
clear(); | ||
console.log(blue(figlet.textSync('commando', { horizontalLayout: 'universal smushing' }))); | ||
console.log("Your friendly cli tool for managing your discord application commands."); | ||
console.log("Brought to you by @ming-suhi/djs-commando.\n"); | ||
console.log(green("Usage: npx djsc <command> <option?>")); | ||
console.log("Sample Usage: npx djsc help\n"); | ||
console.log(green("Commands:")); | ||
console.log("help View usage and other documentation"); | ||
console.log("cc Compare local commands with Discord commands."); | ||
console.log("sc Sync Discord with local. Deletes from Discord"); | ||
console.log(" unexisting files in the local commands folder."); | ||
console.log(" Posts existing local files that is not posted"); | ||
console.log(" on Discord.") | ||
console.log("gc Get and print all bot commands from Discord"); | ||
console.log("gc <commandName> Get and print a specific command from Discord"); | ||
console.log(" by name.") | ||
console.log("dc <commandName> Delete a specific command from Discord by name"); | ||
console.log("pc <commandName> Post a specific command from your commands"); | ||
console.log(" folder to Discord by name."); | ||
console.log("\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { red, green } from "chalk"; | ||
|
||
import CommandsAPIService from "../../services/commands-api"; | ||
import { InteractionsHandler } from "../../structures/interactions-handler"; | ||
|
||
import CLICommand from "../structures/cli-command"; | ||
|
||
module.exports = class extends CLICommand { | ||
name = "postCommand"; | ||
aliases = ["pc"]; | ||
description = "Post a specific command from your commands folder to Discord by name."; | ||
usage = "npcx djsc pc <commandName>"; | ||
|
||
async execute(args?: string[]) { | ||
// check if command name was provided | ||
const commandName = args?.[0]; | ||
if(!commandName) return console.log(red(`Command name not provided \n`)); | ||
|
||
// get local commands | ||
const handler = new InteractionsHandler(); | ||
const localCommand = handler.commands.get(commandName); | ||
if(!localCommand) return console.log(red(`No command found with the name: ${commandName} \n`)); | ||
|
||
// post command | ||
await CommandsAPIService.postCommand(this.client.appID, this.client.botToken, localCommand.rawData); | ||
console.log(green(`Posted command with the name: ${commandName} \n`)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { green } from "chalk"; | ||
|
||
import CommandsAPIService from "../../services/commands-api"; | ||
import MakeCommandService from "../../services/make-command"; | ||
import { InteractionsHandler } from "../../structures/interactions-handler"; | ||
|
||
import CLICommand from "../structures/cli-command"; | ||
|
||
import { compareCommands } from "./compare-command"; | ||
|
||
module.exports = class extends CLICommand { | ||
name = "syncCommand"; | ||
aliases = ["sc"]; | ||
description = `Sync Discord with local. Deletes from Discord unexisting files in the local commands folder. Posts existing local files that is not posted on Discord.`; | ||
usage = "npx djsc sc"; | ||
|
||
async execute(args?: string[]) { | ||
// get local commands | ||
const commandDatas = await CommandsAPIService.getCommands(this.client.appID, this.client.botToken); | ||
const databaseCommands = await MakeCommandService.makeApplicationCommands(commandDatas); | ||
const localCommands = new InteractionsHandler(); | ||
const { localOnly, databaseOnly, modified } = compareCommands(localCommands.commands, databaseCommands); | ||
|
||
// post local only | ||
for(let commandName of localOnly) { | ||
const command = localCommands.commands.get(commandName)!; | ||
await CommandsAPIService.postCommand(this.client.appID, this.client.botToken, command.rawData); | ||
} | ||
|
||
// edit modified | ||
for(let commandName of modified) { | ||
const command = localCommands.commands.get(commandName)!; | ||
await CommandsAPIService.postCommand(this.client.appID, this.client.botToken, command.rawData); | ||
} | ||
|
||
// delete database only | ||
for(let commandName of databaseOnly) { | ||
const command = commandDatas.find(data => data.name == commandName); | ||
await CommandsAPIService.deleteCommand(this.client.appID, this.client.botToken, command.id) | ||
} | ||
|
||
console.log(green(`Successfully synched commands. \n`)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.