From a6697074c0f4920a9fee54dfab8b236a00fa6aaf Mon Sep 17 00:00:00 2001
From: DarkRRb <177549718+DarkRRb@users.noreply.github.com>
Date: Sun, 3 Nov 2024 16:10:23 +0800
Subject: [PATCH 1/2] [All] add chat type

---
 .../Common/Interface/Api/OperationExt.cs          |  8 ++++----
 .../Logic/Implementation/OperationLogic.cs        |  8 ++++----
 .../Internal/Event/Action/GroupAiRecordEvent.cs   | 15 ++++++++-------
 .../Service/Action/GroupAiRecordService.cs        | 10 +++++++---
 .../Core/Entity/Action/OneBotGetAiRecord.cs       |  8 +++++---
 .../Core/Operation/Group/GetAiRecordOperation.cs  |  7 ++++++-
 .../Message/SendGroupAiRecordOperation.cs         |  7 ++++++-
 7 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/Lagrange.Core/Common/Interface/Api/OperationExt.cs b/Lagrange.Core/Common/Interface/Api/OperationExt.cs
index ff4f29870..e53e60e70 100644
--- a/Lagrange.Core/Common/Interface/Api/OperationExt.cs
+++ b/Lagrange.Core/Common/Interface/Api/OperationExt.cs
@@ -273,11 +273,11 @@ public static Task<string> UploadImage(this BotContext bot, ImageEntity entity)
     public static Task<ImageOcrResult?> OcrImage(this BotContext bot, ImageEntity entity)
         => bot.ContextCollection.Business.OperationLogic.ImageOcr(entity);
 
-    public static Task<(int Code, string ErrMsg, string? Url)> GetGroupGenerateAiRecordUrl(this BotContext bot, uint groupUin, string character, string text)
-        => bot.ContextCollection.Business.OperationLogic.GetGroupGenerateAiRecordUrl(groupUin, character, text);
+    public static Task<(int Code, string ErrMsg, string? Url)> GetGroupGenerateAiRecordUrl(this BotContext bot, uint groupUin, string character, string text, uint chatType)
+        => bot.ContextCollection.Business.OperationLogic.GetGroupGenerateAiRecordUrl(groupUin, character, text, chatType);
 
-    public static Task<(int Code, string ErrMsg, RecordEntity? RecordEntity)> GetGroupGenerateAiRecord(this BotContext bot, uint groupUin, string character, string text)
-        => bot.ContextCollection.Business.OperationLogic.GetGroupGenerateAiRecord(groupUin, character, text);
+    public static Task<(int Code, string ErrMsg, RecordEntity? RecordEntity)> GetGroupGenerateAiRecord(this BotContext bot, uint groupUin, string character, string text, uint chatType)
+        => bot.ContextCollection.Business.OperationLogic.GetGroupGenerateAiRecord(groupUin, character, text, chatType);
 
     public static Task<(int Code, string ErrMsg, List<AiCharacterList>? Result)> GetAiCharacters(this BotContext bot, uint chatType, uint groupUin = 42)
         => bot.ContextCollection.Business.OperationLogic.GetAiCharacters(chatType, groupUin);
diff --git a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs
index 86f40d126..33d40cc34 100644
--- a/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs
+++ b/Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs
@@ -723,9 +723,9 @@ public async Task<bool> FriendJoinEmojiChain(uint friendUin, uint emojiId, uint
         return results.Count != 0 && results[0].ResultCode == 0;
     }
 
