Make temp dirs at startup

This commit is contained in:
Dragon Fire
2021-04-04 11:44:38 -04:00
parent 5776cadd14
commit 93494062d3
2 changed files with 13 additions and 1 deletions
+8 -1
View File
@@ -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' },
+5
View File
@@ -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);