From 5cf427c500929aac8a32ce74eae0456a567d702c Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Sat, 21 Aug 2021 02:33:03 +0100 Subject: [PATCH] Update Inbound.cs adds support for large replys to discord --- BetterSecondbot/DiscordSupervisor/Inbound.cs | 36 ++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/BetterSecondbot/DiscordSupervisor/Inbound.cs b/BetterSecondbot/DiscordSupervisor/Inbound.cs index d2e7067..631b4d3 100644 --- a/BetterSecondbot/DiscordSupervisor/Inbound.cs +++ b/BetterSecondbot/DiscordSupervisor/Inbound.cs @@ -6,7 +6,8 @@ using System.Text; using System.Threading.Tasks; using System.Linq; using System.Threading; - +using System.Collections.Generic; + namespace BetterSecondBot.DiscordSupervisor { @@ -128,7 +129,12 @@ namespace BetterSecondBot.DiscordSupervisor reply = controler.getBot().CallAPI(bits[0], args.Split("~#~"), target); } await MarkMessage(message, "✅").ConfigureAwait(false); - await message.Channel.SendMessageAsync(reply, false, null,null,null, new MessageReference(message.Id)).ConfigureAwait(false); + + foreach(string A in Split(reply, 1250)) + { + await message.Channel.SendMessageAsync(A, false, null, null, null, new MessageReference(message.Id)).ConfigureAwait(false); + } + } else { @@ -139,6 +145,32 @@ namespace BetterSecondBot.DiscordSupervisor } return Task.CompletedTask; } + + public string[] Split(string input,int size) + { + if (input.Length < size) + { + return new string[] { input }; + } + else + { + int index = 0; + int length = input.Length; + List bits = new List(); + while((index+size) < length) + { + bits.Add(input.Substring(index, size)); + index += size; + } + if(index != length) + { + // last bit + int remain = length - index; + bits.Add(input.Substring(index, remain)); + } + return bits.ToArray(); + } + } protected virtual async Task InboundImMessage(ITextChannel Chan, IUserMessage message) { if (HasBot() == true)