From 93494062d3764a2c4a9e927d546e91993738c326 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 4 Apr 2021 11:44:38 -0400 Subject: [PATCH] Make temp dirs at startup --- Xiao.js | 9 ++++++++- util/Util.js | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Xiao.js b/Xiao.js index 80b2c6f0..12f6a000 100644 --- a/Xiao.js +++ b/Xiao.js @@ -1,5 +1,6 @@ require('dotenv').config(); const { XIAO_TOKEN, OWNERS, XIAO_PREFIX, INVITE, APRIL_FOOLS } = process.env; +const { mkdir } = require('fs/promises'); const path = require('path'); const { Intents, MessageEmbed } = require('discord.js'); const Client = require('./structures/Client'); @@ -11,7 +12,7 @@ const client = new Client({ partials: ['GUILD_MEMBER'], ws: { intents: [Intents.NON_PRIVILEGED, 'GUILD_MEMBERS'] } }); -const { formatNumber } = require('./util/Util'); +const { formatNumber, checkFileExists } = require('./util/Util'); client.registry .registerDefaultTypes() @@ -57,6 +58,12 @@ client.registry client.on('ready', async () => { client.logger.info(`[READY] Logged in as ${client.user.tag}! ID: ${client.user.id}`); + // Make temp directories + const tmpFolderExists = await checkFileExists(path.join(__dirname, 'tmp')); + if (!tmpFolderExists) await mkdir(path.join(__dirname, 'tmp')); + const decTalkFolderExists = await checkFileExists(path.join(__dirname, 'tmp', 'dec-talk')); + if (!decTalkFolderExists) await mkdir(path.join(__dirname, 'tmp', 'dec-talk')); + // Push client-related activities client.activities.push( { text: () => `${formatNumber(client.guilds.cache.size)} servers`, type: 'WATCHING' }, diff --git a/util/Util.js b/util/Util.js index 67d721b5..76ecf2f1 100644 --- a/util/Util.js +++ b/util/Util.js @@ -1,5 +1,6 @@ const crypto = require('crypto'); const request = require('node-superfetch'); +const fs = require('fs'); const tf = require('@tensorflow/tfjs-node'); const { parseDomain, ParseResultType } = require('parse-domain'); const { decode: decodeHTML } = require('html-entities'); @@ -198,6 +199,10 @@ module.exports = class Util { return `[${title}](${uri.replaceAll(')', '%29')}${display ? ` "${display}"` : ''})`; } + static checkFileExists(filepath) { + return new Promise((res) => fs.access(filepath, fs.constants.F_OK, error => res(!error))); + } + static stripInvites(str, { guild = true, bot = true, text = '[redacted invite]' } = {}) { if (guild) str = str.replace(inviteRegex, text); if (bot) str = str.replace(botInvRegex, text);