Tidy up reminder messages
This commit is contained in:
parent
62c278a639
commit
6399545331
3 changed files with 41 additions and 14 deletions
|
@ -7,6 +7,7 @@ using System.Text;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using RhinoReminds.Utilities;
|
||||
using S22.Xmpp;
|
||||
using S22.Xmpp.Client;
|
||||
using S22.Xmpp.Im;
|
||||
|
@ -144,19 +145,20 @@ namespace RhinoReminds
|
|||
messageText.IndexOf(rawDateTimeString, StringComparison.OrdinalIgnoreCase),
|
||||
messageText.IndexOf(rawDateTimeString, StringComparison.OrdinalIgnoreCase) + rawDateTimeString.Length
|
||||
);
|
||||
string reminder = Regex.Replace(
|
||||
messageText.Remove(dateStringLocation.Min, dateStringLocation.Stride),
|
||||
@"^remind\s+(?:me\s+)?", "",
|
||||
RegexOptions.IgnoreCase
|
||||
).Replace(@"\s{2,}", " ").Trim();
|
||||
|
||||
if (Debug)
|
||||
{
|
||||
sendChatReply(message, $"[debug] Raw date identified: [{rawDateTimeString}]");
|
||||
sendChatReply(message, $"[debug] Time identified at {dateStringLocation}");
|
||||
sendChatReply(message, $"[debug] Transforming message - phase #1 [{reminder}]");
|
||||
sendChatReply(message, $"[debug] Transforming message - phase #2 [{reminder}]");
|
||||
}
|
||||
string reminder = messageText.Remove(dateStringLocation.Min, dateStringLocation.Stride)
|
||||
.ReplaceMultiple(new string[] {
|
||||
@"\s{2,}",
|
||||
@"^remind\s+(?:me\s+)?",
|
||||
@"^me\s+",
|
||||
@"^on\s+",
|
||||
@"my",
|
||||
}, new string[] {
|
||||
" ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"your"
|
||||
}, RegexOptions.IgnoreCase).Trim();
|
||||
|
||||
sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
|
||||
|
||||
|
@ -238,7 +240,7 @@ namespace RhinoReminds
|
|||
|
||||
sendChatMessage(
|
||||
nextReminder.Jid,
|
||||
$"Hello! You asked me to remind you {nextReminder.Message} at {nextReminder.Time}.".Replace(@"\s{2,}", " ").Trim()
|
||||
$"Hello! You asked me to remind you {nextReminder.Message} at {nextReminder.Time}.".Trim().Replace(@"\s+", " ")
|
||||
);
|
||||
if (nextWaitingTime.TotalMilliseconds < 0) {
|
||||
sendChatMessage(
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
<Compile Include="AIRecogniser.cs" />
|
||||
<Compile Include="Exceptions.cs" />
|
||||
<Compile Include="Utilities\Range.cs" />
|
||||
<Compile Include="Utilities\TextHelpers.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
24
RhinoReminds/Utilities/TextHelpers.cs
Normal file
24
RhinoReminds/Utilities/TextHelpers.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhinoReminds.Utilities
|
||||
{
|
||||
public static class TextHelpers
|
||||
{
|
||||
public static string ReplaceMultiple(this string input, IEnumerable<string> regexes, IEnumerable<string> replacements, RegexOptions options = RegexOptions.None)
|
||||
{
|
||||
using (IEnumerator<string> regexIterator = regexes.GetEnumerator())
|
||||
using (IEnumerator<string> replacementsIterator = replacements.GetEnumerator()) {
|
||||
while (regexIterator.MoveNext() && replacementsIterator.MoveNext()) {
|
||||
input = Regex.Replace(
|
||||
input,
|
||||
regexIterator.Current, replacementsIterator.Current,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue