Archived
0
0
Fork 0

chore: removed the goddamn motherfucking pnp features

This commit is contained in:
Daryl Ronningen 2021-06-29 18:41:45 -05:00
parent 8bb2dc16b1
commit 82d66ffbe8
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
24 changed files with 426 additions and 1471 deletions

View file

@ -47,7 +47,13 @@
<option name="HTML_DO_NOT_INDENT_CHILDREN_OF" value="" />
</HTMLCodeStyleSettings>
<JSCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings>
<Markdown>
<option name="MAX_LINES_AROUND_HEADER" value="0" />
@ -61,9 +67,15 @@
<option name="ENFORCE_QUOTES_ON_FORMAT" value="true" />
</ScssCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<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="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
<option name="IMPORT_SORT_MODULE_NAME" value="true" />
</TypeScriptCodeStyleSettings>
<codeStyleSettings language="CSS">
@ -105,8 +117,9 @@
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<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" />
@ -156,8 +169,9 @@
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="TypeScript">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<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" />

View file

@ -3,4 +3,4 @@
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint"
]
}
}

View file

@ -1,13 +1,10 @@
{
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
},
"eslint.nodePath": ".yarn/sdks",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"eslint.format.enable": true,
"eslint.lintTask.enable": true,
@ -15,4 +12,4 @@
"editor.insertSpaces": false,
"editor.tabSize": 2,
"typescript.preferences.quoteStyle": "single"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,20 +0,0 @@
#!/usr/bin/env node
const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);
const relPnpApiPath = "../../../../.pnp.cjs";
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require eslint/lib/api.js
require(absPnpApiPath).setup();
}
}
// Defer to the real eslint/lib/api.js your application uses
module.exports = absRequire(`eslint/lib/api.js`);

View file

@ -1,6 +0,0 @@
{
"name": "eslint",
"version": "7.28.0-pnpify",
"main": "./lib/api.js",
"type": "commonjs"
}

View file

@ -1,5 +0,0 @@
# This file is automatically generated by PnPify.
# Manual changes will be lost!
integrations:
- vscode

View file

@ -1,20 +0,0 @@
#!/usr/bin/env node
const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);
const relPnpApiPath = "../../../../.pnp.cjs";
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/lib/tsc.js
require(absPnpApiPath).setup();
}
}
// Defer to the real typescript/lib/tsc.js your application uses
module.exports = absRequire(`typescript/lib/tsc.js`);

View file

@ -1,143 +0,0 @@
#!/usr/bin/env node
const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);
const relPnpApiPath = "../../../../.pnp.cjs";
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
const moduleWrapper = tsserver => {
const {isAbsolute} = require(`path`);
const pnpApi = require(`pnpapi`);
const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
return `${locator.name}@${locator.reference}`;
}));
// VSCode sends the zip paths to TS using the "zip://" prefix, that TS
// doesn't understand. This layer makes sure to remove the protocol
// before forwarding it to TS, and to add it back on all returned paths.
function toEditorPath(str) {
// We add the `zip:` prefix to both `.zip/` paths and virtual paths
if (isAbsolute(str) && !str.match(/^\^zip:/) && (str.match(/\.zip\//) || isVirtual(str))) {
// We also take the opportunity to turn virtual paths into physical ones;
// this makes it much easier to work with workspaces that list peer
// dependencies, since otherwise Ctrl+Click would bring us to the virtual
// file instances instead of the real ones.
//
// We only do this to modules owned by the the dependency tree roots.
// This avoids breaking the resolution when jumping inside a vendor
// with peer dep (otherwise jumping into react-dom would show resolution
// errors on react).
//
const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
if (resolved) {
const locator = pnpApi.findPackageLocator(resolved);
if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
str = resolved;
}
}
str = normalize(str);
if (str.match(/\.zip\//)) {
switch (hostInfo) {
// Absolute VSCode `Uri.fsPath`s need to start with a slash.
// VSCode only adds it automatically for supported schemes,
// so we have to do it manually for the `zip` scheme.
// The path needs to start with a caret otherwise VSCode doesn't handle the protocol
//
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
//
case `vscode`: {
str = `^zip:${str}`;
} break;
// To make "go to definition" work,
// We have to resolve the actual file system path from virtual path
// and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
case `coc-nvim`: {
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
str = resolve(`zipfile:${str}`);
} break;
default: {
str = `zip:${str}`;
} break;
}
}
}
return str;
}
function fromEditorPath(str) {
return process.platform === `win32`
? str.replace(/^\^?zip:\//, ``)
: str.replace(/^\^?zip:/, ``);
}
// Force enable 'allowLocalPluginLoads'
// TypeScript tries to resolve plugins using a path relative to itself
// which doesn't work when using the global cache
// https://github.com/microsoft/TypeScript/blob/1b57a0395e0bff191581c9606aab92832001de62/src/server/project.ts#L2238
// VSCode doesn't want to enable 'allowLocalPluginLoads' due to security concerns but
// TypeScript already does local loads and if this code is running the user trusts the workspace
// https://github.com/microsoft/vscode/issues/45856
const ConfiguredProject = tsserver.server.ConfiguredProject;
const {enablePluginsWithOptions: originalEnablePluginsWithOptions} = ConfiguredProject.prototype;
ConfiguredProject.prototype.enablePluginsWithOptions = function() {
this.projectService.allowLocalPluginLoads = true;
return originalEnablePluginsWithOptions.apply(this, arguments);
};
// And here is the point where we hijack the VSCode <-> TS communications
// by adding ourselves in the middle. We locate everything that looks
// like an absolute path of ours and normalize it.
const Session = tsserver.server.Session;
const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
let hostInfo = `unknown`;
return Object.assign(Session.prototype, {
onMessage(/** @type {string} */ message) {
const parsedMessage = JSON.parse(message)
if (
parsedMessage != null &&
typeof parsedMessage === `object` &&
parsedMessage.arguments &&
typeof parsedMessage.arguments.hostInfo === `string`
) {
hostInfo = parsedMessage.arguments.hostInfo;
}
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
return typeof value === `string` ? fromEditorPath(value) : value;
}));
},
send(/** @type {any} */ msg) {
return originalSend.call(this, JSON.parse(JSON.stringify(msg, (key, value) => {
return typeof value === `string` ? toEditorPath(value) : value;
})));
}
});
};
if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/lib/tsserver.js
require(absPnpApiPath).setup();
}
}
// Defer to the real typescript/lib/tsserver.js your application uses
module.exports = moduleWrapper(absRequire(`typescript/lib/tsserver.js`));

