diff --git a/package.json b/package.json index 866e709..bcb5cd4 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build:tsc": "tsc", "build": "npm run build:prisma && npm run build:tsc", "start": "prisma migrate deploy && node .", + "start:no-db": "npm run build:tsc && node .", "dev": "npm run build && npm run start" }, "dependencies": { diff --git a/packages/bot/index.ts b/packages/bot/index.ts index 6dde7ae..e91c55b 100644 --- a/packages/bot/index.ts +++ b/packages/bot/index.ts @@ -30,16 +30,26 @@ export class DiscordBot { } const commandsCachePath = join(cwd(), "cache", "commands"); - await mkdir(commandsCachePath); - const commandsCache: { [key: string]: string } = JSON.parse(await readFile(join(commandsCachePath, "list.json"), "utf-8") || "{}"); + await mkdir(commandsCachePath, { + recursive: true + }); + let commandsCache: { [key: string]: string } + try { + commandsCache = JSON.parse( + await readFile(join(commandsCachePath, "list.json"), "utf-8") + ); + } catch { + commandsCache = {}; + } for (const [command, id] of Object.entries(commandsCache)) { if (commandExecuteNameHashMap[command]) { continue; } + console.log(`sync(delete) command: ${command}(${id})`); await this.deleteCommand(id); } - + await this.rest.put( Routes.applicationCommands(APPLICATION_ID), { @@ -58,7 +68,9 @@ export class DiscordBot { ).reduce>((acc, cur) => { acc[cur.name] = cur.id; return acc; - }, {}) + }, {}), + null, + 2 ) ); } catch(err) { diff --git a/packages/cli/remove_command.ts b/packages/cli/remove_command.ts deleted file mode 100644 index 36b5f9b..0000000 --- a/packages/cli/remove_command.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { bot } from ".."; - -export default function remove() { - bot.deleteCommand("1463496119135899671"); - bot.deleteCommand("1463496119135899675"); - bot.deleteCommand("1463496119135899676"); - bot.deleteCommand("1463496119135899677"); - bot.deleteCommand("1463496119286759606"); - bot.deleteCommand("1464993345427476648"); - bot.deleteCommand("1464993345427476649"); -} \ No newline at end of file diff --git a/packages/index.ts b/packages/index.ts index 87f2988..2b08196 100644 --- a/packages/index.ts +++ b/packages/index.ts @@ -4,15 +4,15 @@ import { APPLICATION_ID, DISCORD_TOKEN } from "./env"; export const bot = new DiscordBot(DISCORD_TOKEN); -bot.client.once("ready", async (client) => { +bot.client.once("clientReady", async (client) => { await bot.registerCommands(); await bot.registerEvents(); console.log( - "registerCommands: \n" + + "registerCommands: \n| " + ( (await client.rest.get(Routes.applicationCommands(APPLICATION_ID))) as any[] - ).map(info => `name: ${info.name} id: ${info.id}`).join("\n") + ).map(info => `name: ${info.name} id: ${info.id}`).join("\n| ") ); }); diff --git a/packages/utils/outputHandler.ts b/packages/utils/outputHandler.ts index fcd20ac..3c22776 100644 --- a/packages/utils/outputHandler.ts +++ b/packages/utils/outputHandler.ts @@ -28,6 +28,8 @@ export namespace OutputHandler { } export async function errorLog(...args: any[]): Promise { const output = getErrorOutput(...args); + console.log(output); + await mkdir(dirname(ErrorLogPath), { recursive: true }); const fileHandle = await open(ErrorLogPath, "a");