-    public async Task<(int Code, string ErrMsg, string? Url)> GetGroupGenerateAiRecordUrl(uint groupUin, string character, string text)
+    public async Task<(int Code, string ErrMsg, string? Url)> GetGroupGenerateAiRecordUrl(uint groupUin, string character, string text, uint chatType)
     {
-        var (code, errMsg, record) = await GetGroupGenerateAiRecord(groupUin, character, text);
+        var (code, errMsg, record) = await GetGroupGenerateAiRecord(groupUin, character, text, chatType);
         if (code != 0)
             return (code, errMsg, null);
 
@@ -739,9 +739,9 @@ public async Task<bool> FriendJoinEmojiChain(uint friendUin, uint emojiId, uint
             : (finalResult.ResultCode, "Failed to get group ai record", null);
     }
 
-    public async Task<(int Code, string ErrMsg, RecordEntity? Record)> GetGroupGenerateAiRecord(uint groupUin, string character, string text)
+    public async Task<(int Code, string ErrMsg, RecordEntity? Record)> GetGroupGenerateAiRecord(uint groupUin, string character, string text, uint chatType)
     {
-        var groupAiRecordEvent = GroupAiRecordEvent.Create(groupUin, character, text);
+        var groupAiRecordEvent = GroupAiRecordEvent.Create(groupUin, character, text, chatType);
         while (true)
         {
             var results = await Collection.Business.SendEvent(groupAiRecordEvent);
diff --git a/Lagrange.Core/Internal/Event/Action/GroupAiRecordEvent.cs b/Lagrange.Core/Internal/Event/Action/GroupAiRecordEvent.cs
index d5389204e..9cdabacb2 100644
--- a/Lagrange.Core/Internal/Event/Action/GroupAiRecordEvent.cs
+++ b/Lagrange.Core/Internal/Event/Action/GroupAiRecordEvent.cs
@@ -1,22 +1,23 @@
 using Lagrange.Core.Internal.Packets.Service.Oidb.Common;
-using Lagrange.Core.Message.Entity;
 
 namespace Lagrange.Core.Internal.Event.Action;
 
 internal class GroupAiRecordEvent : ProtocolEvent
 {
     public uint GroupUin { get; set; }
-    public string Character { get; set; }= string.Empty;
-    public string Text { get; set; }= string.Empty;
+    public string Character { get; set; } = string.Empty;
+    public string Text { get; set; } = string.Empty;
+    public uint ChatType { get; set; }
 
     public MsgInfo? RecordInfo { get; set; }
-    public string ErrorMessage { get; set; }= string.Empty;
+    public string ErrorMessage { get; set; } = string.Empty;
 
-    private GroupAiRecordEvent(uint groupUin, string character, string text) : base(0)
+    private GroupAiRecordEvent(uint groupUin, string character, string text, uint chatType) : base(0)
     {
         GroupUin = groupUin;
         Character = character;
         Text = text;
+        ChatType = chatType;
     }
 
     private GroupAiRecordEvent(int resultCode, MsgInfo? msgInfo) : base(resultCode)
@@ -29,8 +30,8 @@ private GroupAiRecordEvent(int resultCode, string errMsg) : base(resultCode)
         ErrorMessage = errMsg;
     }
 
-    public static GroupAiRecordEvent Create(uint groupUin, string character, string text) =>
-        new(groupUin, character, text);
+    public static GroupAiRecordEvent Create(uint groupUin, string character, string text, uint chatType) =>
+        new(groupUin, character, text, chatType);
 
     public static GroupAiRecordEvent Result(int resultCode, MsgInfo? msgInfo) => new(resultCode, msgInfo);
 
diff --git a/Lagrange.Core/Internal/Service/Action/GroupAiRecordService.cs b/Lagrange.Core/Internal/Service/Action/GroupAiRecordService.cs
index faa68b435..2d39f279f 100644
--- a/Lagrange.Core/Internal/Service/Action/GroupAiRecordService.cs
+++ b/Lagrange.Core/Internal/Service/Action/GroupAiRecordService.cs
@@ -2,10 +2,8 @@
 using Lagrange.Core.Internal.Event;
 using Lagrange.Core.Internal.Event.Action;
 using Lagrange.Core.Internal.Packets.Service.Oidb;
-using Lagrange.Core.Internal.Packets.Service.Oidb.Common;
 using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
 using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
-using Lagrange.Core.Message.Entity;
 using Lagrange.Core.Utility.Extension;
 using ProtoBuf;
 
@@ -20,7 +18,13 @@ protected override bool Build(GroupAiRecordEvent input, BotKeystore keystore, Bo
         out List<Memory<byte>>? extraPackets)
     {
         var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x929B_0>(
-            new OidbSvcTrpcTcp0x929B_0 { GroupCode = input.GroupUin, VoiceId = input.Character, Text = input.Text }
+            new OidbSvcTrpcTcp0x929B_0
+            {
+                GroupCode = input.GroupUin,
+                VoiceId = input.Character,
+                Text = input.Text,
+                ChatType = input.ChatType
+            }
         );
         output = packet.Serialize();
         extraPackets = null;
diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
index e215b27f7..db1e92af8 100644
--- a/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
+++ b/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
@@ -5,9 +5,11 @@ namespace Lagrange.OneBot.Core.Entity.Action;
 [Serializable]
 public class OneBotGetAiRecord
 {
-    [JsonPropertyName("character")] public string Character { get; set; } = string.Empty;
+    [JsonPropertyName("character")] public required string Character { get; set; }
 
-    [JsonPropertyName("group_id")] public uint GroupId { get; set; }
+    [JsonPropertyName("group_id")] public required uint GroupId { get; set; }
 
-    [JsonPropertyName("text")] public string Text { get; set; } = string.Empty;
+    [JsonPropertyName("text")] public required string Text { get; set; }
+
+    [JsonPropertyName("chat_type")] public uint ChatType { get; set; } = 1;
 }
\ No newline at end of file
diff --git a/Lagrange.OneBot/Core/Operation/Group/GetAiRecordOperation.cs b/Lagrange.OneBot/Core/Operation/Group/GetAiRecordOperation.cs
index 3860878a5..b6d8b9611 100644
--- a/Lagrange.OneBot/Core/Operation/Group/GetAiRecordOperation.cs
+++ b/Lagrange.OneBot/Core/Operation/Group/GetAiRecordOperation.cs
@@ -15,7 +15,12 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
         var message = payload.Deserialize<OneBotGetAiRecord>(SerializerOptions.DefaultOptions);
         if (message != null)
         {
-            var (code, errMsg, url) = await context.GetGroupGenerateAiRecordUrl(message.GroupId, message.Character, message.Text);
+            var (code, errMsg, url) = await context.GetGroupGenerateAiRecordUrl(
+                message.GroupId,
+                message.Character,
+                message.Text,
+                message.ChatType
+            );
             return code != 0 ? new OneBotResult(errMsg, code, "failed") : new OneBotResult(url, 0, "ok");
         }
 
diff --git a/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs b/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs
index c49ca5503..626e45074 100644
--- a/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs
+++ b/Lagrange.OneBot/Core/Operation/Message/SendGroupAiRecordOperation.cs
@@ -18,7 +18,12 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
         var message = payload.Deserialize<OneBotGetAiRecord>(SerializerOptions.DefaultOptions);
         if (message != null)
         {
-            (int code, string errMsg, var recordEntity) = await context.GetGroupGenerateAiRecord(message.GroupId, message.Character, message.Text);
+            (int code, string _, var recordEntity) = await context.GetGroupGenerateAiRecord(
+                message.GroupId,
+                message.Character,
+                message.Text,
+                message.ChatType
+            );
             if (code != 0 || recordEntity == null) return new OneBotResult(null, code, "failed");
 
 

From ee25ca800246a4b0781215d02a19a32e4927f876 Mon Sep 17 00:00:00 2001
From: DarkRRb <177549718+DarkRRb@users.noreply.github.com>
Date: Sun, 3 Nov 2024 16:38:41 +0800
Subject: [PATCH 2/2] restore some thing

---
 Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
index db1e92af8..80bad05c8 100644
--- a/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
+++ b/Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
@@ -5,11 +5,11 @@ namespace Lagrange.OneBot.Core.Entity.Action;
 [Serializable]
 public class OneBotGetAiRecord
 {
-    [JsonPropertyName("character")] public required string Character { get; set; }
+    [JsonPropertyName("character")] public string Character { get; set; } = string.Empty;
 
-    [JsonPropertyName("group_id")] public required uint GroupId { get; set; }
+    [JsonPropertyName("group_id")] public uint GroupId { get; set; }
 
-    [JsonPropertyName("text")] public required string Text { get; set; }
+    [JsonPropertyName("text")] public string Text { get; set; } = string.Empty;
 
     [JsonPropertyName("chat_type")] public uint ChatType { get; set; } = 1;
 }
\ No newline at end of file