-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoCommit: Bump Repository (Update Repository Files)
- Loading branch information
1 parent
00d7f23
commit 0552ddb
Showing
13 changed files
with
397 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { ChannelType, EmbedBuilder, EmbedField } from "discord.js"; | ||
import { RedactClient } from "../RedactClient"; | ||
|
||
export class RedactErrorHandler { | ||
|
||
private redactClient: RedactClient; | ||
private guildId: string; | ||
private channelId: string; | ||
private description: string; | ||
private errorField: EmbedField; | ||
private dateField: EmbedField; | ||
|
||
constructor(redactClient: RedactClient, guildId: string, channelId: string) { | ||
this.redactClient = redactClient; | ||
this.guildId = guildId; | ||
this.channelId = channelId; | ||
this.description = "An error occured while trying to run the bot."; | ||
this.errorField = { | ||
name: "Error", | ||
value: "%error_value%", | ||
inline: true | ||
}; | ||
this.dateField = { | ||
name: "Date", | ||
value: "%date%", | ||
inline: true | ||
}; | ||
} | ||
|
||
setDescription(description: string) { | ||
this.description = description; | ||
} | ||
|
||
getDescription(): string { | ||
return this.description; | ||
} | ||
|
||
setErrorField(field: EmbedField) { | ||
this.errorField = field; | ||
} | ||
|
||
getErrorField(): EmbedField { | ||
return this.errorField; | ||
} | ||
|
||
setDateField(field: EmbedField) { | ||
this.dateField = field; | ||
} | ||
|
||
getDateField(): EmbedField { | ||
return this.dateField; | ||
} | ||
|
||
async reportError(error: Error) { | ||
const stack = error.stack ? error.stack : ""; | ||
this.errorField.value = this.errorField.value.replace("%error_value%", `\`\`\`${stack}\`\`\``); | ||
this.dateField.value = this.dateField.value.replace("%date%", new Date().toUTCString()) | ||
const embed = new EmbedBuilder() | ||
.setDescription(this.description) | ||
.setFields(this.errorField, this.dateField); | ||
|
||
const guild = this.redactClient.getClient().guilds.cache.get(this.guildId); | ||
if (!guild) | ||
throw error; | ||
const channel = await guild.channels.fetch(this.channelId); | ||
if (!channel) | ||
throw error; | ||
if (!channel.isTextBased() || channel.type !== ChannelType.GuildText) | ||
throw error; | ||
channel.send({ | ||
embeds: [embed] | ||
}); | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.