Skip to content

Commit

Permalink
catch lock error
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Jan 11, 2024
1 parent 22320aa commit 69ec8b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/commands/editsnipe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Snipe } from "../util/Cache.js";
import Command from "../util/Command.js";
import EncryptionHandler from "../util/EncryptionHandler.js";
import { filter, getSnipe } from "../util/util.js";
Expand All @@ -17,7 +18,16 @@ export default class EditSnipeCommand extends Command {
override type = ApplicationCommandTypes.CHAT_INPUT;
override async run(this: Client, interaction: CommandInteraction) {
const channel = interaction.data.options.getChannelOption("channel")?.value || interaction.channelID;
const snipe = await getSnipe(channel, "edit");
let snipe: Snipe | null;
try {
snipe = await getSnipe(channel, "edit");
} catch (e) {
const err = e as Error;
return interaction.createMessage({
content: `Failed to fetch snipe: **${err.name}: ${err.message}**`,
flags: MessageFlags.EPHEMERAL
});
}
if (!snipe) {
return interaction.createMessage({
content: "No snipes found.",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class EvalCommand extends Command {
{
title: "Eval Result",
// eslint-disable-next-line no-eval, @typescript-eslint/restrict-template-expressions
description: `\`\`\`js\n${eval(interaction.data.options.getString("code", true))}\`\`\``
description: `\`\`\`js\n${await eval(interaction.data.options.getString("code", true))}\`\`\``
}
]
});
Expand Down
12 changes: 11 additions & 1 deletion src/commands/snipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Command from "../util/Command.js";
import { filter, getSnipe } from "../util/util.js";
import EncryptionHandler from "../util/EncryptionHandler.js";
import { type Snipe } from "../util/Cache.js";
import {
ApplicationCommandOptionTypes,
ApplicationCommandTypes,
Expand All @@ -17,7 +18,16 @@ export default class SnipeCommand extends Command {
override type = ApplicationCommandTypes.CHAT_INPUT;
override async run(this: Client, interaction: CommandInteraction) {
const channel = interaction.data.options.getChannelOption("channel")?.value || interaction.channelID;
const snipe = await getSnipe(channel, "delete");
let snipe: Snipe | null;
try {
snipe = await getSnipe(channel, "delete");
} catch (e) {
const err = e as Error;
return interaction.createMessage({
content: `Failed to fetch snipe: **${err.name}: ${err.message}**`,
flags: MessageFlags.EPHEMERAL
});
}
if (!snipe) {
return interaction.createMessage({
content: "No snipes found.",
Expand Down
2 changes: 1 addition & 1 deletion src/util/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ICache {
snipes: Array<Snipe>;
}

interface Snipe {
export interface Snipe {
author: Record<"id" | "tag" | "avatarURL", string>;
channel: string;
content: string;
Expand Down

0 comments on commit 69ec8b2

Please sign in to comment.