Nullify MessageContent

This commit is contained in:
Jordan Dominion
2023-12-23 10:34:49 -05:00
parent 047618c4c4
commit ffbf0f5ba7
2 changed files with 20 additions and 6 deletions
@@ -218,6 +218,22 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
var channelsClient = serviceProvider.GetRequiredService<IDiscordRestChannelAPI>();
async ValueTask SendToChannel(Snowflake channelId)
{
if (message.Text == null)
{
Logger.LogWarning(
"Failed to send to channel {channelId}: Message was null!",
channelId);
await channelsClient.CreateMessageAsync(
channelId,
"TGS: Could not send message to Discord. Message was `null`!",
messageReference: replyToReference,
allowedMentions: allowedMentions,
ct: cancellationToken);
return;
}
var result = await channelsClient.CreateMessageAsync(
channelId,
message.Text,
@@ -940,7 +956,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
/// <param name="embed">The <see cref="ChatEmbed"/> to convert.</param>
/// <returns>The parameter for sending a single <see cref="IEmbed"/>.</returns>
#pragma warning disable CA1502
Optional<IReadOnlyList<IEmbed>> ConvertEmbed(ChatEmbed embed)
Optional<IReadOnlyList<IEmbed>> ConvertEmbed(ChatEmbed? embed)
{
if (embed == null)
return default;
@@ -1,6 +1,4 @@
#nullable disable
namespace Tgstation.Server.Host.Components.Interop
namespace Tgstation.Server.Host.Components.Interop
{
/// <summary>
/// Represents a message to send to a chat provider.
@@ -10,11 +8,11 @@ namespace Tgstation.Server.Host.Components.Interop
/// <summary>
/// The message <see cref="string"/>.
/// </summary>
public string Text { get; set; }
public string? Text { get; set; }
/// <summary>
/// The <see cref="ChatEmbed"/>.
/// </summary>
public ChatEmbed Embed { get; set; }
public ChatEmbed? Embed { get; set; }
}
}