Skip to content

Commit

Permalink
Implemented GroupInfo for Lagrange.OneBot
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 14, 2023
1 parent 3e1fefa commit 20c633e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Lagrange.OneBot/Core/Entity/Action/OneBotGetGroupInfo.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
15 changes: 15 additions & 0 deletions Lagrange.OneBot/Core/Entity/OneBotGroup.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
22 changes: 22 additions & 0 deletions Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs
Original file line number Diff line number Diff line change
@@ -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<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
{
if (payload.Deserialize<OneBotGetGroupInfo>() 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();
}
}
25 changes: 25 additions & 0 deletions Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs
Original file line number Diff line number Diff line change
@@ -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<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
{
if (payload.Deserialize<OneBotGetGroupInfo>() 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);
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] | 🔴 |
Expand Down

0 comments on commit 20c633e

Please sign in to comment.