Conciseness with .catch
This commit is contained in:
parent
a40c150012
commit
125a872fbb
|
@ -73,46 +73,34 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
: "[Confession removed by moderator]"
|
: "[Confession removed by moderator]"
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
// Replace the given confession with an empty embed
|
||||||
// Replace the given confession with an empty embed
|
(BotClient.channels.cache.get(channelId) as TextChannel).messages
|
||||||
await (BotClient.channels.cache.get(channelId) as TextChannel).messages
|
.fetch(confession)
|
||||||
.fetch(confession)
|
.then(message => {
|
||||||
.then(e => {
|
message.edit({
|
||||||
e.edit({
|
embeds: [emptyEmbed]
|
||||||
embeds: [emptyEmbed]
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: "Confession removed.",
|
content: "Confession removed.",
|
||||||
...messageOpts
|
...messageOpts
|
||||||
});
|
});
|
||||||
} catch (err) {
|
})
|
||||||
logger.error("A confession delete error occured:", err);
|
.catch(async err => {
|
||||||
return interaction.reply({
|
logger.error("An error occured deleting a confession:", err);
|
||||||
content: "An error occured.",
|
|
||||||
...messageOpts
|
return interaction.reply({
|
||||||
});
|
content: "An error occured when trying to delete that confession.",
|
||||||
}
|
...messageOpts
|
||||||
|
})
|
||||||
|
.catch(err => logger.error("An error occured following up:", err));
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
try {
|
// If there was a result, the user wasn't allowed to remove it, otherwise it didn't exist.
|
||||||
// If there was a result, the user wasn't allowed to remove it, otherwise it didn't exist.
|
return interaction.reply({
|
||||||
return result
|
content: result ? "You are not allowed to remove this confession." : "Either the confession wasn't found or you may not be allowed to remove it.",
|
||||||
? interaction.reply({
|
...messageOpts
|
||||||
content: "You are not allowed to remove this confession.",
|
})
|
||||||
...messageOpts
|
.catch(err => logger.error("A confession delete error occured:", err));
|
||||||
})
|
|
||||||
: interaction.reply({
|
|
||||||
content:
|
|
||||||
"Either the confession wasn't found or you may not be allowed to remove it.",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("A confession delete interaction occured:", err);
|
|
||||||
return interaction.reply({
|
|
||||||
content: "An error occured.",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,51 +93,34 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
const confessionId = interaction.options.getString("id")!;
|
const confessionId = interaction.options.getString("id")!;
|
||||||
|
|
||||||
if (dt.isBannedById(guildId, confessionId)) {
|
if (dt.isBannedById(guildId, confessionId)) {
|
||||||
try {
|
return interaction.reply({
|
||||||
return interaction.reply({
|
content: "That user is already banned!",
|
||||||
content: "That user is already banned!",
|
...messageOpts
|
||||||
...messageOpts
|
})
|
||||||
});
|
.catch(err => logger.error("A ban interaction error occured:", err));
|
||||||
} catch (err) {
|
|
||||||
logger.error("A ban interaction error occured:", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = dt.addBanById(guildId, confessionId);
|
const result = dt.addBanById(guildId, confessionId);
|
||||||
|
|
||||||
try {
|
return interaction.reply({
|
||||||
return result
|
content: result ? "User was banned." : "No confession with that ID was found.",
|
||||||
? interaction.reply({
|
...messageOpts
|
||||||
content: "User was banned.",
|
})
|
||||||
...messageOpts
|
.catch(err => logger.error("A ban interaction error occured:", err));
|
||||||
})
|
|
||||||
: interaction.reply({
|
// /confessmod banuser <user>
|
||||||
content: "No confession with that ID was found.",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("A ban interaction error occured:", err);
|
|
||||||
}
|
|
||||||
// /confessmod banuser <user>
|
|
||||||
} else if (interaction.options.getSubcommand() === "banuser") {
|
} else if (interaction.options.getSubcommand() === "banuser") {
|
||||||
const { id: userId } = interaction.options.getUser("user")!;
|
const { id: userId } = interaction.options.getUser("user")!;
|
||||||
|
|
||||||
const result = dt.addBanByUser(guildId, userId);
|
const result = dt.addBanByUser(guildId, userId);
|
||||||
|
|
||||||
try {
|
return interaction.reply({
|
||||||
return result
|
content: result ? "User was banned." : "How did we get here?",
|
||||||
? interaction.reply({
|
...messageOpts
|
||||||
content: "User was banned.",
|
})
|
||||||
...messageOpts
|
.catch(err => logger.log("A ban user interaction error occured:", err));
|
||||||
})
|
|
||||||
: interaction.reply({
|
// /confessmod list
|
||||||
content: "How did we get here? (An error occured.)}",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("A banuser interaction error occured:", err);
|
|
||||||
}
|
|
||||||
// /confessmod list
|
|
||||||
} else if (interaction.options.getSubcommand() === "list") {
|
} else if (interaction.options.getSubcommand() === "list") {
|
||||||
const bannedMembers = dt.getBans(guildId);
|
const bannedMembers = dt.getBans(guildId);
|
||||||
|
|
||||||
|
@ -170,58 +153,39 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
return interaction.reply({
|
||||||
return interaction.reply({
|
content: determineContent(),
|
||||||
content: determineContent(),
|
...messageOpts
|
||||||
...messageOpts
|
})
|
||||||
});
|
.catch(err => logger.error("A banlist interaction error occured:", err));
|
||||||
} catch (err) {
|
|
||||||
logger.error("A banlist interaction error occured:", err);
|
// /confessmod pardon <id>
|
||||||
return interaction.reply({
|
|
||||||
content: "A server-side error occurred when getting the ban list.",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// /confessmod pardon <id>
|
|
||||||
} else if (interaction.options.getSubcommand() === "pardon") {
|
} else if (interaction.options.getSubcommand() === "pardon") {
|
||||||
const result = dt.removeBanById(
|
const result = dt.removeBanById(
|
||||||
guildId,
|
guildId,
|
||||||
interaction.options.getString("id")!
|
interaction.options.getString("id")!
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
return interaction.reply({
|
||||||
return result
|
content: result ? "User was unbanned." : "No confession with that ID was found.",
|
||||||
? interaction.reply({
|
...messageOpts
|
||||||
content: "User was unbanned.",
|
})
|
||||||
...messageOpts
|
.catch(err => logger.log("An unban interaction error occured", err));
|
||||||
})
|
|
||||||
: interaction.reply({
|
// /confessmod pardonuser <user>
|
||||||
content: "No confession with that ID was found.",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("An unban interaction error occured:", err);
|
|
||||||
}
|
|
||||||
} else if (interaction.options.getSubcommand() === "pardonuser") {
|
} else if (interaction.options.getSubcommand() === "pardonuser") {
|
||||||
const { id: userId } = interaction.options.getUser("user")!;
|
const { id: userId } = interaction.options.getUser("user")!;
|
||||||
|
|
||||||
const result = dt.removeBanByUser(guildId, userId);
|
const result = dt.removeBanByUser(guildId, userId);
|
||||||
|
|
||||||
try {
|
return interaction.reply({
|
||||||
return result
|
content: result ? "User was unbanned." : "That user is not banned from confessions.",
|
||||||
? interaction.reply({
|
...messageOpts
|
||||||
content: "User was unbanned.",
|
})
|
||||||
...messageOpts
|
.catch(err => logger.log("Error replying to user ban interaction", err));
|
||||||
})
|
|
||||||
: interaction.reply({
|
|
||||||
content: "That user is not banned from confessions.",
|
|
||||||
...messageOpts
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("An unban user interaction error occured:", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Catch-all
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: "Unknown error",
|
content: "Unknown error",
|
||||||
...messageOpts
|
...messageOpts
|
||||||
|
|
|
@ -17,11 +17,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
|
import Logger from "../utils/Logger";
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
.setName("ping")
|
.setName("ping")
|
||||||
.setDescription("Ping!");
|
.setDescription("Ping!");
|
||||||
|
|
||||||
|
const logger = new Logger("(/) ping");
|
||||||
|
|
||||||
export async function execute(interaction: CommandInteraction) {
|
export async function execute(interaction: CommandInteraction) {
|
||||||
return interaction.reply("I'm an OSS confessions bot!");
|
return interaction.reply("I'm an OSS confessions bot!")
|
||||||
|
.catch(err => logger.error("I'm honestly suprised this even happened:", err));
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,8 @@ export async function execute(interaction: CommandInteraction) {
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: "This guild has already been set up!",
|
content: "This guild has already been set up!",
|
||||||
...messageOpts
|
...messageOpts
|
||||||
});
|
})
|
||||||
|
.catch(err => logger.error("An error occured during setup:", err));
|
||||||
}
|
}
|
||||||
|
|
||||||
let confessChannel: string, logChannel: string;
|
let confessChannel: string, logChannel: string;
|
||||||
|
@ -176,6 +177,6 @@ export async function execute(interaction: CommandInteraction) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("An error occured:", err);
|
logger.error("An error occured during setup:", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,8 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: `You can only run the update command once every ${minutes} minutes.`,
|
content: `You can only run the update command once every ${minutes} minutes.`,
|
||||||
...messageOpts
|
...messageOpts
|
||||||
});
|
})
|
||||||
|
.catch(err => logger.error("An update error occured:", err));
|
||||||
}
|
}
|
||||||
|
|
||||||
deployCommands({ guildId: guildId });
|
deployCommands({ guildId: guildId });
|
||||||
|
@ -60,5 +61,6 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: "Commands refreshed.",
|
content: "Commands refreshed.",
|
||||||
...messageOpts
|
...messageOpts
|
||||||
});
|
})
|
||||||
|
.catch(err => logger.error("An update error occured", err));
|
||||||
}
|
}
|
||||||
|
|
13
src/main.ts
13
src/main.ts
|
@ -95,7 +95,9 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
||||||
content: "You are banned from confessions in this server!",
|
content: "You are banned from confessions in this server!",
|
||||||
...messageOpts
|
...messageOpts
|
||||||
})
|
})
|
||||||
: interaction.showModal(submit);
|
.catch(err => logger.error("An error occured during a requestSubmit", err))
|
||||||
|
: interaction.showModal(submit)
|
||||||
|
.catch(err => logger.error("An error occured during a requestSubmit", err));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -110,13 +112,8 @@ BotClient.on(Events.InteractionCreate, interaction => {
|
||||||
"confessionAttachment"
|
"confessionAttachment"
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
submitConfession(interaction, messageContent, attachment ? attachment : undefined)
|
||||||
attachment
|
.catch(err => logger.error("An error occured when submitting a confession", err));
|
||||||
? submitConfession(interaction, messageContent)
|
|
||||||
: submitConfession(interaction, messageContent, attachment);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("An error occured:", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue