瀏覽代碼

Fixed issue where a single word longer than max message would create stack overflow (infinite recursion).

Fixed issue where Wolfram Alpha result trimming was 3 characters too long.
tags/3.1.2
Teknikode 4 年之前
父節點
當前提交
b4cf738c43
共有 2 個文件被更改,包括 43 次插入5 次删除
  1. 42
    4
      IRCServices/Commanding/Commands.cs
  2. 1
    1
      Modules/Wolfram Alpha/Wolfram_Alpha.cs

+ 42
- 4
IRCServices/Commanding/Commands.cs 查看文件

@@ -67,16 +67,35 @@ namespace Combot.IRCServices.Commanding
{
if (message.Length > MaxMessageLength)
{
List<string> splitMessage = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
List<string> splitMessage = message.Split(new char[] { ' ' }).ToList();
string subMessage = string.Empty;
string nextMessage = string.Empty;
for (int i = 0; i < splitMessage.Count; i++)
{
int wordLength = splitMessage[i].Length + 1;
int totalLength = subMessage.Length;
int leftover = MaxMessageLength - totalLength;
if (totalLength + wordLength > MaxMessageLength)
{
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
if (wordLength > MaxMessageLength)
{
if (leftover > 0)
{
string firstPart = splitMessage[i].Substring(0, leftover);
subMessage = string.Join(" ", subMessage, firstPart);
}
string lastPart = (leftover > 0) ? splitMessage[i].Substring(leftover, (wordLength - leftover) - 1) : splitMessage[i];
nextMessage = string.Join(" ", new string[]
{
lastPart,
(splitMessage.Count > i + 1) ? string.Join(" ", splitMessage.GetRange(i + 1, splitMessage.Count - i)) : string.Empty
});
}
else
{
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
}
break;
}
subMessage = string.Join(" ", subMessage, splitMessage[i]);
@@ -123,16 +142,35 @@ namespace Combot.IRCServices.Commanding
{
if (message.Length > MaxMessageLength)
{
List<string> splitMessage = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
List<string> splitMessage = message.Split(new char[] { ' ' }).ToList();
string subMessage = string.Empty;
string nextMessage = string.Empty;
for (int i = 0; i < splitMessage.Count; i++)
{
int wordLength = splitMessage[i].Length + 1;
int totalLength = subMessage.Length;
int leftover = MaxMessageLength - totalLength;
if (totalLength + wordLength > MaxMessageLength)
{
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
if (wordLength > MaxMessageLength)
{
if (leftover > 0)
{
string firstPart = splitMessage[i].Substring(0, leftover);
subMessage = string.Join(" ", subMessage, firstPart);
}
string lastPart = (leftover > 0) ? splitMessage[i].Substring(leftover, (wordLength - leftover) - 1) : splitMessage[i];
nextMessage = string.Join(" ", new string[]
{
lastPart,
(splitMessage.Count > i + 1) ? string.Join(" ", splitMessage.GetRange(i + 1, splitMessage.Count - i)) : string.Empty

});
}
else
{
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
}
break;
}
subMessage = string.Join(" ", subMessage, splitMessage[i]);

+ 1
- 1
Modules/Wolfram Alpha/Wolfram_Alpha.cs 查看文件

@@ -49,7 +49,7 @@ namespace Combot.Modules.Plugins
int maxResults = Convert.ToInt32(GetOptionValue("Max Response Length"));
if (resultMessage.Length > (int)maxResults)
{
resultMessage = string.Format("{0}...", resultMessage.Substring(0, (int)maxResults));
resultMessage = string.Format("{0}...", resultMessage.Substring(0, (int)maxResults - 3));
}
char[] tails = {';', ' '};
resultMessage = resultMessage

Loading…
取消
儲存