View file

@ -1,20 +0,0 @@
#!/usr/bin/env node
const {existsSync} = require(`fs`);
const {createRequire, createRequireFromPath} = require(`module`);
const {resolve} = require(`path`);
const relPnpApiPath = "../../../../.pnp.cjs";
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
const absRequire = (createRequire || createRequireFromPath)(absPnpApiPath);
if (existsSync(absPnpApiPath)) {
if (!process.versions.pnp) {
// Setup the environment to be able to require typescript/lib/typescript.js
require(absPnpApiPath).setup();
}
}
// Defer to the real typescript/lib/typescript.js your application uses
module.exports = absRequire(`typescript/lib/typescript.js`);

View file

@ -1,6 +0,0 @@
{
"name": "typescript",
"version": "4.3.3-pnpify",
"main": "./lib/typescript.js",
"type": "commonjs"
}

View file

@ -1,9 +1,11 @@
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
yarnPath: .yarn/releases/yarn-sources.cjs
nodeLinker: node-modules

View file

@ -81,7 +81,6 @@
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"@typescript-eslint/typescript-estree": "^4.28.1",
"@yarnpkg/pnpify": "^3.0.0-rc.7",
"chai": "^4.3.4",
"eslint": "^7.29.0",
"eslint-formatter-pretty": "^4.1.0",

View file

