Skip to content

Commit

Permalink
feat(test): workflow, fix(removeCommand): message
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jan 8, 2022
1 parent 81ad565 commit 5dc234c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"always"
],
"prefer-const": "error",
"@typescript-eslint/no-explicit-any": "off"
"@typescript-eslint/no-explicit-any": "off",
"no-async-promise-executor": "off"
}
}
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Testing
on: [push, pull_request]
jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Node v16
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run lint

build:
name: Package
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Node v16
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install dependencies
run: npm ci

- name: Run package build
run: npm run build:babel
12 changes: 6 additions & 6 deletions src/commands/discord-api-manager/removeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default async() => {

const commands = await runJob(() => getCommands(clientId, response), 'Getting commands').catch(() => process.exit(1));

if (!Array.isArray(commands) || commands.length === 0) return console.log(chalk.red(`There are probably no commands, or you have entered some property wrong.`));
if (!Array.isArray(commands) || commands.length === 0) return console.log(chalk.red('There are probably no commands, or you have entered some property wrong.'));

const commandsToDelete = (await prompts(selectCommand(commands))).commands;

const jobs: [() => any, string][] = [
[() => deleteCommands(clientId, response, commandsToDelete, commands), 'Generating config']
[() => deleteCommands(clientId, response, commandsToDelete, commands), 'Removing commands']
];

for (const [job, message] of jobs) {
Expand Down Expand Up @@ -45,9 +45,9 @@ export const deleteCommands = (clientId, response, commandsToDelete, allCommands
}).catch(e => e);

if (res.ok) resolve(true);
else reject(res.data)
})
}
else reject(res.data);
});
};

export const getCommands = (clientId, response) => {
return new Promise(async(resolve, reject) => {
Expand All @@ -67,4 +67,4 @@ export const getCommands = (clientId, response) => {
if (res.ok) resolve(res.data);
else reject(res.data);
});
}
};
74 changes: 37 additions & 37 deletions src/prompts/discord-api-manager/removePrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ import type { PromptObject } from 'prompts';
export const removePrompt = (): Array<PromptObject> => {
return [
{
type: 'password',
name: 'token',
message: 'You must provide a token to fetch commands.'
},
{
type: 'select',
name: 'select',
message: 'Select whether the command you want to delete is a global or a guild command.',
choices: [
{
title: 'Global Command',
value: 'global'
},
{
title: 'Guild Command',
value: 'guild'
}
]
},
{
type: (prev) => prev === 'guild' ? 'text' : null,
name: 'guildId',
message: 'What\'s the id of your guild?'
}
type: 'password',
name: 'token',
message: 'You must provide a token to fetch commands.'
},
{
type: 'select',
name: 'select',
message: 'Select whether the command you want to delete is a global or a guild command.',
choices: [
{
title: 'Global Command',
value: 'global'
},
{
title: 'Guild Command',
value: 'guild'
}
]
},
{
type: (prev) => prev === 'guild' ? 'text' : null,
name: 'guildId',
message: 'What\'s the id of your guild?'
}
];
};

export const selectCommand = (commands): Array<PromptObject> => {
return [
{
type: 'multiselect',
name: 'commands',
message: 'Select the command you want to delete.',
choices: commands.map(c => new Object({
title: c.name,
value: c.id,
description: c.description
}))
}
]
}
return [
{
type: 'multiselect',
name: 'commands',
message: 'Select the command you want to delete.',
choices: commands.map(c => new Object({
title: c.name,
value: c.id,
description: c.description
}))
}
];
};

0 comments on commit 5dc234c

Please sign in to comment.