Convert unnecessary async functions

This commit is contained in:
Essem 2022-09-10 23:18:44 -05:00
parent 239d69d6d3
commit 20f4849fee
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
8 changed files with 19 additions and 14 deletions

View file

@ -11,8 +11,9 @@ class EvalCommand extends Command {
await this.acknowledge(); await this.acknowledge();
const code = this.options.code ?? this.args.join(" "); const code = this.options.code ?? this.args.join(" ");
try { try {
const evaled = eval(code); let evaled = eval(code);
const cleaned = await clean(evaled); if (evaled?.constructor?.name == "Promise") evaled = await evaled;
const cleaned = clean(evaled);
const sendString = `\`\`\`js\n${cleaned}\n\`\`\``; const sendString = `\`\`\`js\n${cleaned}\n\`\`\``;
if (sendString.length >= 2000) { if (sendString.length >= 2000) {
return { return {
@ -24,7 +25,9 @@ class EvalCommand extends Command {
return sendString; return sendString;
} }
} catch (err) { } catch (err) {
return `\`ERROR\` \`\`\`xl\n${await clean(err)}\n\`\`\``; let error = err;
if (err?.constructor?.name == "Promise") error = await err;
return `\`ERROR\` \`\`\`xl\n${clean(error)}\n\`\`\``;
} }
} }

View file

@ -61,8 +61,10 @@ export default async (client, cluster, worker, ipc, interaction) => {
} else { } else {
logger.error(`Error occurred with application command ${command} with arguments ${JSON.stringify(interaction.data.options)}: ${error.stack || error}`); logger.error(`Error occurred with application command ${command} with arguments ${JSON.stringify(interaction.data.options)}: ${error.stack || error}`);
try { try {
let err = error;
if (error?.constructor?.name == "Promise") err = await error;
await interaction[replyMethod]("Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>", { await interaction[replyMethod]("Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>", {
file: `Message: ${await clean(error)}\n\nStack Trace: ${await clean(error.stack)}`, file: `Message: ${clean(err)}\n\nStack Trace: ${clean(err.stack)}`,
name: "error.txt" name: "error.txt"
}); });
} catch { /* silently ignore */ } } catch { /* silently ignore */ }

View file

@ -155,10 +155,12 @@ export default async (client, cluster, worker, ipc, message) => {
} else { } else {
_error(`Error occurred with command message ${message.cleanContent}: ${error.stack || error}`); _error(`Error occurred with command message ${message.cleanContent}: ${error.stack || error}`);
try { try {
let err = error;
if (error?.constructor?.name == "Promise") err = await error;
await client.createMessage(message.channel.id, Object.assign({ await client.createMessage(message.channel.id, Object.assign({
content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>" content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>"
}, reference), [{ }, reference), [{
file: `Message: ${await clean(error)}\n\nStack Trace: ${await clean(error.stack)}`, file: `Message: ${clean(err)}\n\nStack Trace: ${clean(err.stack)}`,
name: "error.txt" name: "error.txt"
}]); }]);
} catch { /* silently ignore */ } } catch { /* silently ignore */ }

View file

@ -81,7 +81,7 @@ class Shard extends BaseClusterWorker {
// generate docs // generate docs
if (process.env.OUTPUT && process.env.OUTPUT !== "") { if (process.env.OUTPUT && process.env.OUTPUT !== "") {
await generateList(); generateList();
if (this.clusterID === 0) { if (this.clusterID === 0) {
await createPage(process.env.OUTPUT); await createPage(process.env.OUTPUT);
log("info", "The help docs have been generated."); log("info", "The help docs have been generated.");

View file

@ -74,7 +74,7 @@ export async function load(client, command, soundStatus, slashReload = false) {
return commandName; return commandName;
} }
export async function update() { export function update() {
const commandArray = []; const commandArray = [];
const privateCommandArray = []; const privateCommandArray = [];
const merged = new Map([...commands, ...messageCommands]); const merged = new Map([...commands, ...messageCommands]);
@ -118,7 +118,7 @@ export async function update() {
} }
export async function send(bot) { export async function send(bot) {
const commandArray = await update(); const commandArray = update();
log("info", "Sending application command data to Discord..."); log("info", "Sending application command data to Discord...");
let cmdArray = commandArray.main; let cmdArray = commandArray.main;
if (process.env.ADMIN_SERVER && process.env.ADMIN_SERVER !== "") { if (process.env.ADMIN_SERVER && process.env.ADMIN_SERVER !== "") {

View file

@ -10,7 +10,7 @@ export let categories = categoryTemplate;
export let generated = false; export let generated = false;
export async function generateList() { export function generateList() {
categories = categoryTemplate; categories = categoryTemplate;
for (const [command] of commands) { for (const [command] of commands) {
const category = info.get(command).category; const category = info.get(command).category;

View file

@ -13,9 +13,7 @@ const optionalReplace = (token) => {
}; };
// clean(text) to clean message of any private info or mentions // clean(text) to clean message of any private info or mentions
export async function clean(text) { export function clean(text) {
if (text?.constructor?.name == "Promise")
text = await text;
if (typeof text !== "string") if (typeof text !== "string")
text = util.inspect(text, { depth: 1 }); text = util.inspect(text, { depth: 1 });

View file

@ -31,7 +31,7 @@ export async function checkStatus() {
return status; return status;
} }
export async function connect(client) { export function connect(client) {
manager = new Shoukaku(new Connectors.Eris(client), nodes, { moveOnDisconnect: true, resume: true, reconnectInterval: 500, reconnectTries: 1 }); manager = new Shoukaku(new Connectors.Eris(client), nodes, { moveOnDisconnect: true, resume: true, reconnectInterval: 500, reconnectTries: 1 });
client.emit("ready"); // workaround client.emit("ready"); // workaround
manager.on("error", (node, error) => { manager.on("error", (node, error) => {
@ -71,7 +71,7 @@ export async function play(client, sound, options, music = false) {
if (!node) { if (!node) {
const status = await checkStatus(); const status = await checkStatus();
if (!status) { if (!status) {
await connect(client); connect(client);
node = manager.getNode(); node = manager.getNode();
} }
} }