-
Notifications
You must be signed in to change notification settings - Fork 286
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
1 parent
ea4474d
commit 20b656e
Showing
4 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
|
||
namespace Lagrange.Core.Internal.Event.System; | ||
|
||
internal class FetchRKeyEvent : ProtocolEvent | ||
{ | ||
public List<string> RKeys { get; } = new(); | ||
public List<RKeyInfo> RKeys { get; } = new(); | ||
|
||
private FetchRKeyEvent() : base(true) | ||
{ | ||
} | ||
private FetchRKeyEvent() : base(true) { } | ||
|
||
private FetchRKeyEvent(int resultCode, List<string> rKeys) : base(resultCode) | ||
private FetchRKeyEvent(int resultCode, List<RKeyInfo> rKeys) : base(resultCode) | ||
{ | ||
RKeys = rKeys; | ||
} | ||
|
||
public static FetchRKeyEvent Create() => new(); | ||
public static FetchRKeyEvent Result(int resultCode, List<string> rKeys) => new(resultCode, rKeys); | ||
|
||
public static FetchRKeyEvent Result(int resultCode, List<RKeyInfo> rKeys) => new(resultCode, rKeys); | ||
} |
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
18 changes: 18 additions & 0 deletions
18
Lagrange.OneBot/Core/Entity/Action/Response/OneBotGetRkeyResponse.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,18 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action.Response; | ||
|
||
[Serializable] | ||
public class OneBotGetRkeyResponse(List<OneBotRkey> rkeys) | ||
{ | ||
[JsonPropertyName("rkeys")] public List<OneBotRkey> Rkeys { get; set; } = rkeys; | ||
} | ||
|
||
[Serializable] | ||
public class OneBotRkey | ||
{ | ||
[JsonPropertyName("type")] public string? Type { get; set; } | ||
[JsonPropertyName("rkey")] public string? Rkey { get; set; } | ||
[JsonPropertyName("created_at")] public uint? CreateTime { get; set; } | ||
[JsonPropertyName("ttl")] public ulong? TtlSeconds { get; set; } | ||
} |
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,30 @@ | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Internal.Event.System; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Core.Entity.Action.Response; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Generic; | ||
|
||
[Operation("get_rkey")] | ||
public class GetRkey : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload) | ||
{ | ||
var fetchRKeyEvent = FetchRKeyEvent.Create(); | ||
var events = await context.ContextCollection.Business.SendEvent(fetchRKeyEvent); | ||
var rKeyEvent = (FetchRKeyEvent)events[0]; | ||
if (rKeyEvent.ResultCode != 0) return new OneBotResult(null, rKeyEvent.ResultCode, "failed"); | ||
var response = new OneBotGetRkeyResponse(rKeyEvent.RKeys.Select(x => new OneBotRkey | ||
{ | ||
Type = x.Type == 10 | ||
? "private" | ||
: "group", | ||
Rkey = x.Rkey, | ||
CreateTime = x.RkeyCreateTime, | ||
TtlSeconds = x.RkeyTtlSec | ||
}) | ||
.ToList()); | ||
return new OneBotResult(response, 0, "ok"); | ||
} | ||
} |