Skip to content

Commit

Permalink
可控chattype 以应对后续可能开放的唱歌
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Nov 3, 2024
1 parent 82f541f commit fcf419f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,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);

Expand All @@ -746,9 +746,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);
Expand Down
15 changes: 9 additions & 6 deletions Lagrange.Core/Internal/Event/Action/GroupAiRecordEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ 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; } = 1;

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)
Expand All @@ -29,8 +32,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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class OneBotGetAiCharacters
{
[JsonPropertyName("group_id")] public uint GroupId { get; set; } = 42;

[JsonPropertyName("chat_type")] public uint ChatType { get; set; }
[JsonPropertyName("chat_type")] public uint ChatType { get; set; } = 1;
}
2 changes: 2 additions & 0 deletions Lagrange.OneBot/Core/Entity/Action/OneBotGetAiRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public class OneBotGetAiRecord
[JsonPropertyName("group_id")] public uint GroupId { get; set; }

[JsonPropertyName("text")] public string Text { get; set; } = string.Empty;

[JsonPropertyName("chat_type")] public uint ChatType { get; set; } = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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 errMsg, var recordEntity) = await context.GetGroupGenerateAiRecord(message.GroupId, message.Character, message.Text , message.ChatType);
if (code != 0 || recordEntity == null) return new OneBotResult(null, code, "failed");


Expand Down

0 comments on commit fcf419f

Please sign in to comment.