Skip to content

Commit

Permalink
[OneBot] Fixed Message Id for message related operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Feb 15, 2024
1 parent 54f1d83 commit beca091
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lagrange.Core.Common.Interface.Api;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Entity.Action.Response;
using Lagrange.OneBot.Database;

namespace Lagrange.OneBot.Core.Operation.Message;

Expand All @@ -12,14 +13,17 @@ public sealed class SendGroupMessageOperation(MessageCommon common) : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
var result = payload.Deserialize<OneBotGroupMessageBase>() switch
var chain = payload.Deserialize<OneBotGroupMessageBase>() switch
{
OneBotGroupMessage message => await context.SendMessage(common.ParseChain(message).Build()),
OneBotGroupMessageSimple messageSimple => await context.SendMessage(common.ParseChain(messageSimple).Build()),
OneBotGroupMessageText messageText => await context.SendMessage(common.ParseChain(messageText).Build()),
OneBotGroupMessage message => common.ParseChain(message).Build(),
OneBotGroupMessageSimple messageSimple => common.ParseChain(messageSimple).Build(),
OneBotGroupMessageText messageText => common.ParseChain(messageText).Build(),
_ => throw new Exception()
};

return new OneBotResult(new OneBotMessageResponse(0), 0, "ok");
var result = await context.SendMessage(chain);
int hash = MessageRecord.CalcMessageHash(chain.MessageId, result.Sequence ?? 0);

return new OneBotResult(new OneBotMessageResponse(hash), (int)result.Result, "ok");
}
}
14 changes: 9 additions & 5 deletions Lagrange.OneBot/Core/Operation/Message/SendMessageOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lagrange.Core.Common.Interface.Api;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Entity.Action.Response;
using Lagrange.OneBot.Database;

namespace Lagrange.OneBot.Core.Operation.Message;

Expand All @@ -12,14 +13,17 @@ public sealed class SendMessageOperation(MessageCommon common) : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
var result = payload.Deserialize<OneBotMessageBase>() switch
var chain = payload.Deserialize<OneBotMessageBase>() switch
{
OneBotMessage message => await context.SendMessage(common.ParseChain(message).Build()),
OneBotMessageSimple messageSimple => await context.SendMessage(common.ParseChain(messageSimple).Build()),
OneBotMessageText messageText => await context.SendMessage(common.ParseChain(messageText).Build()),
OneBotMessage message => common.ParseChain(message).Build(),
OneBotMessageSimple messageSimple => common.ParseChain(messageSimple).Build(),
OneBotMessageText messageText => common.ParseChain(messageText).Build(),
_ => throw new Exception()
};

return new OneBotResult(new OneBotMessageResponse(0), 0, "ok");
var result = await context.SendMessage(chain);
int hash = MessageRecord.CalcMessageHash(chain.MessageId, result.Sequence ?? 0);

return new OneBotResult(new OneBotMessageResponse(hash), (int)result.Result, "ok");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lagrange.Core.Common.Interface.Api;
using Lagrange.OneBot.Core.Entity.Action;
using Lagrange.OneBot.Core.Entity.Action.Response;
using Lagrange.OneBot.Database;

namespace Lagrange.OneBot.Core.Operation.Message;

Expand All @@ -12,15 +13,17 @@ public sealed class SendPrivateMessageOperation(MessageCommon common) : IOperati
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{

var result = payload.Deserialize<OneBotPrivateMessageBase>() switch
var chain = payload.Deserialize<OneBotPrivateMessageBase>() switch
{
OneBotPrivateMessage message => await context.SendMessage(common.ParseChain(message).Build()),
OneBotPrivateMessageSimple messageSimple => await context.SendMessage(common.ParseChain(messageSimple).Build()),
OneBotPrivateMessageText messageText => await context.SendMessage(common.ParseChain(messageText).Build()),
OneBotPrivateMessage message => common.ParseChain(message).Build(),
OneBotPrivateMessageSimple messageSimple => common.ParseChain(messageSimple).Build(),
OneBotPrivateMessageText messageText => common.ParseChain(messageText).Build(),
_ => throw new Exception()
};

return new OneBotResult(new OneBotMessageResponse(0), 0, "ok");
var result = await context.SendMessage(chain);
int hash = MessageRecord.CalcMessageHash(chain.MessageId, result.Sequence ?? 0);

return new OneBotResult(new OneBotMessageResponse(hash), (int)result.Result, "ok");
}
}
2 changes: 1 addition & 1 deletion Lagrange.OneBot/Database/MessageRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static explicit operator MessageChain(MessageRecord record)
MessageHash = CalcMessageHash(chain.MessageId, chain.Sequence)
};

private static int CalcMessageHash(ulong msgId, uint seq)
public static int CalcMessageHash(ulong msgId, uint seq)
{
var messageId = BitConverter.GetBytes(msgId);
var sequence = BitConverter.GetBytes(seq);
Expand Down

0 comments on commit beca091

Please sign in to comment.