Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
chore(code): Reformat project
Browse files Browse the repository at this point in the history
  • Loading branch information
noxzym committed May 28, 2022
1 parent 383bb62 commit e796f2a
Show file tree
Hide file tree
Showing 64 changed files with 1,868 additions and 1,122 deletions.
106 changes: 106 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"tscompile": "tsc --build tsconfig.json",
"lint": "eslint . --ignore-path .gitignore --ext .ts",
"lint:fix": "eslint . --ignore-path .gitignore --ext .ts --fix",
"pretty": "prettier --check src/**/*.ts",
"pretty:write": "prettier --write src/**/*.ts",
"start": "node --es-module-specifier-resolution=node -r dotenv/config .",
"start:dev": "rimraf ./dist && npm run compile && npm start"
},
Expand All @@ -28,7 +30,13 @@
"npm": ">=7.0.0"
},
"eslintConfig": {
"extends": "@clytage-pkg/eslint-config/typescript",
"extends": [
"@clytage-pkg/eslint-config/typescript",
"prettier"
],
"plugins": [
"prettier"
],
"ignorePatterns": [
"dist/*",
"index.js",
Expand All @@ -38,6 +46,12 @@
"@typescript-eslint/no-extra-parens": "off"
}
},
"prettier": {
"tabWidth": 4,
"trailingComma": "none",
"arrowParens": "avoid",
"printWidth": 120
},
"dependencies": {
"@discordjs/voice": "0.9.0",
"@swc/cli": "0.1.57",
Expand All @@ -61,6 +75,9 @@
"@typescript-eslint/eslint-plugin": "5.26.0",
"@typescript-eslint/parser": "5.26.0",
"eslint": "8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typescript": "4.7.2"
},
Expand Down
10 changes: 7 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ const client = new Rawon(clientOptions);

process
.on("exit", code => client.logger.info(`NodeJS process exited with code ${code}`))
.on("unhandledRejection", reason => client.logger.error("UNHANDLED_REJECTION:", (reason as Error).stack ? reason : new NoStackError(reason as string)))
.on("unhandledRejection", reason =>
client.logger.error(
"UNHANDLED_REJECTION:",
(reason as Error).stack ? reason : new NoStackError(reason as string)
)
)
.on("warning", (...args) => client.logger.warn(...args))
.on("uncaughtException", err => {
client.logger.error("UNCAUGHT_EXCEPTION:", err);
client.logger.warn("Uncaught Exception detected, trying to restart...");
process.exit(1);
});

client.build()
.catch(e => client.logger.error("PROMISE_ERR:", e));
client.build().catch(e => client.logger.error("PROMISE_ERR:", e));
46 changes: 18 additions & 28 deletions src/commands/developers/EvalCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ export class EvalCommand extends BaseCommand {
const msg = ctx;
const client = this.client;

const code = ctx.args.join(" ")
.replace(
/^\s*\n?(```(?:[^\s]+\n)?(.*?)```|.*)$/s,
(_, a: string, b) => a.startsWith("```") ? b : a
);
const embed = createEmbed("info")
.addField("Input", `\`\`\`js\n${code}\`\`\``);
const code = ctx.args
.join(" ")
.replace(/^\s*\n?(```(?:[^\s]+\n)?(.*?)```|.*)$/s, (_, a: string, b) => (a.startsWith("```") ? b : a));
const embed = createEmbed("info").addField("Input", `\`\`\`js\n${code}\`\`\``);

try {
if (!code) {
Expand All @@ -35,25 +32,18 @@ export class EvalCommand extends BaseCommand {
});
}

const isAsync = (/.* --async( +)?(--silent)?$/).test(code);
const isSilent = (/.* --silent( +)?(--async)?$/).test(code);
const toExecute = isAsync || isSilent
? code.replace(/--(async|silent)( +)?(--(silent|async))?$/, "")
: code;
const evaled = inspect(
await eval(
isAsync
? `(async () => {\n${toExecute}\n})()`
: toExecute
), { depth: 0 }
);
const isAsync = /.* --async( +)?(--silent)?$/.test(code);
const isSilent = /.* --silent( +)?(--async)?$/.test(code);
const toExecute =
isAsync || isSilent ? code.replace(/--(async|silent)( +)?(--(silent|async))?$/, "") : code;
const evaled = inspect(await eval(isAsync ? `(async () => {\n${toExecute}\n})()` : toExecute), {
depth: 0
});

if (isSilent) return;

const cleaned = this.clean(evaled);
const output = cleaned.length > 1024
? `${await this.hastebin(cleaned)}.js`
: `\`\`\`js\n${cleaned}\`\`\``;
const output = cleaned.length > 1024 ? `${await this.hastebin(cleaned)}.js` : `\`\`\`js\n${cleaned}\`\`\``;

embed.addField(i18n.__("commands.developers.eval.outputString"), output);
ctx.send({
Expand All @@ -65,9 +55,7 @@ export class EvalCommand extends BaseCommand {
} catch (e) {
const cleaned = this.clean(String(e));
const isTooLong = cleaned.length > 1024;
const error = isTooLong
? `${await this.hastebin(cleaned)}.js`
: `\`\`\`js\n${cleaned}\`\`\``;
const error = isTooLong ? `${await this.hastebin(cleaned)}.js` : `\`\`\`js\n${cleaned}\`\`\``;

embed.setColor("RED").addField(i18n.__("commands.developers.eval.errorString"), error);
ctx.send({
Expand All @@ -88,9 +76,11 @@ export class EvalCommand extends BaseCommand {
}

private async hastebin(text: string): Promise<string> {
const result = await this.client.request.post("https://bin.clytage.org/documents", {
body: text
}).json<{ key: string }>();
const result = await this.client.request
.post("https://bin.clytage.org/documents", {
body: text
})
.json<{ key: string }>();

return `https://bin.clytage.org/${result.key}`;
}
Expand Down
17 changes: 10 additions & 7 deletions src/commands/general/AboutCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ export class AboutCommand extends BaseCommand {
];
const value = createTable(values);

void ctx.reply({
embeds: [createEmbed("info", `\`\`\`asciidoc\n${value}\n\`\`\``)
.setAuthor({
name: i18n.__mf("commands.general.about.aboutFooter", {
botname: this.client.user?.username ?? "Unknown"
void ctx
.reply({
embeds: [
createEmbed("info", `\`\`\`asciidoc\n${value}\n\`\`\``).setAuthor({
name: i18n.__mf("commands.general.about.aboutFooter", {
botname: this.client.user?.username ?? "Unknown"
})
})
})]
}).catch(e => this.client.logger.error("ABOUT_CMD_ERR:", e));
]
})
.catch(e => this.client.logger.error("ABOUT_CMD_ERR:", e));
}
}
Loading

0 comments on commit e796f2a

Please sign in to comment.