Archived
0
0
Fork 0

feat: just a bunch of nits and fixes

This commit is contained in:
Daryl Ronningen 2021-06-29 12:15:00 -05:00
parent 77a4f9121d
commit 8bb2dc16b1
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
8 changed files with 75 additions and 12 deletions

View file

@ -46,6 +46,9 @@
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" /> <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" /> <option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" />
</HTMLCodeStyleSettings> </HTMLCodeStyleSettings>
<JSCodeStyleSettings version="0">
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
</JSCodeStyleSettings>
<Markdown> <Markdown>
<option name="MAX_LINES_AROUND_HEADER" value="0" /> <option name="MAX_LINES_AROUND_HEADER" value="0" />
<option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" /> <option name="MAX_LINES_AROUND_BLOCK_ELEMENTS" value="0" />
@ -58,6 +61,7 @@
<option name="ENFORCE_QUOTES_ON_FORMAT" value="true" /> <option name="ENFORCE_QUOTES_ON_FORMAT" value="true" />
</ScssCodeStyleSettings> </ScssCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0"> <TypeScriptCodeStyleSettings version="0">
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="USE_PUBLIC_MODIFIER" value="true" /> <option name="USE_PUBLIC_MODIFIER" value="true" />
<option name="PREFER_AS_TYPE_CAST" value="true" /> <option name="PREFER_AS_TYPE_CAST" value="true" />
<option name="IMPORT_SORT_MODULE_NAME" value="true" /> <option name="IMPORT_SORT_MODULE_NAME" value="true" />
@ -101,6 +105,11 @@
</indentOptions> </indentOptions>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="JavaScript"> <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> <indentOptions>
<option name="INDENT_SIZE" value="2" /> <option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="2" />
@ -147,6 +156,11 @@
</arrangement> </arrangement>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="TypeScript"> <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> <indentOptions>
<option name="INDENT_SIZE" value="2" /> <option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" /> <option name="CONTINUATION_INDENT_SIZE" value="2" />

View file

@ -180,6 +180,10 @@
"switch": { "switch": {
"before": true, "before": true,
"after": false "after": false
},
"for": {
"before": true,
"after": false
} }
} }
} }

View file

@ -15,15 +15,30 @@
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>. * along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/ */
import Command from '@structures/command'; import Command from '@structures/command';
import type { Client, Message } from 'discord.js';
import i18next from 'i18next'; import i18next from 'i18next';
import { transpile } from 'typescript'; import { transpile } from 'typescript';
import { NodeVM } from 'vm2'; import { NodeVM } from 'vm2';
import type { Client, Message } from 'discord.js';
export class vm extends Command { export class vm extends Command {
public constructor(client: Client, file: string) { 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> { public async run(message: Message, vmLang: string, ...codeArray: string[]): Promise<void> {

View file

@ -87,18 +87,20 @@ client.on('message', async (msg) => {
if(!findCommand) return; if(!findCommand) return;
await msg.channel.startTyping();
if(findCommand.options.ownerOnly && msg.author.id !== config.get('owner')) { 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; return;
} }
if((findCommand.options.runIn === ECommandRunIn.DM) && msg.channel.type !== 'dm') { 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; return;
} }
if((findCommand.options.runIn === ECommandRunIn.Server) && msg.channel.type !== 'text') { 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; 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); info(`Command ${findCommand.options.name} is being ran in ${msg.guild ? msg.guild.name : 'DMs'}`, ELoggingScope.Command);
await findCommand.run(msg, ...args); await findCommand.run(msg, ...args);
info(`Finished running ${findCommand.options.name} in ${msg.guild ? msg.guild.name : `${msg.author.username} DMs`}`, ELoggingScope.Command); info(`Finished running ${findCommand.options.name} in ${msg.guild ? msg.guild.name : `${msg.author.username} DMs`}`, ELoggingScope.Command);
msg.channel.stopTyping();
} catch(e) { } catch(e) {
error(`An error has occurred while running ${findCommand.options.name}!\n${e.message}`, ELoggingScope.Command); 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' + await msg.reply(i18next.t('commands:errors.runError', { error: e.message }));
` https://code.relms.dev/Relms/ArgonBot!\n\`\`\`${e.message}\`\`\``); msg.channel.stopTyping();
} }
}); });

View file

@ -14,11 +14,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>. * 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 type { ICommandOptions } from '@utils/types';
import { ECommandRunIn } from '@utils/types';
import config from 'config';
import type { Client, Message } from 'discord.js'; import type { Client, Message } from 'discord.js';
import path from 'path';
export default abstract class Command { export default abstract class Command {
public readonly client: Client; public readonly client: Client;
@ -32,6 +32,10 @@ export default abstract class Command {
const defaultOptions: ICommandOptions = { const defaultOptions: ICommandOptions = {
name: path.basename(this.file, path.extname(this.file)), name: path.basename(this.file, path.extname(this.file)),
group: path.basename(path.dirname(this.file)) === 'commands' ? '' : path.basename(path.dirname(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); this.options = config.util.extendDeep(defaultOptions, options);

View file

@ -37,6 +37,13 @@ export interface ICommandOptions {
group?: string; group?: string;
ownerOnly?: boolean; ownerOnly?: boolean;
runIn?: ECommandRunIn; runIn?: ECommandRunIn;
args?: {
name: string;
description?: string;
acceptedValues?: string[];
goToEnd?: boolean;
optional?: boolean;
}[];
} }
// Type Aliases // Type Aliases

View file

@ -1,7 +1,22 @@
{ {
"vm": { "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!", "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!" "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!"
} }
} }

View file

@ -0,0 +1 @@
{}