Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
USERSATOSHI committed Nov 5, 2023
1 parent 0196350 commit 8365391
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ plugins
.idea
.vscode
.DS_Store
.env

/aoi
7 changes: 7 additions & 0 deletions src/core/parsers/objectParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export const ObjectQuoteRegex = /".*?"/g;
export function getObjectData(stringObject: string, currentObj: StringObject) {
let i = 0,
text = "";
let arrayEnded = false;
while (i < stringObject.length) {
const char = stringObject[i];
if (char === "{" || char === "[") {
const newObj = new StringObject(char, currentObj);
currentObj.addValue(`#StringObject_${newObj.name}#`);
currentObj = newObj;
} else if (char === "}" || char === "]") {
if(char === "]") arrayEnded = true;
currentObj.addEnd(char);
if (text.trim() !== "") {
let t = parseData(text.trim());
Expand Down Expand Up @@ -47,6 +49,11 @@ export function getObjectData(stringObject: string, currentObj: StringObject) {
currentObj.addKey(text.trim());
text = "";
} else if (char === ",") {
if(arrayEnded) {
i++;
arrayEnded = false;
continue;
}
if (currentObj.start === "[") {
let t = parseData(text.trim());
if (typeof t === "string") {
Expand Down
21 changes: 0 additions & 21 deletions src/core/plugin.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import functions from "./functions/index.js";
import { defaultCacheConfig } from "./util/DapiHelper.js";
export * from "./manager/Command.js";
export * from "./manager/Function.js";
export * from "./manager/Plugin.js";
export { AoiClient, functions,defaultCacheConfig };
6 changes: 0 additions & 6 deletions src/manager/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,7 @@ export class CommandManager {
const cmd = this[type].filter((cmd) => filter(cmd));
if (cmd.size) {
for (const command of cmd.values()) {
this.#client.managers.plugins.preCommand.forEach((plugin) => {
plugin.func({ command, data });
});
await command.__compiled__({ ...data, command });
this.#client.managers.plugins.postCommand.forEach((plugin) => {
plugin.func({ command, data });
});
}
}
}
Expand Down
53 changes: 0 additions & 53 deletions src/manager/Plugin.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/structures/AoiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Util } from "./Util.js";
import { FunctionManager } from "../manager/Function.js";
import { AoiClientProps, CommandTypes } from "../typings/types.js";
import { AoiClientEvents } from "../typings/enums.js";
import PluginManager from "../manager/Plugin.js";
import { onInteraction } from "../events/interactionCreate.js";
import { onReady } from "../events/ready.js";

Expand All @@ -25,7 +24,6 @@ class AoiClient {
this.managers = {
commands: new CommandManager(this),
functions: new FunctionManager(this),
plugins: new PluginManager(),
};
this.options = options;
if (options.caches)
Expand All @@ -36,11 +34,6 @@ class AoiClient {
this.util = Util;
Util.client = this;
this.__on__ = {};

const plugs = this.managers.plugins.getPlugins("load");
for (const plug of plugs) {
plug.func(this);
}
}
#bindEvents() {
for (const event of this.options.events)
Expand Down
2 changes: 0 additions & 2 deletions src/typings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
TranspiledFuncData,
} from "./interfaces.js";
import { AoiClientEvents } from "./enums.js";
import PluginManager from "../manager/Plugin.js";

export type CommandTypes =
| "basic"
Expand Down Expand Up @@ -51,7 +50,6 @@ export type AoiClientProps = {
managers: {
commands: CommandManager;
functions: FunctionManager;
plugins: PluginManager;
};
options: AoiClientOptions;
cache?: Cacher;
Expand Down
25 changes: 17 additions & 8 deletions src/util/transpilerHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ import { funcData } from "../typings/interfaces.js";
import { TranspilerCustoms } from "../typings/enums.js";
import { StringObject, parseStringObject } from "../index.js";
import { Command } from "../structures/Command.js";

export function areBracketsBalanced(code: string) {
const leftbracket = /\[/g;
const rightbracket = /\]/g;
const leftbracketCount = code.match(leftbracket)?.length ?? 0;
const rightbracketCount = code.match(rightbracket)?.length ?? 0;
return leftbracketCount === rightbracketCount;
}

export function countBrackets(code: string) {
const leftbracket = /\[/g;
const rightbracket = /\]/g;
const leftbracketCount = code.match(leftbracket)?.length ?? 0;
const rightbracketCount = code.match(rightbracket)?.length ?? 0;
return { leftbracketCount, rightbracketCount };
}

export function parseData(text: string) {
if (text === "") return text;
else if (!isNaN(Number(text)) && Number.isSafeInteger(Number(text)))
Expand Down Expand Up @@ -61,6 +64,7 @@ export function escapeResult(res: string) {
export function escapeMathResult(res: string) {
return `${TranspilerCustoms.MFS}${res}${TranspilerCustoms.MFE}`;
}

export function parseResult(result: string) {
if (typeof result !== "string") return result;
return result
Expand Down Expand Up @@ -95,7 +99,7 @@ export function getFunctionData(
code: string,
func: string,
functions: string[],
command?:Command,
command?: Command,
): funcData {
const FuncD = FUNCDATA[func];
const reg = new RegExp(`${func.replace("$", "\\$")}`, "i");
Expand All @@ -111,12 +115,12 @@ export function getFunctionData(
let rawTotal = "";
// eslint-disable-next-line no-constant-condition
while (true) {
if(i >= code.length) break;
if (i >= code.length) break;
if (!FuncD?.brackets && !code.slice(func.length).startsWith("[")) {
break;
}
if (!FuncD?.optional && !code.slice(func.length).startsWith("[")) {
throw new TranspilerError("Function requires brackets",{
throw new TranspilerError("Function requires brackets", {
function: {
name: func,
code: func,
Expand Down Expand Up @@ -228,18 +232,23 @@ export function reverseArray(arr: funcData[]) {
export function Reverse(code: string, funcs: funcData[]) {
let codeWithGenricFuncs = code;

for(const func of funcs) {
codeWithGenricFuncs = codeWithGenricFuncs.replace(func.total, "#GENERIC-FUNCTION#");
for (const func of funcs) {
codeWithGenricFuncs = codeWithGenricFuncs.replace(
func.total,
"#GENERIC-FUNCTION#",
);
}

const reversedFuncs = reverseArray(funcs);

for(const func of reversedFuncs) {
codeWithGenricFuncs = codeWithGenricFuncs.replace("#GENERIC-FUNCTION#", func.total);
for (const func of reversedFuncs) {
codeWithGenricFuncs = codeWithGenricFuncs.replace(
"#GENERIC-FUNCTION#",
func.total,
);
}

return { code: codeWithGenricFuncs, funcs: reversedFuncs };

}

export function ExecuteData(
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"module": "NodeNext",
"outDir": "dist/esm",
"target": "ESNext"
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"module": "ESNext",
"module": "NodeNext",
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"declaration": true,
Expand Down

0 comments on commit 8365391

Please sign in to comment.