Skip to content

Commit

Permalink
Merge pull request #13 from eclipserporg/fix/send_large_messages
Browse files Browse the repository at this point in the history
Fix large messages
  • Loading branch information
pauliusdotpro authored Nov 11, 2023
2 parents 0e7ab6b + fed271f commit c89fd0b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions DiscordBot.App/Controllers/FeedsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c89fd0b

Please sign in to comment.