forked from LagrangeDev/Lagrange.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Lagrange.OneBot/Core/Entity/Message/OneBotSendMessageWithGroup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Message; | ||
|
||
[Serializable] | ||
public class OneBotSendMessageWithGroup | ||
{ | ||
[JsonPropertyName("message_id")] public int MessageId { get; set; } | ||
|
||
[JsonPropertyName("target_group_id")] public uint TargetGroupId { get; set; } | ||
} |
44 changes: 44 additions & 0 deletions
44
Lagrange.OneBot/Core/Operation/Message/SendMessageWithGroupOperation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Message; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Core.Entity.Message; | ||
using Lagrange.OneBot.Core.Operation.Converters; | ||
using Lagrange.OneBot.Message; | ||
using Lagrange.OneBot.Database; | ||
using Lagrange.OneBot.Core.Entity.Action.Response; | ||
namespace Lagrange.OneBot.Core.Operation.Message; | ||
|
||
using LiteDB; | ||
|
||
[Operation("send_msg_with_group")] | ||
public class SendMessageWithGroupOperation(LiteDatabase database) : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload) | ||
{ | ||
if (payload.Deserialize<OneBotSendMessageWithGroup>(SerializerOptions.DefaultOptions) is { } history) | ||
{ | ||
var record = database.GetCollection<MessageRecord>().FindById(history.MessageId); | ||
var chain = (MessageChain)record; | ||
if (chain.GroupUin == 0) | ||
{ | ||
return new OneBotResult("messageid not group", -1, "failed"); | ||
} | ||
uint groupUin = chain.GroupUin ?? 0; | ||
|
||
if (await context.GetGroupMessageWithPushMsgBody(groupUin, (uint)chain.Sequence, (uint)chain.Sequence) is { } results) | ||
{ | ||
var newMessageChain = new MessageChain(history.TargetGroupId); | ||
var sendMsgRes = await context.SendMessage(newMessageChain, results.Item2?[0] ?? throw new Exception("No PushMsgBody found")); | ||
|
||
if (sendMsgRes.Result != 0) return new OneBotResult(null, (int)sendMsgRes.Result, "failed"); | ||
if (sendMsgRes.Sequence == null || sendMsgRes.Sequence == 0) return new OneBotResult(null, 9000, "failed"); | ||
int hash = MessageRecord.CalcMessageHash(newMessageChain.MessageId, sendMsgRes.Sequence ?? 0); | ||
return new OneBotResult(new OneBotMessageResponse(hash, (int)sendMsgRes.Sequence.GetValueOrDefault()), (int)sendMsgRes.Result, "ok"); | ||
} | ||
} | ||
throw new Exception(); | ||
} | ||
} |