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.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using RhinoReminds.Utilities;
|
||||||
using S22.Xmpp;
|
using S22.Xmpp;
|
||||||
using S22.Xmpp.Client;
|
using S22.Xmpp.Client;
|
||||||
using S22.Xmpp.Im;
|
using S22.Xmpp.Im;
|
||||||
|
@ -144,19 +145,20 @@ namespace RhinoReminds
|
||||||
messageText.IndexOf(rawDateTimeString, StringComparison.OrdinalIgnoreCase),
|
messageText.IndexOf(rawDateTimeString, StringComparison.OrdinalIgnoreCase),
|
||||||
messageText.IndexOf(rawDateTimeString, StringComparison.OrdinalIgnoreCase) + rawDateTimeString.Length
|
messageText.IndexOf(rawDateTimeString, StringComparison.OrdinalIgnoreCase) + rawDateTimeString.Length
|
||||||
);
|
);
|
||||||
string reminder = Regex.Replace(
|
string reminder = messageText.Remove(dateStringLocation.Min, dateStringLocation.Stride)
|
||||||
messageText.Remove(dateStringLocation.Min, dateStringLocation.Stride),
|
.ReplaceMultiple(new string[] {
|
||||||
@"^remind\s+(?:me\s+)?", "",
|
@"\s{2,}",
|
||||||
RegexOptions.IgnoreCase
|
@"^remind\s+(?:me\s+)?",
|
||||||
).Replace(@"\s{2,}", " ").Trim();
|
@"^me\s+",
|
||||||
|
@"^on\s+",
|
||||||
if (Debug)
|
@"my",
|
||||||
{
|
}, new string[] {
|
||||||
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}]");
|
"",
|
||||||
}
|
"your"
|
||||||
|
}, RegexOptions.IgnoreCase).Trim();
|
||||||
|
|
||||||
sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
|
sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
|
||||||
|
|
||||||
|
@ -238,7 +240,7 @@ namespace RhinoReminds
|
||||||
|
|
||||||
sendChatMessage(
|
sendChatMessage(
|
||||||
nextReminder.Jid,
|
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) {
|
if (nextWaitingTime.TotalMilliseconds < 0) {
|
||||||
sendChatMessage(
|
sendChatMessage(
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
<Compile Include="AIRecogniser.cs" />
|
<Compile Include="AIRecogniser.cs" />
|
||||||
<Compile Include="Exceptions.cs" />
|
<Compile Include="Exceptions.cs" />
|
||||||
<Compile Include="Utilities\Range.cs" />
|
<Compile Include="Utilities\Range.cs" />
|
||||||
|
<Compile Include="Utilities\TextHelpers.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<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