feat: just a bunch of nits and fixes
This commit is contained in:
parent
77a4f9121d
commit
8bb2dc16b1
8 changed files with 75 additions and 12 deletions
|
@ -46,6 +46,9 @@
|
|||
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
||||
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" />
|
||||
</HTMLCodeStyleSettings>
|
||||
<JSCodeStyleSettings version="0">
|
||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||
</JSCodeStyleSettings>
|
||||
<Markdown>
|
||||
<option name="MAX_LINES_AROUND_HEADER" value="0" />
|
||||
<option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" />
|
||||
|
@ -58,6 +61,7 @@
|
|||
<option name="ENFORCE_QUOTES_ON_FORMAT" value="true" />
|
||||
</ScssCodeStyleSettings>
|
||||
<TypeScriptCodeStyleSettings version="0">
|
||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||
<option name="USE_PUBLIC_MODIFIER" value="true" />
|
||||
<option name="PREFER_AS_TYPE_CAST" value="true" />
|
||||
<option name="IMPORT_SORT_MODULE_NAME" value="true" />
|
||||
|
@ -101,6 +105,11 @@
|
|||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="JavaScript">
|
||||
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_WHILE_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_FOR_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
|
@ -147,6 +156,11 @@
|
|||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="TypeScript">
|
||||
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_WHILE_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_FOR_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
|
||||
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
||||
|
|
|
@ -180,6 +180,10 @@
|
|||
"switch": {
|
||||
"before": true,
|
||||
"after": false
|
||||
},
|
||||
"for": {
|
||||
"before": true,
|
||||
"after": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,30 @@
|
|||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||
*/
|
||||
import Command from '@structures/command';
|
||||
|
||||
import type { Client, Message } from 'discord.js';
|
||||
import i18next from 'i18next';
|
||||
import { transpile } from 'typescript';
|
||||
import { NodeVM } from 'vm2';
|
||||
|
||||
import type { Client, Message } from 'discord.js';
|
||||
|
||||
export class vm extends Command {
|
||||
public constructor(client: Client, file: string) {
|
||||
super(client, file);
|
||||
super(client, file, {
|
||||
shortDescription: i18next.t('commands:vm.shortDescription'),
|
||||
extendedDescription: i18next.t('commands:vm.extendedDescription'),
|
||||
args: [
|
||||
{
|
||||
name: 'language',
|
||||
acceptedValues: ['js', 'javascript', 'ts', 'typescript'],
|
||||
description: i18next.t('commands:vm.languageArg'),
|
||||
},
|
||||
{
|
||||
name: 'code',
|
||||
goToEnd: true,
|
||||
description: i18next.t('commands:vm.codeArg'),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
public async run(message: Message, vmLang: string, ...codeArray: string[]): Promise<void> {
|
||||
|
|
13
src/index.ts
13
src/index.ts
|
@ -87,18 +87,20 @@ client.on('message', async (msg) => {
|
|||
|
||||
if(!findCommand) return;
|
||||
|
||||
await msg.channel.startTyping();
|
||||
|
||||
if(findCommand.options.ownerOnly && msg.author.id !== config.get('owner')) {
|
||||
await msg.reply('Only the bot owner can run this command!');
|
||||
await msg.reply(i18next.t('commands:errors.ownerOnly'));
|
||||
return;
|
||||
}
|
||||
|
||||
if((findCommand.options.runIn === ECommandRunIn.DM) && msg.channel.type !== 'dm') {
|
||||
await msg.reply('You can only run this command in DMs!');
|
||||
await msg.reply(i18next.t('commands:errors.dmsOnly'));
|
||||
return;
|
||||
}
|
||||
|
||||
if((findCommand.options.runIn === ECommandRunIn.Server) && msg.channel.type !== 'text') {
|
||||
await msg.reply('You can only run this command in a server!');
|
||||
await msg.reply(i18next.t('commands:errors.serverOnly'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -106,10 +108,11 @@ client.on('message', async (msg) => {
|
|||
info(`Command ${findCommand.options.name} is being ran in ${msg.guild ? msg.guild.name : 'DMs'}`, ELoggingScope.Command);
|
||||
await findCommand.run(msg, ...args);
|
||||
info(`Finished running ${findCommand.options.name} in ${msg.guild ? msg.guild.name : `${msg.author.username} DMs`}`, ELoggingScope.Command);
|
||||
msg.channel.stopTyping();
|
||||
} catch(e) {
|
||||
error(`An error has occurred while running ${findCommand.options.name}!\n${e.message}`, ELoggingScope.Command);
|
||||
msg.reply('I\'m sorry but an error has occurred while running this command! Please file an issue to' +
|
||||
` https://code.relms.dev/Relms/ArgonBot!\n\`\`\`${e.message}\`\`\``);
|
||||
await msg.reply(i18next.t('commands:errors.runError', { error: e.message }));
|
||||
msg.channel.stopTyping();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||
*/
|
||||
import config from 'config';
|
||||
import path from 'path';
|
||||
|
||||
import type { ICommandOptions } from '@utils/types';
|
||||
import { ECommandRunIn } from '@utils/types';
|
||||
import config from 'config';
|
||||
import type { Client, Message } from 'discord.js';
|
||||
import path from 'path';
|
||||
|
||||
export default abstract class Command {
|
||||
public readonly client: Client;
|
||||
|
@ -32,6 +32,10 @@ export default abstract class Command {
|
|||
const defaultOptions: ICommandOptions = {
|
||||
name: path.basename(this.file, path.extname(this.file)),
|
||||
group: path.basename(path.dirname(this.file)) === 'commands' ? '' : path.basename(path.dirname(this.file)),
|
||||
ownerOnly: false,
|
||||
runIn: ECommandRunIn.Both,
|
||||
shortDescription: '',
|
||||
extendedDescription: '',
|
||||
};
|
||||
|
||||
this.options = config.util.extendDeep(defaultOptions, options);
|
||||
|
|
|
@ -37,6 +37,13 @@ export interface ICommandOptions {
|
|||
group?: string;
|
||||
ownerOnly?: boolean;
|
||||
runIn?: ECommandRunIn;
|
||||
args?: {
|
||||
name: string;
|
||||
description?: string;
|
||||
acceptedValues?: string[];
|
||||
goToEnd?: boolean;
|
||||
optional?: boolean;
|
||||
}[];
|
||||
}
|
||||
|
||||
// Type Aliases
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
{
|
||||
"vm": {
|
||||
"shortDescription": "Runs code in a safe sandbox for testing",
|
||||
"extendedDescription": "Runs code in a secure and safe sandbox for prototyping & testing code while preventing access to the system",
|
||||
"languageArg": "The language to use (JavaScript/TypeScript)",
|
||||
"codeArg": "The code to run in the VM",
|
||||
"computing": "Computing { $language } code... Please wait!",
|
||||
"error": "An error has occurred while executing JavaScript code!\n```\n{{ $error }}\n```",
|
||||
"error": "An error has occurred while executing JavaScript code!\n```\n{ $error }\n```",
|
||||
"unknown": "Unknown language given!"
|
||||
},
|
||||
"errors": {
|
||||
"ownerOnly": "Only the bot owner can run this command!",
|
||||
"dmsOnly": "You can only run this command in DMs!",
|
||||
"serverOnly": "You can only run this command in a server!",
|
||||
"runError": "I'm sorry but an error has occurred while running this command! Please file an issue to https://code.relms.dev/Relms/ArgonBot!\n```{ $error }```"
|
||||
},
|
||||
"generic": {
|
||||
"noShortDescription": "No short description given!",
|
||||
"noExtendedDescription": "No extended description given!",
|
||||
"noArgsDescription": "No description for { $arg } has been given!"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{}
|
Reference in a new issue