@@ -49,6 +50,9 @@
[Parameter]
public List
Messages { get; set; } = null!;
+ [Parameter]
+ public IChatRobot Robot { get; set; } = null!;
+
private void SendMessageClicked()
{
if (string.IsNullOrWhiteSpace(MessageSending))
@@ -63,13 +67,16 @@
Text = MessageSending
});
- MessageSending = string.Empty;
-
- Messages.Add(new ChatMessage
+ foreach (string answer in Robot.ChatNext(MessageSending))
{
- Left = true,
- Sender = "凯瑟琳",
- Text = "对不起,做不到。"
- });
+ Messages.Add(new ChatMessage
+ {
+ Left = true,
+ Sender = Robot.RobotName,
+ Text = answer
+ });
+ }
+
+ MessageSending = string.Empty;
}
}
\ No newline at end of file
diff --git a/Katheryne/Abstractions/IChatRobot.cs b/Katheryne/Abstractions/IChatRobot.cs
index ea64e2d..48575ad 100644
--- a/Katheryne/Abstractions/IChatRobot.cs
+++ b/Katheryne/Abstractions/IChatRobot.cs
@@ -10,6 +10,6 @@ public interface IChatRobot
public IEnumerable OnChatStart();
public IEnumerable OnChatStop();
-
-
+
+ public IEnumerable ChatNext(string input);
}
\ No newline at end of file
diff --git a/Katheryne/DefaultChatRobot.cs b/Katheryne/DefaultChatRobot.cs
new file mode 100644
index 0000000..7cac34b
--- /dev/null
+++ b/Katheryne/DefaultChatRobot.cs
@@ -0,0 +1,44 @@
+using Katheryne.Abstractions;
+using Microsoft.Extensions.Logging;
+
+namespace Katheryne;
+
+public class DefaultChatRobot : IChatRobot
+{
+ private readonly ILogger _logger;
+
+ public DefaultChatRobot(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ public string RobotName => "凯瑟琳";
+
+ public IEnumerable OnChatStart()
+ {
+ _logger.LogDebug("Start default chat robot.");
+ return new[]
+ {
+ "向着星辰与深渊!",
+ "欢迎来到冒险家协会。"
+ };
+ }
+
+ public IEnumerable OnChatStop()
+ {
+ _logger.LogDebug("End default chat robot.");
+ return new[]
+ {
+ "再见,感谢您对协会做出的贡献,冒险家。"
+ };
+ }
+
+ public IEnumerable ChatNext(string input)
+ {
+ _logger.LogDebug("Robot receive message: \"{}\".", input);
+ return new[]
+ {
+ "暂时不支持该功能,请联系维护人员。"
+ };
+ }
+}
\ No newline at end of file
diff --git a/Katheryne/Katheryne.csproj b/Katheryne/Katheryne.csproj
index 6836c68..7a99e3a 100644
--- a/Katheryne/Katheryne.csproj
+++ b/Katheryne/Katheryne.csproj
@@ -6,4 +6,8 @@
enable
+
+
+
+