From 20c633eed688b6bc8c769da799a1c33d6ff89082 Mon Sep 17 00:00:00 2001 From: Linwenxuan <116782992+Linwenxuan05@users.noreply.github.com> Date: Sat, 14 Oct 2023 21:43:14 +0800 Subject: [PATCH] Implemented GroupInfo for Lagrange.OneBot --- .../Core/Entity/Action/OneBotGetGroupInfo.cs | 11 ++++++++ Lagrange.OneBot/Core/Entity/OneBotGroup.cs | 15 +++++++++++ .../Operation/Info/GetGroupInfoOperation.cs | 22 ++++++++++++++++ .../Operation/Info/GetGroupListOperation.cs | 25 +++++++++++++++++++ README.md | 4 +-- 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 Lagrange.OneBot/Core/Entity/Action/OneBotGetGroupInfo.cs create mode 100644 Lagrange.OneBot/Core/Entity/OneBotGroup.cs create mode 100644 Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs create mode 100644 Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs diff --git a/Lagrange.OneBot/Core/Entity/Action/OneBotGetGroupInfo.cs b/Lagrange.OneBot/Core/Entity/Action/OneBotGetGroupInfo.cs new file mode 100644 index 000000000..13f28bf53 --- /dev/null +++ b/Lagrange.OneBot/Core/Entity/Action/OneBotGetGroupInfo.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace Lagrange.OneBot.Core.Entity.Action; + +[Serializable] +public class OneBotGetGroupInfo +{ + [JsonPropertyName("group_id")] public uint GroupId { get; set; } + + [JsonPropertyName("no_cache")] public bool NoCache { get; set; } +} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Entity/OneBotGroup.cs b/Lagrange.OneBot/Core/Entity/OneBotGroup.cs new file mode 100644 index 000000000..03eba165f --- /dev/null +++ b/Lagrange.OneBot/Core/Entity/OneBotGroup.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace Lagrange.OneBot.Core.Entity; + +[Serializable] +public class OneBotGroup(uint groupId, string groupName) +{ + [JsonPropertyName("group_id")] public uint GroupId { get; set; } = groupId; + + [JsonPropertyName("group_name")] public string GroupName { get; set; } = groupName; + + [JsonPropertyName("member_count")] public int MemberCount { get; set; } + + [JsonPropertyName("max_member_count")] public int MaxMemberCount { get; set; } +} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs new file mode 100644 index 000000000..5e6166490 --- /dev/null +++ b/Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs @@ -0,0 +1,22 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using Lagrange.Core; +using Lagrange.Core.Common.Interface.Api; +using Lagrange.OneBot.Core.Entity.Action; + +namespace Lagrange.OneBot.Core.Operation.Info; + +[Operation("get_group_info")] +public class GetGroupInfoOperation : IOperation +{ + public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + { + if (payload.Deserialize() is { } message) + { + var result = await context.FetchGroups(message.NoCache); + return new OneBotResult(result.FirstOrDefault(x => x.GroupUin == message.GroupId), 0, "ok", echo); + } + + throw new Exception(); + } +} \ No newline at end of file diff --git a/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs b/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs new file mode 100644 index 000000000..bdd3b70c4 --- /dev/null +++ b/Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs @@ -0,0 +1,25 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using Lagrange.Core; +using Lagrange.Core.Common.Interface.Api; +using Lagrange.OneBot.Core.Entity.Action; + +namespace Lagrange.OneBot.Core.Operation.Info; + +[Operation("get_group_list")] +public class GetGroupListOperation : IOperation +{ + public async Task HandleOperation(string echo, BotContext context, JsonObject? payload) + { + if (payload.Deserialize() is { } message) + { + var result = await context.FetchGroups(message.NoCache); + return new OneBotResult(result, 0, "ok", echo); + } + else + { + var result = await context.FetchGroups(); + return new OneBotResult(result, 0, "ok", echo); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index e4e8aaa33..fcbe6aa3f 100644 --- a/README.md +++ b/README.md @@ -123,8 +123,8 @@ Please use Lagrange.Core responsibly and in accordance with the law. | [/get_login_info] | 🟢 | | [/get_stranger_info] | 🔴 | | [/get_friend_list] | 🔴 | -| [/get_group_info] | 🔴 | -| [/get_group_list] | 🔴 | +| [/get_group_info] | 🟢 | +| [/get_group_list] | 🟢 | | [/get_group_member_info] | 🔴 | | [/get_group_member_list] | 🔴 | | [/get_group_honor_info] | 🔴 |