Improve regexes & comment some code
This commit is contained in:
parent
a81f012c0c
commit
0bf68aa35c
1 changed files with 36 additions and 5 deletions
|
@ -96,6 +96,14 @@ namespace RhinoReminds
|
|||
}
|
||||
}
|
||||
|
||||
public void SetAvatar(string avatarFilepath)
|
||||
{
|
||||
if (!client.Connected)
|
||||
throw new InvalidOperationException("Error: The XMPP client isn't connected, so the avatar can't be updated.");
|
||||
|
||||
client.SetAvatar(avatarFilepath);
|
||||
}
|
||||
|
||||
private void messageHandler(Message message)
|
||||
{
|
||||
if (!AllowedDomains.Contains("*") && !AllowedDomains.Contains(message.From.Domain)) {
|
||||
|
@ -185,12 +193,18 @@ namespace RhinoReminds
|
|||
@"^me\s+",
|
||||
@"^on\s+",
|
||||
@"my",
|
||||
@"you",
|
||||
@"your",
|
||||
@"&" // Ampersands cause a crash when sending!
|
||||
}, new string[] {
|
||||
" ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"your"
|
||||
"your",
|
||||
@"me",
|
||||
@"my",
|
||||
@"and"
|
||||
}, RegexOptions.IgnoreCase).Trim();
|
||||
|
||||
sendChatReply(message, $"Ok! I'll remind you {reminder} at {dateTime}.");
|
||||
|
@ -205,6 +219,11 @@ namespace RhinoReminds
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a chat message to the specified JID.
|
||||
/// </summary>
|
||||
/// <param name="to">The JID to send the message to.</param>
|
||||
/// <param name="message">The messaage to send.</param>
|
||||
private void sendChatMessage(Jid to, string message) {
|
||||
//Console.WriteLine($"[Rhino/Send/Chat] Sending {message} -> {to}");
|
||||
client.SendMessage(
|
||||
|
@ -212,6 +231,11 @@ namespace RhinoReminds
|
|||
null, null, MessageType.Chat
|
||||
);
|
||||
}
|
||||
/// <summary>
|
||||
/// Sends a chat message in direct reply to a given incoming message.
|
||||
/// </summary>
|
||||
/// <param name="originalMessage">Original message.</param>
|
||||
/// <param name="reply">Reply.</param>
|
||||
private void sendChatReply(Message originalMessage, string reply)
|
||||
{
|
||||
//Console.WriteLine($"[Rhino/Send/Reply] Sending {reply} -> {originalMessage.From}");
|
||||
|
@ -272,10 +296,17 @@ namespace RhinoReminds
|
|||
|
||||
Console.WriteLine($"[Rhino/Reminderd] Sending notification {nextReminder}");
|
||||
|
||||
try
|
||||
{
|
||||
sendChatMessage(
|
||||
nextReminder.Jid,
|
||||
$"Hello! You asked me to remind you {nextReminder.Message} at {nextReminder.Time}.".Trim().Replace(@"\s+", " ")
|
||||
);
|
||||
} catch (Exception error) {
|
||||
Console.Error.WriteLine($"[Rhino/Reminderd] Caught error sending message to client: {error}");
|
||||
Console.Error.WriteLine($"[Rhink/Reminderd] Offending reminder: {nextReminder}");
|
||||
sendChatMessage(nextReminder.Jid, "Oops! I encountered an error sending you a reminder. Please contact my operator!");
|
||||
}
|
||||
if (nextWaitingTime.TotalMilliseconds < 0) {
|
||||
sendChatMessage(
|
||||
nextReminder.Jid,
|
||||
|
|
Loading…
Reference in a new issue