private static async Task SendCodeBlock(ITextChannel channel, string code, int maxMessageLength, string codeWrapper) {
maxMessageLength -= (2 * codeWrapper.Length);
// let's break up the code into lines.
List<string> lines = code.Split("\n")
.ToList();
// add lines until we hit or go over the max message length.
string content = string.Empty;
while (lines.Count != 0) {
// if one line puts us over, we need to break the line up more.
if (content.Length + lines[1].Length > maxMessageLength && string.IsNullOrEmpty(content)) {
//TODO: we need to split on sentence, then on spaces, then finally on letters and do the same thing.
}
// if adding the next thing will push us over the limit, send and reset.
else if (content.Length + lines[1].Length > maxMessageLength) {
await SendMessageAsync(channel, $"{codeWrapper}{content}{codeWrapper}");
content = "";
}
else {
content += "\n" + lines.pop(1);
}
}
}
#Feedback Request: Printing strings.
1 messages · Page 1 of 1 (latest)