mirror of
https://github.com/sern-handler/cli
synced 2026-06-22 07:42:23 +00:00
Compare commits
6 Commits
v1.2.0
...
feat/useri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
715f373dea | ||
|
|
504331d7ca | ||
|
|
44e5dd3845 | ||
|
|
9f9a2aaca7 | ||
|
|
d1832e44ce | ||
|
|
e55ceedadd |
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [1.2.1](https://github.com/sern-handler/cli/compare/v1.2.0...v1.2.1) (2024-02-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* better error messages for publish ([d1832e4](https://github.com/sern-handler/cli/commit/d1832e44ce1b10aeb5b9dc902b7d35ab51c41ff3))
|
||||||
|
|
||||||
## [1.2.0](https://github.com/sern-handler/cli/compare/v1.1.0...v1.2.0) (2024-01-29)
|
## [1.2.0](https://github.com/sern-handler/cli/compare/v1.1.0...v1.2.0) (2024-01-29)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -3,11 +3,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
- Manage discord application commands from the command line.
|
||||||
😁 **User Friendly** <br>
|
- Install plugins from the community.
|
||||||
💦 **Simple** <br>
|
- Really fast startup times (I think).
|
||||||
🌱 **Efficient** <br>
|
- Deploy with premade docker configurations.
|
||||||
💪 **Powerful** <br>
|
- Inhouse build tool based on esbuild built for sern applications, nearly **zero** config.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/cli",
|
"name": "@sern/cli",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@sern/cli",
|
"name": "@sern/cli",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@esbuild-kit/cjs-loader": "^2.4.2",
|
"@esbuild-kit/cjs-loader": "^2.4.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/cli",
|
"name": "@sern/cli",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"description": "Official CLI for @sern/handler",
|
"description": "Official CLI for @sern/handler",
|
||||||
"exports": "./dist/index.js",
|
"exports": "./dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import * as Rest from './rest';
|
|||||||
import type { sernConfig } from './utilities/getConfig';
|
import type { sernConfig } from './utilities/getConfig';
|
||||||
import type { PublishableData, PublishableModule, Typeable } from './create-publish.d.ts';
|
import type { PublishableData, PublishableModule, Typeable } from './create-publish.d.ts';
|
||||||
import { cyanBright, greenBright, magentaBright, redBright } from 'colorette';
|
import { cyanBright, greenBright, magentaBright, redBright } from 'colorette';
|
||||||
|
import { inspect } from 'node:util'
|
||||||
import ora from 'ora';
|
import ora from 'ora';
|
||||||
|
|
||||||
async function deriveFileInfo(dir: string, file: string) {
|
async function deriveFileInfo(dir: string, file: string) {
|
||||||
@@ -143,6 +144,7 @@ const serialize = (permissions: unknown) => {
|
|||||||
|
|
||||||
const makePublishData = ({ commandModule, config }: Record<string, Record<string, unknown>>) => {
|
const makePublishData = ({ commandModule, config }: Record<string, Record<string, unknown>>) => {
|
||||||
const applicationType = intoApplicationType(commandModule.type as number);
|
const applicationType = intoApplicationType(commandModule.type as number);
|
||||||
|
console.log(config)
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
name: commandModule.name as string,
|
name: commandModule.name as string,
|
||||||
@@ -152,6 +154,19 @@ const makePublishData = ({ commandModule, config }: Record<string, Record<string
|
|||||||
options: optionsTransformer((commandModule?.options ?? []) as Typeable[]),
|
options: optionsTransformer((commandModule?.options ?? []) as Typeable[]),
|
||||||
dm_permission: config?.dmPermission,
|
dm_permission: config?.dmPermission,
|
||||||
default_member_permissions: serialize(config?.defaultMemberPermissions),
|
default_member_permissions: serialize(config?.defaultMemberPermissions),
|
||||||
|
//@ts-ignore
|
||||||
|
integration_types: (config?.integrationTypes ?? ['Guild']).map(
|
||||||
|
(s: string) => {
|
||||||
|
if(s === "Guild") {
|
||||||
|
return 0
|
||||||
|
} else if (s == "User") {
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
|
throw Error("IntegrationType is not one of Guild or User");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
//@ts-ignore
|
||||||
|
contexts: config?.contexts ? config.contexts : undefined
|
||||||
},
|
},
|
||||||
config,
|
config,
|
||||||
};
|
};
|
||||||
@@ -167,8 +182,9 @@ appid && console.warn(`${magentaBright('WARNING')}: APPLICATION_ID is not necess
|
|||||||
// partition globally published and guilded commands
|
// partition globally published and guilded commands
|
||||||
const [globalCommands, guildedCommands] = publishableData.reduce(
|
const [globalCommands, guildedCommands] = publishableData.reduce(
|
||||||
([globals, guilded], module) => {
|
([globals, guilded], module) => {
|
||||||
const isPublishableGlobally = !module.config || !Array.isArray(module.config.guildIds);
|
const isPublishableGlobally = !Array.isArray(module.config?.guildIds);
|
||||||
if (isPublishableGlobally) {
|
if (isPublishableGlobally) {
|
||||||
|
console.log(module)
|
||||||
return [[module, ...globals], guilded];
|
return [[module, ...globals], guilded];
|
||||||
}
|
}
|
||||||
return [globals, [module, ...guilded]];
|
return [globals, [module, ...guilded]];
|
||||||
@@ -185,31 +201,35 @@ const res = await rest.updateGlobal(globalCommands);
|
|||||||
|
|
||||||
let globalCommandsResponse: unknown;
|
let globalCommandsResponse: unknown;
|
||||||
|
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
globalCommands.length && spin.succeed(`All ${cyanBright('Global')} commands published`);
|
globalCommands.length && spin.succeed(`All ${cyanBright('Global')} commands published`);
|
||||||
globalCommandsResponse = await res.json();
|
globalCommandsResponse = await res.json();
|
||||||
|
console.log(globalCommandsResponse)
|
||||||
} else {
|
} else {
|
||||||
spin.fail(`Failed to publish global commands [Code: ${redBright(res.status)}]`);
|
spin.fail(`Failed to publish global commands [Code: ${redBright(res.status)}]`);
|
||||||
switch(res.status) {
|
let err: Error
|
||||||
case 400 :
|
|
||||||
throw Error("400: Ensure your commands have proper fields and data with nothing left out");
|
|
||||||
case 404 :
|
|
||||||
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
|
||||||
case 429:
|
|
||||||
throw Error('Chill out homie, too many requests')
|
|
||||||
}
|
|
||||||
console.error('errors:',
|
|
||||||
await res
|
|
||||||
.json()
|
|
||||||
.then((res) => {
|
|
||||||
const errors = Object.values(res?.errors ?? {});
|
|
||||||
// @ts-ignore
|
|
||||||
return errors.map((err) => err?.name?._errors);
|
|
||||||
})
|
|
||||||
.catch(() => "No errors found (Unparsable json for a request with bad status code). Read the status code.")
|
|
||||||
);
|
|
||||||
console.error("Status Text ", res.statusText);
|
console.error("Status Text ", res.statusText);
|
||||||
|
switch(res.status) {
|
||||||
|
case 400 : {
|
||||||
|
const validation_errors = await res.json()
|
||||||
|
console.error('errors:', inspect(validation_errors, { depth: Infinity }));
|
||||||
|
console.error("Modules with validation errors:"
|
||||||
|
+ inspect(Object.keys(validation_errors.errors).map(idx => globalCommands[idx as any])))
|
||||||
|
throw Error("400: Ensure your commands have proper fields and data with nothing left out");
|
||||||
|
}
|
||||||
|
case 404 : {
|
||||||
|
console.error('errors:', inspect(await res.json(), { depth: Infinity }));
|
||||||
|
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
||||||
|
}
|
||||||
|
case 429: {
|
||||||
|
console.error('errors:', inspect(await res.json(), { depth: Infinity }));
|
||||||
|
err = Error('Chill out homie, too many requests')
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
|
console.error('errors:', inspect(await res.json(), { depth: Infinity }));
|
||||||
|
throw Error(res.status.toString() + " error")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function associateGuildIdsWithData(data: PublishableModule[]): Map<string, PublishableData[]> {
|
function associateGuildIdsWithData(data: PublishableModule[]): Map<string, PublishableData[]> {
|
||||||
@@ -248,12 +268,21 @@ for (const [guildId, array] of guildCommandMap.entries()) {
|
|||||||
} else {
|
} else {
|
||||||
spin.fail(`[${redBright(guildId)}] Failed to update commands for guild, Reason: ${result.message}`);
|
spin.fail(`[${redBright(guildId)}] Failed to update commands for guild, Reason: ${result.message}`);
|
||||||
switch(response.status) {
|
switch(response.status) {
|
||||||
case 400 :
|
case 400 : {
|
||||||
|
console.error(inspect(result, { depth: Infinity }))
|
||||||
|
console.error("Modules with validation errors:"
|
||||||
|
+ inspect(Object.keys(result.errors).map(idx => array[idx as any])))
|
||||||
|
|
||||||
throw Error("400: Ensure your commands have proper fields and data and nothing left out");
|
throw Error("400: Ensure your commands have proper fields and data and nothing left out");
|
||||||
case 404 :
|
}
|
||||||
|
case 404 : {
|
||||||
|
console.error(inspect(result, { depth: Infinity }))
|
||||||
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
||||||
case 429:
|
}
|
||||||
|
case 429: {
|
||||||
|
console.error(inspect(result, { depth: Infinity }))
|
||||||
throw Error('Chill out homie, too many requests')
|
throw Error('Chill out homie, too many requests')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ program //
|
|||||||
.description('New way to manage your slash commands')
|
.description('New way to manage your slash commands')
|
||||||
.option('-W --suppress-warnings', 'suppress experimental warning')
|
.option('-W --suppress-warnings', 'suppress experimental warning')
|
||||||
.option('-i, --import [scriptPath...]', 'Prerequire a script to load into publisher')
|
.option('-i, --import [scriptPath...]', 'Prerequire a script to load into publisher')
|
||||||
.option('-t, --token [token]')
|
.option('-e --env', 'path to .env file')
|
||||||
.option('--appId [applicationId]')
|
|
||||||
.argument('[path]', 'path with respect to current working directory that will locate all published files')
|
.argument('[path]', 'path with respect to current working directory that will locate all published files')
|
||||||
.action(async (...args) => importDynamic('publish.js').then((m) => m.publish(...args)))
|
.action(async (...args) => importDynamic('publish.js').then((m) => m.publish(...args)))
|
||||||
).addCommand(
|
).addCommand(
|
||||||
@@ -53,7 +52,6 @@ program //
|
|||||||
.option('-y, --yes', "Say yes to all prompts")
|
.option('-y, --yes', "Say yes to all prompts")
|
||||||
.option('-e, --env [path]', "Supply a path to a .env")
|
.option('-e, --env [path]', "Supply a path to a .env")
|
||||||
.action(async (...args) => importDynamic('command-clear.js').then((m) => m.commandClear(...args))));
|
.action(async (...args) => importDynamic('command-clear.js').then((m) => m.commandClear(...args))));
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('build')
|
.command('build')
|
||||||
.description('Build your bot')
|
.description('Build your bot')
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export async function getConfig(): Promise<sernConfig> {
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface sernConfig {
|
export interface sernConfig {
|
||||||
language: 'typescript' | 'javascript';
|
language: 'typescript' | 'javascript';
|
||||||
defaultPrefix?: string;
|
defaultPrefix?: string;
|
||||||
@@ -20,5 +19,4 @@ export interface sernConfig {
|
|||||||
commands: string;
|
commands: string;
|
||||||
events?: string;
|
events?: string;
|
||||||
};
|
};
|
||||||
buildPath: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user