submodule对gitea不管用,所以直接拉了一份拉格兰
This commit is contained in:
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("delete_friend")]
|
||||
public class DeleteFriendOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotDeleteFriend>(SerializerOptions.DefaultOptions) is {} delete)
|
||||
{
|
||||
return await context.DeleteFriend(delete.UserId, delete.Block)
|
||||
? new OneBotResult(null, 0, "ok")
|
||||
: new OneBotResult(null, 0, "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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.Generic;
|
||||
|
||||
[Operation("fetch_custom_face")]
|
||||
internal class FetchCustomFaceOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload) =>
|
||||
new(await context.FetchCustomFace(), 0, "ok");
|
||||
}
|
||||
@@ -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.Generic;
|
||||
|
||||
[Operation("fetch_mface_key")]
|
||||
internal class FetchMFaceKeyOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload?["emoji_ids"]?.Deserialize<string[]>() is { Length: not 0 } emojiIds)
|
||||
{
|
||||
if (await context.FetchMarketFaceKey([.. emojiIds]) is { Count: not 0 } keys)
|
||||
{
|
||||
return new(keys, 0, "ok");
|
||||
}
|
||||
else return new(Array.Empty<string>(), -1, "failed");
|
||||
}
|
||||
else throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Message;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
using Lagrange.OneBot.Database;
|
||||
using LiteDB;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
|
||||
[Operation(".join_friend_emoji_chain")]
|
||||
public class FriendJoinEmojiChainOperation(LiteDatabase database) : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotPrivateJoinEmojiChain>(SerializerOptions.DefaultOptions) is { } data)
|
||||
{
|
||||
var message = (MessageChain)database.GetCollection<MessageRecord>().FindById(data.MessageId);
|
||||
bool res = await context.FriendJoinEmojiChain(data.UserId, data.EmojiId, message.Sequence);
|
||||
return new OneBotResult(null, res ? 0 : -1, res ? "ok" : "failed");
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("get_ai_characters")]
|
||||
public class GetAiCharacters : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotGetAiCharacters>(SerializerOptions.DefaultOptions)
|
||||
?? throw new Exception();
|
||||
|
||||
var (code, errMsg, result) = await context.GetAiCharacters(message.ChatType, message.GroupId);
|
||||
if (code != 0) return new(null, -1, "failed");
|
||||
|
||||
return result != null
|
||||
? new OneBotResult(result.Select(x => new OneBotAiCharacters(x)), 0, "ok")
|
||||
: new OneBotResult(null, -1, "failed");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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.Generic;
|
||||
|
||||
[Operation("get_cookies")]
|
||||
public class GetCookiesOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload?["domain"]?.ToString() is { } domain)
|
||||
{
|
||||
var cookies = await context.FetchCookies([domain]);
|
||||
return new OneBotResult(new JsonObject { { "cookies", cookies[0] } }, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Notify;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("get_credentials")]
|
||||
public class GetCredentialsOperation(TicketService ticket) : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload?["domain"]?.ToString() is { } domain)
|
||||
{
|
||||
var cookies = await context.FetchCookies([domain]);
|
||||
int bkn = await ticket.GetCsrfToken();
|
||||
|
||||
return new OneBotResult(new JsonObject
|
||||
{
|
||||
{ "cookies", cookies[0] },
|
||||
{ "csrf_token", bkn }
|
||||
}, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Notify;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("get_csrf_token")]
|
||||
public class GetCsrfTokenOperation(TicketService ticket) : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
int bkn = await ticket.GetCsrfToken();
|
||||
return new OneBotResult(new JsonObject { { "token", bkn } }, 0, "ok");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Internal.Event.System;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Entity.Action.Response;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("get_rkey")]
|
||||
public class GetRkey : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var fetchRKeyEvent = FetchRKeyEvent.Create();
|
||||
var events = await context.ContextCollection.Business.SendEvent(fetchRKeyEvent);
|
||||
var rKeyEvent = (FetchRKeyEvent)events[0];
|
||||
if (rKeyEvent.ResultCode != 0) return new OneBotResult(null, rKeyEvent.ResultCode, "failed");
|
||||
var response = new OneBotGetRkeyResponse(rKeyEvent.RKeys.Select(x => new OneBotRkey
|
||||
{
|
||||
Type = x.Type == 10
|
||||
? "private"
|
||||
: "group",
|
||||
Rkey = x.Rkey,
|
||||
CreateTime = x.RkeyCreateTime,
|
||||
TtlSeconds = x.RkeyTtlSec
|
||||
})
|
||||
.ToList());
|
||||
return new OneBotResult(response, 0, "ok");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Message;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
using Lagrange.OneBot.Database;
|
||||
using LiteDB;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
|
||||
[Operation(".join_group_emoji_chain")]
|
||||
public class GroupJoinEmojiChainOperation(LiteDatabase database) : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotGroupJoinEmojiChain>(SerializerOptions.DefaultOptions) is { } data)
|
||||
{
|
||||
var message = (MessageChain)database.GetCollection<MessageRecord>().FindById(data.MessageId);
|
||||
bool res = await context.GroupJoinEmojiChain(data.GroupId, data.EmojiId, message.Sequence);
|
||||
return new OneBotResult(null, res ? 0 : -1, res ? "ok" : "failed");
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Message.Entity;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
using Lagrange.OneBot.Message.Entity;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
|
||||
[Operation(".ocr_image")]
|
||||
[Operation("ocr_image")]
|
||||
public class OcrImageOperation() : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotOcrImage>(SerializerOptions.DefaultOptions) is { } data && CommonResolver.ResolveStream(data.Image) is { } stream)
|
||||
{
|
||||
var entity = new ImageEntity(stream);
|
||||
var res = await context.OcrImage(entity);
|
||||
return new OneBotResult(res, 0, "ok");
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("send_like")]
|
||||
public class SendLikeOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotSendLike>(SerializerOptions.DefaultOptions) is { } like)
|
||||
{
|
||||
return await context.Like(like.UserId, like.Times ?? 1) // the times is ignored to simulate the real user behaviour
|
||||
? new OneBotResult(null, 0, "ok")
|
||||
: new OneBotResult(null, 0, "user not found in the buffer");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Internal.Packets;
|
||||
using Lagrange.Core.Utility.Extension;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Entity.Action.Response;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation(".send_packet")]
|
||||
public class SendPacketOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotSendPacket>() is { } send)
|
||||
{
|
||||
int sequence = context.ContextCollection.Service.GetNewSequence();
|
||||
var ssoPacket = new SsoPacket(send.Type, send.Command, (uint)sequence, send.Data.UnHex());
|
||||
var task = await context.ContextCollection.Packet.SendPacket(ssoPacket);
|
||||
|
||||
return new OneBotResult(new OneBotSendPacketResponse
|
||||
{
|
||||
Sequence = sequence,
|
||||
RetCode = task.RetCode,
|
||||
Extra = task.Extra,
|
||||
Result = task.Payload.Hex()
|
||||
}, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.Core.Message.Entity;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Message.Entity;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("set_qq_avatar")]
|
||||
public class SetQQAvatar : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload?["file"]?.ToString() is { } portrait)
|
||||
{
|
||||
var image = CommonResolver.ResolveStream(portrait);
|
||||
if (image == null) throw new Exception();
|
||||
|
||||
var imageEntity = new ImageEntity(image);
|
||||
bool result = await context.SetAvatar(imageEntity);
|
||||
return new OneBotResult(null, result ? 0 : 1, "");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Generic;
|
||||
|
||||
[Operation("set_restart")]
|
||||
public class SetRestartOperation(IHost host) : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await host.StopAsync();
|
||||
await host.StartAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user