-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented GroupInfo for Lagrange.OneBot
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Oct 14, 2023
1 parent
3e1fefa
commit 20c633e
Showing
5 changed files
with
75 additions
and
2 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 |
---|---|---|
@@ -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; } | ||
} |
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,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
22
Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.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,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
25
Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.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,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); | ||
} | ||
} | ||
} |
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