-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented APIs for Lagrange.OneBot
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Oct 14, 2023
1 parent
f95318f
commit f565c54
Showing
17 changed files
with
222 additions
and
16 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
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,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupAdmin | ||
{ | ||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("user_id")] public uint UserId { get; set; } | ||
|
||
[JsonPropertyName("enable")] public bool Enable { 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,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupBan | ||
{ | ||
[JsonPropertyName("user_id")] public uint UserId { get; set; } | ||
|
||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("duration")] public uint Duration { 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,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupKick | ||
{ | ||
[JsonPropertyName("user_id")] public uint UserId { get; set; } | ||
|
||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("reject_add_request")] public bool RejectAddRequest { get; set; } | ||
} |
11 changes: 11 additions & 0 deletions
11
Lagrange.OneBot/Core/Entity/Action/OneBotSetGroupWholeBan.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,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotSetGroupWholeBan | ||
{ | ||
[JsonPropertyName("group_id")] public uint GroupId { get; set; } | ||
|
||
[JsonPropertyName("enable")] public bool Enable { get; set; } | ||
} |
11 changes: 11 additions & 0 deletions
11
Lagrange.OneBot/Core/Entity/Action/Response/OneBotLoginInfoResponse.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,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action.Response; | ||
|
||
[Serializable] | ||
public class OneBotLoginInfoResponse(uint userId, string nickName) | ||
{ | ||
[JsonPropertyName("user_id")] public uint UserId { get; set; } = userId; | ||
|
||
[JsonPropertyName("nickname")] public string NickName { get; set; } = nickName; | ||
} |
15 changes: 15 additions & 0 deletions
15
Lagrange.OneBot/Core/Entity/Action/Response/OneBotVersionInfoResponse.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,15 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action.Response; | ||
|
||
[Serializable] | ||
public class OneBotVersionInfoResponse(string ntProtocol) | ||
{ | ||
[JsonPropertyName("app_name")] public string AppName => Constant.OneBotImpl; | ||
|
||
[JsonPropertyName("app_version")] public string AppVersion => Constant.OneBotImplVersion; | ||
|
||
[JsonPropertyName("protocol_version")] public string ProtocolVersion => $"v{Constant.OneBotProtocolVersion}"; | ||
|
||
[JsonPropertyName("nt_protocol")] public string NTProtocol { get; } = ntProtocol; | ||
} |
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
17 changes: 17 additions & 0 deletions
17
Lagrange.OneBot/Core/Operation/Message/GetLoginInfoOperation.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,17 @@ | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Core.Entity.Action.Response; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Message; | ||
|
||
[Operation("get_login_info")] | ||
public class GetLoginInfoOperation : IOperation | ||
{ | ||
public Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var keystore = context.ContextCollection.Keystore; | ||
var result = new OneBotLoginInfoResponse(keystore.Uin, keystore.Info?.Name ?? ""); | ||
return Task.FromResult(new OneBotResult(result, 0, "ok", echo)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Lagrange.OneBot/Core/Operation/Message/GetVersionInfoOperation.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.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Core.Entity.Action.Response; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Message; | ||
|
||
[Operation("get_version_info")] | ||
public class GetVersionInfoOperation : IOperation | ||
{ | ||
public Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var appInfo = context.ContextCollection.AppInfo; | ||
string version = $"{appInfo.Os} | {appInfo.CurrentVersion}"; | ||
|
||
return Task.FromResult(new OneBotResult(new OneBotVersionInfoResponse(version), 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
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Message/SetGroupAdminOperation.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,24 @@ | ||
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.Message; | ||
|
||
[Operation("set_group_admin")] | ||
public class SetGroupAdminOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var message = payload.Deserialize<OneBotSetGroupAdmin>(); | ||
|
||
if (message != null) | ||
{ | ||
bool _ = await context.SetGroupAdmin(message.GroupId, message.UserId, message.Enable); | ||
return new OneBotResult(null, 0, "ok", echo); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Message/SetGroupBanOperation.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,24 @@ | ||
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.Message; | ||
|
||
[Operation("set_group_ban")] | ||
public class SetGroupBanOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var message = payload.Deserialize<OneBotSetGroupBan>(); | ||
|
||
if (message != null) | ||
{ | ||
bool _ = await context.MuteGroupMember(message.GroupId, message.UserId, message.Duration); | ||
return new OneBotResult(null, 0, "ok", echo); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Message/SetGroupKickOperation.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,24 @@ | ||
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.Message; | ||
|
||
[Operation("set_group_kick")] | ||
public class SetGroupKickOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var message = payload.Deserialize<OneBotSetGroupKick>(); | ||
|
||
if (message != null) | ||
{ | ||
bool _ = await context.KickGroupMember(message.GroupId, message.UserId, message.RejectAddRequest); | ||
return new OneBotResult(null, 0, "ok", echo); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Message/SetGroupWholeBanOperation.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,24 @@ | ||
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.Message; | ||
|
||
[Operation("set_group_whole_ban")] | ||
public class SetGroupWholeBanOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload) | ||
{ | ||
var message = payload.Deserialize<OneBotSetGroupWholeBan>(); | ||
|
||
if (message != null) | ||
{ | ||
bool _ = await context.MuteGroupGlobal(message.GroupId, message.Enable); | ||
return new OneBotResult(null, 0, "ok", echo); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
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
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