Skip to content

Commit

Permalink
fix: check downloads folder exists before deleting contents (#215)
Browse files Browse the repository at this point in the history
* fix: check downloads folder exists before deleting contents

* chore: use emojis for changer gates
  • Loading branch information
wopian authored Jul 17, 2024
1 parent 8ed1b1b commit 5fb4463
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/createFolder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir, readdir } from 'node:fs/promises'
import { mkdir, readdir, access } from 'node:fs/promises'

import { rimraf } from 'rimraf'

Expand All @@ -9,9 +9,18 @@ interface NodeJSWithCodeError extends Error {
code?: string
}

const folderExists = async (folder: string): Promise<boolean> => {
try {
await access(folder);
return true;
} catch {
return false;
}
};

export const createFolder = async (folder: string, cleanFolder = false) => {
try {
if (cleanFolder) {
if (cleanFolder && await folderExists(folder)) {
const filesToDelete = await readdir(folder)

for (const file of filesToDelete) {
Expand Down
10 changes: 5 additions & 5 deletions src/getLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ const changerGateBlockIdsByMode = new Set<ChangerGateBlockIdsByMode>([
{
blockIds: new Set([1978, 1979, 1990]),
mode: 'Invert Steering',
emoji: 'invert_steering'
emoji: '<:invert_steering:1263232209452794057>'
},
{
blockIds: new Set([1980, 1981, 1991]),
mode: 'Invert Arms Up Braking',
emoji: 'invert_arms_up_braking'
emoji: '<:invert_arms_up_braking:1263232208278126685>'
},
{
blockIds: new Set([1982, 1983, 1992]),
mode: 'Offroad Wheels',
emoji: 'offroad_wheels'
emoji: '<:offroad_wheels:1263232210861817937>'
},
{
blockIds: new Set([1984, 1985, 1993]),
mode: 'Paraglider',
emoji: 'paraglider'
emoji: '<:paraglider:1263232212153929870>'
},
{
blockIds: new Set([1608, 1610, 1987]),
mode: 'Soap Wheels',
emoji: 'soap_wheels'
emoji: '<:soap_wheels:1263232213634257066>'
}
])

Expand Down
4 changes: 2 additions & 2 deletions src/sendJudgeMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export const sendJudgeMessage = async ({

if (level.changerGateModes.size > 0) {
const changerGateModes = [...level.changerGateModes]
.map(({ mode, emoji }) => `${emoji} ${mode}`)
.join(', ')
.map(({ emoji }) => `${emoji}`)
.join(' ')

embed.addFields([
{
Expand Down

0 comments on commit 5fb4463

Please sign in to comment.