Skip to content

Commit

Permalink
[OneBot] Fixed object of Echo for OneBotAction.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 26, 2023
1 parent 84e2a41 commit 6b3d691
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Lagrange.OneBot/Core/Entity/Action/OneBotAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class OneBotAction

[JsonPropertyName("params")] public JsonObject? Params { get; set; }

[JsonPropertyName("echo")] public string Echo { get; set; } = "";
[JsonPropertyName("echo")] public JsonObject? Echo { get; set; }
}
5 changes: 3 additions & 2 deletions Lagrange.OneBot/Core/Entity/Action/OneBotResult.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace Lagrange.OneBot.Core.Entity.Action;

[Serializable]
public class OneBotResult(object? data, int retCode, string status, string echo)
public class OneBotResult(object? data, int retCode, string status)
{
[JsonPropertyName("status")] public string Status { get; set; } = status;

[JsonPropertyName("retcode")] public int RetCode { get; set; } = retCode;

[JsonPropertyName("data")] public object? Data { get; set; } = data;

[JsonPropertyName("echo")] public string Echo { get; set; } = echo;
[JsonPropertyName("echo")] public JsonObject? Echo { get; set; }

[JsonIgnore] public string? Identifier { get; internal set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_admin")]
public class SetGroupAdminOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(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);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Operation/Group/SetGroupBanOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_ban")]
public class SetGroupBanOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(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);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Operation/Group/SetGroupCardOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_card")]
public class SetGroupCardOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
var message = payload.Deserialize<OneBotSetGroupCard>();

if (message != null)
{
bool _ = await context.RenameGroupMember(message.GroupId, message.UserId, message.Card);
return new OneBotResult(null, 0, "ok", echo);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Operation/Group/SetGroupKickOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_kick")]
public class SetGroupKickOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(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);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_leave")]
public class SetGroupLeaveOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
var message = payload.Deserialize<OneBotSetGroupLeave>();

if (message != null)
{
bool _ = await context.LeaveGroup(message.GroupId); // TODO: Figure out is_dismiss
return new OneBotResult(null, 0, "ok", echo);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Operation/Group/SetGroupNameOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_name")]
public class SetGroupNameOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
var message = payload.Deserialize<OneBotSetGroupName>();

if (message != null)
{
bool _ = await context.RenameGroup(message.GroupId, message.GroupName);
return new OneBotResult(null, 0, "ok", echo);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Lagrange.OneBot.Core.Operation.Group;
[Operation("set_group_whole_ban")]
public class SetGroupWholeBanOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(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);
return new OneBotResult(null, 0, "ok");
}

throw new Exception();
Expand Down
2 changes: 1 addition & 1 deletion Lagrange.OneBot/Core/Operation/IOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Lagrange.OneBot.Core.Operation;

public interface IOperation
{
public Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload);
public Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload);
}
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Operation/Info/GetGroupInfoOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ 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)
public async Task<OneBotResult> HandleOperation(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);
return new OneBotResult(result.FirstOrDefault(x => x.GroupUin == message.GroupId), 0, "ok");
}

throw new Exception();
Expand Down
6 changes: 3 additions & 3 deletions Lagrange.OneBot/Core/Operation/Info/GetGroupListOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ 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)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
if (payload.Deserialize<OneBotGetGroupInfo>() is { } message)
{
var result = await context.FetchGroups(message.NoCache);
return new OneBotResult(result, 0, "ok", echo);
return new OneBotResult(result, 0, "ok");
}
else
{
var result = await context.FetchGroups();
return new OneBotResult(result, 0, "ok", echo);
return new OneBotResult(result, 0, "ok");
}
}
}
4 changes: 2 additions & 2 deletions Lagrange.OneBot/Core/Operation/Info/GetLoginInfoOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace Lagrange.OneBot.Core.Operation.Info;
[Operation("get_login_info")]
public class GetLoginInfoOperation : IOperation
{
public Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public Task<OneBotResult> HandleOperation(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));
return Task.FromResult(new OneBotResult(result, 0, "ok"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Lagrange.OneBot.Core.Operation.Info;
[Operation("get_version_info")]
public class GetVersionInfoOperation : IOperation
{
public Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public Task<OneBotResult> HandleOperation(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));
return Task.FromResult(new OneBotResult(new OneBotVersionInfoResponse(version), 0, "ok"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Lagrange.OneBot.Core.Operation.Message;
[Operation("send_group_msg")]
public sealed class SendGroupMessageOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
if (payload.Deserialize<OneBotGroupMessage>() is { } message)
{
await context.SendMessage(MessageCommon.ParseChain(message).Build());
return new OneBotResult(new OneBotMessageResponse(0), 0, "ok", echo);
return new OneBotResult(new OneBotMessageResponse(0), 0, "ok");
}

throw new Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Lagrange.OneBot.Core.Operation.Message;
[Operation("send_msg")]
public sealed class SendMessageOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
if (payload.Deserialize<OneBotMessage>() is { } message)
{
await context.SendMessage(MessageCommon.ParseChain(message).Build());
return new OneBotResult(new OneBotMessageResponse(0), 0, "ok", echo);
return new OneBotResult(new OneBotMessageResponse(0), 0, "ok");
}

throw new Exception();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Lagrange.OneBot.Core.Operation.Message;
[Operation("send_private_msg")]
public sealed class SendPrivateMessageOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(string echo, BotContext context, JsonObject? payload)
public async Task<OneBotResult> HandleOperation(BotContext context, JsonObject? payload)
{
if (payload.Deserialize<OneBotPrivateMessage>() is { } message)
{
await context.SendMessage(MessageCommon.ParseChain(message).Build());
return new OneBotResult(new OneBotMessageResponse(0), 0, "ok", echo);
return new OneBotResult(new OneBotMessageResponse(0), 0, "ok");
}

throw new Exception();
Expand Down
4 changes: 3 additions & 1 deletion Lagrange.OneBot/Core/Operation/OperationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ private async Task HandleOperation(string data)

if (supported && handler != null)
{
var result = await handler.HandleOperation(action.Echo, _bot, action.Params);
var result = await handler.HandleOperation(_bot, action.Params);
result.Echo = action.Echo;

await _service.SendJsonAsync(result);
}
}
Expand Down

0 comments on commit 6b3d691

Please sign in to comment.