Skip to content

Commit

Permalink
[OneBot] fix check sequence (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRRb authored Nov 26, 2024
1 parent 5e7072c commit c79f814
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
);
if (code != 0 || recordEntity == null) return new OneBotResult(null, code, "failed");


var chain = MessageBuilder.Group(message.GroupId).Add(recordEntity).Build();
var result = await context.SendMessage(chain);

if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed");
if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed");

int hash = MessageRecord.CalcMessageHash(chain.MessageId, result.Sequence ?? 0);

return new OneBotResult(new OneBotMessageResponse(hash), (int)result.Result, "ok");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
var multi = new MultiMsgEntity(chains);
var chain = MessageBuilder.Group(forward.GroupId).Add(multi).Build();
var ret = await context.SendMessage(chain);

if (ret.Result != 0) return new OneBotResult(null, (int)ret.Result, "failed");
if (ret.Sequence == null || ret.Sequence == 0) return new OneBotResult(null, 9000, "failed");

int hash = MessageRecord.CalcMessageHash(chain.MessageId, ret.Sequence ?? 0);

return new OneBotResult(new OneBotForwardResponse(hash, multi.ResId ?? ""), (int)ret.Result, "ok");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
OneBotGroupMessageText messageText => common.ParseChain(messageText).Build(),
_ => throw new Exception()
};

var result = await context.SendMessage(chain);

if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed");
if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed");

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 @@ -26,6 +26,7 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
var result = await context.SendMessage(chain);

if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed");
if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed");

int hash = MessageRecord.CalcMessageHash(result.MessageId, result.Sequence ?? 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
var result = await context.SendMessage(chain);

if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed");
if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed");

int hash = MessageRecord.CalcMessageHash(result.MessageId, result.Sequence ?? 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
var result = await context.SendMessage(chain);

if (result.Result != 0) return new OneBotResult(null, (int)result.Result, "failed");
if (result.Sequence == null || result.Sequence == 0) return new OneBotResult(null, 9000, "failed");

int hash = MessageRecord.CalcMessageHash(result.MessageId, result.Sequence ?? 0);

Expand Down
2 changes: 1 addition & 1 deletion Lagrange.OneBot/LagrangeAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public LagrangeAppBuilder ConfigureBots()
{
appInfo = JsonSerializer.Deserialize<BotAppInfo>(File.ReadAllText(appInfoPath)) ?? BotAppInfo.ProtocolToAppInfo[config.Protocol];
}

Services.AddSingleton(BotFactory.Create(config, deviceInfo, keystore, appInfo));

return this;
Expand Down
9 changes: 6 additions & 3 deletions Lagrange.OneBot/Utility/QrCodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ internal static void Output(string text, bool compatibilityMode)
if (foregroundBlack && !backgroundBlack)
{
Console.Write(bottomHalfBlock);
} else if (!foregroundBlack && backgroundBlack)
}
else if (!foregroundBlack && backgroundBlack)
{
Console.Write(topHalfBlock);
} else if (foregroundBlack && backgroundBlack)
}
else if (foregroundBlack && backgroundBlack)
{
Console.Write(emptyBlock);

} else if (!foregroundBlack && !backgroundBlack)
}
else if (!foregroundBlack && !backgroundBlack)
{
Console.Write(fullBlock);
}
Expand Down

0 comments on commit c79f814

Please sign in to comment.