Skip to content

Commit

Permalink
Handling exceptions from discord
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Feb 17, 2025
1 parent 9724f4e commit aeae9b0
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/BuildBot.Discord/Services/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,37 @@ CancellationToken cancellationToken
return;
}

await this.PublishCommonAsync(
builder: builder,
socketTextChannel: socketTextChannel,
cancellationToken: cancellationToken
);
}

private async ValueTask PublishCommonAsync(
EmbedBuilder builder,
SocketTextChannel socketTextChannel,
CancellationToken cancellationToken
)
{
try
{
await this.PublishCommonAsync(
builder: builder,
socketTextChannel: socketTextChannel,
cancellationToken: cancellationToken
this._logger.LogSendingMessage(
channelName: socketTextChannel.Name,
message: builder.Title
);

using (socketTextChannel.EnterTypingState())
{
Embed embed = IncludeStandardParameters(builder);

RestUserMessage msg = await socketTextChannel.SendMessageAsync(
text: string.Empty,
embed: embed
);
this.LogSent(msg);
await Task.Delay(delay: TypingDelay, cancellationToken: cancellationToken);
}
}
catch (Exception exception)
{
Expand All @@ -102,27 +126,6 @@ await this.PublishCommonAsync(
}
}

private async ValueTask PublishCommonAsync(
EmbedBuilder builder,
SocketTextChannel socketTextChannel,
CancellationToken cancellationToken
)
{
this._logger.LogSendingMessage(channelName: socketTextChannel.Name, message: builder.Title);

using (socketTextChannel.EnterTypingState())
{
Embed embed = IncludeStandardParameters(builder);

RestUserMessage msg = await socketTextChannel.SendMessageAsync(
text: string.Empty,
embed: embed
);
this.LogSent(msg);
await Task.Delay(delay: TypingDelay, cancellationToken: cancellationToken);
}
}

private void LogSent(RestUserMessage msg)
{
this._logger.LogSentMessage(channelName: msg.Channel.Name, message: msg.CleanContent);
Expand Down

0 comments on commit aeae9b0

Please sign in to comment.