Browse Source

Sed - Added catch for the regex to prevent crashing on bad query.

Module - Renamed error function.
tags/3.1.1
Teknikode 4 years ago
parent
commit
274d0aef4a
3 changed files with 25 additions and 18 deletions
  1. 1
    1
      Combot/Modules/Module.cs
  2. 4
    4
      Modules/Github/Github.cs
  3. 20
    13
      Modules/Sed/Sed.cs

+ 1
- 1
Combot/Modules/Module.cs View File

@@ -101,7 +101,7 @@ namespace Combot.Modules

virtual public void ParseCommand(CommandMessage command) { }

protected void OnError(string e)
protected void ThrowError(string e)
{
string errorMsg = string.Format("[{0}] {1}", Name, e);
EventHandler<string> handler = ModuleErrorEvent;

+ 4
- 4
Modules/Github/Github.cs View File

@@ -81,11 +81,11 @@ namespace Combot.Modules.Plugins
}
catch (Octokit.RateLimitExceededException ex)
{
OnError(ex.Message);
ThrowError(ex.Message);
}
catch (Octokit.ApiValidationException ex)
{
OnError(ex.Message);
ThrowError(ex.Message);
}
}

@@ -117,11 +117,11 @@ namespace Combot.Modules.Plugins
}
catch (Octokit.RateLimitExceededException ex)
{
OnError(ex.Message);
ThrowError(ex.Message);
}
catch (Octokit.ApiValidationException ex)
{
OnError(ex.Message);
ThrowError(ex.Message);
return;
}
}

+ 20
- 13
Modules/Sed/Sed.cs View File

@@ -91,22 +91,29 @@ namespace Combot.Modules.Plugins
msgList.Reverse();
foreach (string msg in msgList)
{
Regex messageRegex = new Regex(match, matchOptions);
if (messageRegex.IsMatch(msg))
try
{
string newMessage = string.Empty;
if (replaceNum < 0)
Regex messageRegex = new Regex(match, matchOptions);
if (messageRegex.IsMatch(msg))
{
newMessage = messageRegex.Replace(msg, replace);
string newMessage = string.Empty;
if (replaceNum < 0)
{
newMessage = messageRegex.Replace(msg, replace);
}
else
{
newMessage = messageRegex.Replace(msg, replace, replaceNum);
}
string replacedMessage = string.Format("\u0002{0}\u0002 meant to say: {1}", message.Sender.Nickname, newMessage);
SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, replacedMessage);
foundResult = true;
break;
}
else
{
newMessage = messageRegex.Replace(msg, replace, replaceNum);
}
string replacedMessage = string.Format("\u0002{0}\u0002 meant to say: {1}", message.Sender.Nickname, newMessage);
SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, replacedMessage);
foundResult = true;
break;
}
catch (Exception ex)
{
ThrowError(ex.Message);
}
}
}

Loading…
Cancel
Save