diff --git a/DiscordBot.App/Controllers/FeedsController.cs b/DiscordBot.App/Controllers/FeedsController.cs index 055dc86..bbd8193 100644 --- a/DiscordBot.App/Controllers/FeedsController.cs +++ b/DiscordBot.App/Controllers/FeedsController.cs @@ -11,6 +11,7 @@ namespace DiscordBot.Controllers; public class FeedsController : ControllerBase { private readonly DiscordService _discordService; + private const int _maxMessageLength = 2000; public FeedsController(DiscordService discordService) { _discordService = discordService; @@ -39,6 +40,27 @@ public async Task PostSend(string channel, string message) _ => throw new Exception("Invalid channel name") }; + if (message.Length > _maxMessageLength) + { + var messageParts = message.Split(" "); + + var currentMessage = string.Empty; + + foreach (var messagePart in messageParts) + { + if (currentMessage.Length + messagePart.Length > _maxMessageLength) + { + await _discordService.Client.SendMessageAsync(discordChannel, currentMessage); + currentMessage = string.Empty; + } + + currentMessage += messagePart + " "; + } + + return; + } + + await _discordService.Client.SendMessageAsync(discordChannel, message); } }