@ -0,0 +1,58 @@
/*
* This file is part of ArgonBot
*
* ArgonBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ArgonBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
import Command from '@structures/command';
import { Client, Message, MessageEmbed } from 'discord.js';
import i18next from 'i18next';
import path from 'path';
export default class extends Command {
public constructor(client: Client, file: string) {
super(client, file, {
shortDescription: i18next.t('commands:help.shortDescription'),
extendedDescription: i18next.t('commands:help.extendedDescription'),
args: [
{
name: 'command',
description: i18next.t('commands:help.commandArg'),
optional: true,
},
],
});
}
public async run(message: Message, command: string): Promise<void> {
if(!command) {
const commandGroups: { name: string; embeds: MessageEmbed, commands: Command[] }[] = [];
this.client.commands.forEach((command) => {
const findCommand = commandGroups.find((val) => val.name === command.options.group);
if(findCommand) {
findCommand.commands.push(command);
} else {
commandGroups.push({
name: command.options.group!,
embeds: new MessageEmbed(),
commands: [command],
});
}
});
console.log(path.basename(this.file));
}
}
}

View file

@ -21,7 +21,7 @@ import i18next from 'i18next';
import { transpile } from 'typescript';
import { NodeVM } from 'vm2';
export class vm extends Command {
export default class extends Command {
public constructor(client: Client, file: string) {
super(client, file, {
shortDescription: i18next.t('commands:vm.shortDescription'),
@ -59,7 +59,7 @@ export class vm extends Command {
await message.reply(`\`\`\`js\n${returnVal}\`\`\``);
} catch(err) {
await message.reply(i18next.t('commands:vm.error', { error: err.message }));
await message.reply(i18next.t('commands:vm.error', { error: err.message, language: 'JavaScript' }));
}
break;
case 'ts':
@ -77,7 +77,7 @@ export class vm extends Command {
await message.reply(`\`\`\`js\n${returnVal}\`\`\``);
} catch(err) {
await message.reply(i18next.t('commands:vm.error', { error: err.message }));
await message.reply(i18next.t('commands:vm.error', { error: err.message, language: 'TypeScript' }));
}
break;
default:

View file

@ -14,16 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
require('module-alias/register');
import 'module-alias/register';
import type Command from '@structures/command';
import ArgonClient from '@lib/ArgonClient';
import { Defaults } from '@utils/defaults';
import { debug, error, fatal, info, verbose } from '@utils/logger';
import { ECommandRunIn, ELoggingScope } from '@utils/types';
import { walkDir } from '@utils/utils';
import chalk from 'chalk';
import config from 'config';
import { Client, Collection } from 'discord.js';
import figlet from 'figlet';
import gradient from 'gradient-string';
import i18next from 'i18next';
@ -38,7 +37,6 @@ import path from 'path';
import process from 'process';
let isBotReady = false;
const commands: Collection<string, Command> = new Collection();
info('Starting bot... Please wait!', ELoggingScope.Startup);
debug('Checking config JSON schema', ELoggingScope.Startup);
@ -70,7 +68,7 @@ figlet('Argon Bot', (err, data) => {
info(gradient.rainbow.multiline(`\n${data}`), ELoggingScope.Startup);
});
const client = new Client({
const client = new ArgonClient({
intents: ['GUILDS', 'GUILD_MESSAGES'],
});
@ -83,11 +81,11 @@ client.on('message', async (msg) => {
const args = msg.content.slice((config.get('prefix') as string).length).trim().split(/ +/);
const command = args.shift()!.toLowerCase();
const findCommand = commands.find((com) => com.options.name === command);
const findCommand = client.commands.find((com) => com.options.name === command);
if(!findCommand) return;
await msg.channel.startTyping();
msg.channel.startTyping();
if(findCommand.options.ownerOnly && msg.author.id !== config.get('owner')) {
await msg.reply(i18next.t('commands:errors.ownerOnly'));
@ -105,7 +103,7 @@ client.on('message', async (msg) => {
}
try {
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'} by ${msg.author.username}`, 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();
@ -148,15 +146,15 @@ client.on('ready', async () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fileCommand = require(file);
const command = new fileCommand[path.basename(file, path.extname(file))](client, path.basename(file, path.extname(file)));
const command = new fileCommand['default'](client, path.basename(file, path.extname(file)));
commands.set(command.options.name, command);
client.commands.set(command.options.name, command);
debug(`Loaded command ${command.options.name}`, ELoggingScope.Startup);
}
});
info(`Finished loading commands! Found ${commands.size} commands.`, ELoggingScope.Startup);
info(`Finished loading commands! Found ${client.commands.size} commands.`, ELoggingScope.Startup);
} catch(err) {
fatal(`An error has occurred while attempting to load command files! Please see error below\n${err.message}`, ELoggingScope.Startup);
}

26
src/lib/ArgonClient.ts Normal file
View file

@ -0,0 +1,26 @@
/*
* This file is part of ArgonBot
*
* ArgonBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ArgonBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
import type Command from '@structures/command';
import { Client, ClientOptions, Collection } from 'discord.js';
export default class extends Client {
public readonly commands: Collection<string, Command> = new Collection();
public constructor(options: ClientOptions) {
super(options);
}
}

View file

@ -31,7 +31,7 @@ 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)),
group: path.dirname(this.file) === 'commands' ? '' : path.dirname(this.file),
ownerOnly: false,
runIn: ECommandRunIn.Both,
shortDescription: '',

16
src/lib/utils/augments.ts Normal file
View file

@ -0,0 +1,16 @@
/*
* This file is part of ArgonBot
*
* ArgonBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ArgonBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/

View file

@ -5,9 +5,15 @@
"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 { $language } code!\n```\n{ $error }\n```",
"unknown": "Unknown language given!"
},
"help": {
"shortDescription": "Shows help menu",
"extendedDescription": "Shows an advanced help menu for commands to show usage",
"commandArg": "The command to see",
"unknownCommand": "Unknown command given!"
},
"errors": {
"ownerOnly": "Only the bot owner can run this command!",
"dmsOnly": "You can only run this command in DMs!",

823
yarn.lock

File diff suppressed because it is too large Load diff