Convert unnecessary async functions
This commit is contained in:
parent
239d69d6d3
commit
20f4849fee
8 changed files with 19 additions and 14 deletions
|
@ -11,8 +11,9 @@ class EvalCommand extends Command {
|
|||
await this.acknowledge();
|
||||
const code = this.options.code ?? this.args.join(" ");
|
||||
try {
|
||||
const evaled = eval(code);
|
||||
const cleaned = await clean(evaled);
|
||||
let evaled = eval(code);
|
||||
if (evaled?.constructor?.name == "Promise") evaled = await evaled;
|
||||
const cleaned = clean(evaled);
|
||||
const sendString = `\`\`\`js\n${cleaned}\n\`\`\``;
|
||||
if (sendString.length >= 2000) {
|
||||
return {
|
||||
|
@ -24,7 +25,9 @@ class EvalCommand extends Command {
|
|||
return sendString;
|
||||
}
|
||||
} 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\`\`\``;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,10 @@ export default async (client, cluster, worker, ipc, interaction) => {
|
|||
} else {
|
||||
logger.error(`Error occurred with application command ${command} with arguments ${JSON.stringify(interaction.data.options)}: ${error.stack || error}`);
|
||||
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>", {
|
||||
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"
|
||||
});
|
||||
} catch { /* silently ignore */ }
|
||||
|
|
|
@ -155,10 +155,12 @@ export default async (client, cluster, worker, ipc, message) => {
|
|||
} else {
|
||||
_error(`Error occurred with command message ${message.cleanContent}: ${error.stack || error}`);
|
||||
try {
|
||||
let err = error;
|
||||
if (error?.constructor?.name == "Promise") err = await error;
|
||||
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>"
|
||||
}, 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"
|
||||
}]);
|
||||
} catch { /* silently ignore */ }
|
||||
|
|
2
shard.js
2
shard.js
|
@ -81,7 +81,7 @@ class Shard extends BaseClusterWorker {
|
|||
|
||||
// generate docs
|
||||
if (process.env.OUTPUT && process.env.OUTPUT !== "") {
|
||||
await generateList();
|
||||
generateList();
|
||||
if (this.clusterID === 0) {
|
||||
await createPage(process.env.OUTPUT);
|
||||
log("info", "The help docs have been generated.");
|
||||
|
|
|
@ -74,7 +74,7 @@ export async function load(client, command, soundStatus, slashReload = false) {
|
|||
return commandName;
|
||||
}
|
||||
|
||||
export async function update() {
|
||||
export function update() {
|
||||
const commandArray = [];
|
||||
const privateCommandArray = [];
|
||||
const merged = new Map([...commands, ...messageCommands]);
|
||||
|
@ -118,7 +118,7 @@ export async function update() {
|
|||
}
|
||||
|
||||
export async function send(bot) {
|
||||
const commandArray = await update();
|
||||
const commandArray = update();
|
||||
log("info", "Sending application command data to Discord...");
|
||||
let cmdArray = commandArray.main;
|
||||
if (process.env.ADMIN_SERVER && process.env.ADMIN_SERVER !== "") {
|
||||
|
|
|
@ -10,7 +10,7 @@ export let categories = categoryTemplate;
|
|||
|
||||
export let generated = false;
|
||||
|
||||
export async function generateList() {
|
||||
export function generateList() {
|
||||
categories = categoryTemplate;
|
||||
for (const [command] of commands) {
|
||||
const category = info.get(command).category;
|
||||
|
|
|
@ -13,9 +13,7 @@ const optionalReplace = (token) => {
|
|||
};
|
||||
|
||||
// clean(text) to clean message of any private info or mentions
|
||||
export async function clean(text) {
|
||||
if (text?.constructor?.name == "Promise")
|
||||
text = await text;
|
||||
export function clean(text) {
|
||||
if (typeof text !== "string")
|
||||
text = util.inspect(text, { depth: 1 });
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ export async function checkStatus() {
|
|||
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 });
|
||||
client.emit("ready"); // workaround
|
||||
manager.on("error", (node, error) => {
|
||||
|
@ -71,7 +71,7 @@ export async function play(client, sound, options, music = false) {
|
|||
if (!node) {
|
||||
const status = await checkStatus();
|
||||
if (!status) {
|
||||
await connect(client);
|
||||
connect(client);
|
||||
node = manager.getNode();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue