Skip to content

Commit

Permalink
🔨 refactor try-catch duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Jul 19, 2022
1 parent a39cf2c commit 483dbbe
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/classes/DiscordBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,14 @@ export default class DiscordBot {
return;
}

if (!this.isDiscordAdmin(message.author.id)) {
try {
try {
if (!this.isDiscordAdmin(message.author.id)) {
// Will return default invalid value
const dummySteamID = new SteamID(null);
dummySteamID.redirectAnswerTo = message;
await this.bot.handler.onMessage(dummySteamID, message.content);
} catch (err) {
log.error(err);
message.channel
.send(`❌ Error:\n${JSON.stringify(err)}`)
.catch(err => log.error('Failed to send error message to Discord:', err));
return await this.bot.handler.onMessage(dummySteamID, message.content);
}

return;
}

try {
const adminID = this.getAdminBy(message.author.id);
adminID.redirectAnswerTo = message;
await this.bot.handler.onMessage(adminID, message.content);
Expand Down

0 comments on commit 483dbbe

Please sign in to comment.