submodule对gitea不管用,所以直接拉了一份拉格兰
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Notify;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("_del_group_notice")]
|
||||
public class DeleteGroupMemoOperation(TicketService ticket) : IOperation
|
||||
{
|
||||
private const string Url = "https://web.qun.qq.com/cgi-bin/announce/del_feed";
|
||||
private const string Domain = "qun.qq.com";
|
||||
|
||||
private async Task<bool> DeleteGroupNotice(OneBotDeleteGroupMemo memo)
|
||||
{
|
||||
string url = $"{Url}?fid={memo.NoticeId}&qid={memo.GroupId}&bkn={await ticket.GetCsrfToken()}&ft=23&op=1";
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
try
|
||||
{
|
||||
var response = await ticket.SendAsync(request, Domain);
|
||||
response.EnsureSuccessStatusCode();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotDeleteGroupMemo>(SerializerOptions.DefaultOptions) is { } memo)
|
||||
{
|
||||
return await DeleteGroupNotice(memo)
|
||||
? new OneBotResult(null, 0, "ok")
|
||||
: new OneBotResult(null, -1, "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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.Group;
|
||||
|
||||
[Operation("get_ai_record")]
|
||||
public class GetAiRecordOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotGetAiRecord>(SerializerOptions.DefaultOptions);
|
||||
if (message != null)
|
||||
{
|
||||
var (code, errMsg, url) = await context.GetGroupGenerateAiRecordUrl(
|
||||
message.GroupId,
|
||||
message.Character,
|
||||
message.Text,
|
||||
message.ChatType
|
||||
);
|
||||
return code != 0 ? new OneBotResult(errMsg, code, "failed") : new OneBotResult(url, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.RegularExpressions;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Notify;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("get_group_honor_info")]
|
||||
public partial class GetGroupHonorInfoOperation(TicketService ticket) : IOperation
|
||||
{
|
||||
[GeneratedRegex(@"window\.__INITIAL_STATE__\s*?=\s*?(\{.*?);")]
|
||||
public static partial Regex HonorRegex();
|
||||
|
||||
private static readonly Dictionary<string, string> Keys = new()
|
||||
{
|
||||
{ "group_id", "group_id" }, { "current_talkative", "currentTalkative" }, { "talkative_list", "talkativeList" },
|
||||
{ "performer_list", "" }, { "legend_list", "legendList" }, { "strong_newbie_list", "strongnewbieList" },
|
||||
{ "emotion_list", "emotionList" }
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, int> HonorToType = new()
|
||||
{
|
||||
{ "talkative", 1 }, { "performer", 2 }, { "legend", 3 }, { "strong_newbie", 5 }, { "emotion", 6 },
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, string> KeyToOnebot11 = new()
|
||||
{
|
||||
{"uin", "user_id"}, {"name", "nickname"}, {"nick", "nickname"}, {"desc", "description"}
|
||||
};
|
||||
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotHonorInfo>(SerializerOptions.DefaultOptions) is { } honor)
|
||||
{
|
||||
var result = new JsonObject();
|
||||
var honors = honor.Type == "all"
|
||||
? HonorToType.Select(x => x.Key).ToArray()
|
||||
: [honor.Type];
|
||||
|
||||
result.TryAdd("group_id", honor.GroupId);
|
||||
|
||||
foreach (string honorRaw in honors)
|
||||
{
|
||||
string url = $"https://qun.qq.com/interactive/honorlist?gc={honor.GroupId}&type={HonorToType[honorRaw]}";
|
||||
var response = await ticket.SendAsync(new HttpRequestMessage(HttpMethod.Get, url));
|
||||
string raw = await response.Content.ReadAsStringAsync();
|
||||
var match = HonorRegex().Match(raw);
|
||||
|
||||
if (JsonSerializer.Deserialize<JsonObject>(match.Groups[1].Value) is { } json) // 神经病
|
||||
{
|
||||
foreach (var (key, value) in Keys)
|
||||
{
|
||||
if (json.Remove(value, out var node))
|
||||
{
|
||||
if (node is JsonObject jsonObject)
|
||||
{
|
||||
ProcessJsonObject(jsonObject);
|
||||
}
|
||||
else if (node is JsonArray jsonArray)
|
||||
{
|
||||
foreach (var subNode in jsonArray)
|
||||
{
|
||||
if (subNode is JsonObject subObject)
|
||||
{
|
||||
ProcessJsonObject(subObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (key.Contains(honorRaw)) result.TryAdd(key, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new OneBotResult(result, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private static void ProcessJsonObject(JsonObject jsonObject)
|
||||
{
|
||||
foreach (var oldKey in KeyToOnebot11.Keys)
|
||||
{
|
||||
if (jsonObject.Remove(oldKey, out var nodeValue))
|
||||
{
|
||||
jsonObject[KeyToOnebot11[oldKey]] = nodeValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.OneBot.Core.Entity;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Notify;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("_get_group_notice")]
|
||||
public class GetGroupMemoOperation(TicketService ticket) : IOperation
|
||||
{
|
||||
|
||||
private const string Url = "https://web.qun.qq.com/cgi-bin/announce/get_t_list";
|
||||
private const string Domain = "qun.qq.com";
|
||||
|
||||
private async Task<IEnumerable<OneBotGroupNotice>?> GetGroupNotice(OneBotGetGroupMemo memo)
|
||||
{
|
||||
var url = $"{Url}?bkn={await ticket.GetCsrfToken()}&qid={memo.GroupId}&ft=23&ni=1&n=1&i=1&log_read=1&platform=1&s=-1&n=20";
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||
try
|
||||
{
|
||||
var response = await ticket.SendAsync(request, Domain);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
var notices = JsonSerializer.Deserialize<GroupNoticeResponse>(content)!;
|
||||
return notices.Feeds.Concat(notices.Inst)
|
||||
.Select(feed => new OneBotGroupNotice(feed.NoticeId, feed.SenderId, feed.PublishTime,
|
||||
new OneBotGroupNoticeMessage(feed.Message.Text, feed.Message.Images.Select(image => new OneBotGroupNoticeImage(image.Id, image.Height, image.Width)))
|
||||
));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotGetGroupMemo>(SerializerOptions.DefaultOptions) is { } memo)
|
||||
{
|
||||
var notices = await GetGroupNotice(memo);
|
||||
return notices is null
|
||||
? new OneBotResult(null, -1, "failed")
|
||||
: new OneBotResult(notices, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class GroupNoticeImage
|
||||
{
|
||||
[JsonPropertyName("h")] public string Height { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("w")] public string Width { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("id")] public string Id { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class GroupNoticeMessage
|
||||
{
|
||||
[JsonPropertyName("text")] public string Text { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("pics")] public IEnumerable<GroupNoticeImage> Images { get; set; } = [];
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class GroupNoticeFeed
|
||||
{
|
||||
[JsonPropertyName("fid")] public string NoticeId { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("u")] public uint SenderId { get; set; }
|
||||
|
||||
[JsonPropertyName("pubt")] public long PublishTime { get; set; }
|
||||
|
||||
[JsonPropertyName("msg")] public GroupNoticeMessage Message { get; set; } = new();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class GroupNoticeResponse
|
||||
{
|
||||
[JsonPropertyName("feeds")] public IEnumerable<GroupNoticeFeed> Feeds { get; set; } = [];
|
||||
|
||||
[JsonPropertyName("inst")] public IEnumerable<GroupNoticeFeed> Inst { get; set; } = [];
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_admin")]
|
||||
public class SetGroupAdminOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupAdmin>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.SetGroupAdmin(message.GroupId, message.UserId, message.Enable);
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_ban")]
|
||||
public class SetGroupBanOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupBan>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.MuteGroupMember(message.GroupId, message.UserId, message.Duration);
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
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.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_bot_status")]
|
||||
public class SetGroupBotOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupBot>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.SetGroupBot(message.BotId, message.Enable , message.GroupId);
|
||||
|
||||
return new OneBotResult(message.BotId, 0, "ok");
|
||||
}
|
||||
|
||||
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.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("send_group_bot_callback")]
|
||||
public class SetGroupBothdOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupBothd>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.SetGroupBotHD(message.BotId, message.GroupId, message.Data_1, message.Data_2);
|
||||
|
||||
return new OneBotResult(message.BotId, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_card")]
|
||||
public class SetGroupCardOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupCard>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.RenameGroupMember(message.GroupId, message.UserId, message.Card);
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_kick")]
|
||||
public class SetGroupKickOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupKick>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.KickGroupMember(message.GroupId, message.UserId, message.RejectAddRequest);
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_leave")]
|
||||
public class SetGroupLeaveOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupLeave>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.LeaveGroup(message.GroupId); // TODO: Figure out is_dismiss
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json.Serialization;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Notify;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("_send_group_notice")]
|
||||
public class SetGroupMemoOperation(TicketService ticket) : IOperation
|
||||
{
|
||||
private const string Url = "https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=";
|
||||
private const string UserAgent = "Dalvik/2.1.0 (Linux; U; Android 7.1.2; PCRT00 Build/N2G48H)";
|
||||
private const string Domain = "qun.qq.com";
|
||||
|
||||
private async Task<string?> SendGroupNoticeSimple(OneBotSetGroupMemo memo)
|
||||
{
|
||||
int bkn = await ticket.GetCsrfToken();
|
||||
string body = $"qid={memo.GroupId}&bkn={bkn}&text={Uri.EscapeDataString(memo.Content)}&pinned=0&type=1&settings={{\"is_show_edit_card\":0,\"tip_window_type\":1,\"confirm_required\":1}}";
|
||||
string url = Url + bkn;
|
||||
try
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, url);
|
||||
request.Headers.UserAgent.ParseAdd(UserAgent);
|
||||
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var response = await ticket.SendAsync(request, Domain);
|
||||
response.EnsureSuccessStatusCode();
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var sendResponse = JsonSerializer.Deserialize<NoticeSendResponse>(content);
|
||||
return sendResponse?.NoticeId;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotSetGroupMemo>(SerializerOptions.DefaultOptions) is { } memo)
|
||||
{
|
||||
var noticeId = string.IsNullOrEmpty(memo.Image)
|
||||
? await SendGroupNoticeSimple(memo)
|
||||
: throw new NotImplementedException();
|
||||
|
||||
return noticeId is null
|
||||
? new OneBotResult(null, -1, "failed")
|
||||
: new OneBotResult(noticeId, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class NoticeSendResponse
|
||||
{
|
||||
[JsonPropertyName("new_fid")] public string NoticeId { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class NoticeImageUploadResponse
|
||||
{
|
||||
[JsonPropertyName("ec")] public int ErrorCode { get; set; }
|
||||
[JsonPropertyName("em")] public string ErrorMessage { get; set; } = string.Empty;
|
||||
[JsonPropertyName("id")] public string Id { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
file class GroupNoticeImage
|
||||
{
|
||||
[JsonPropertyName("h")] public string Height { get; set; } = string.Empty;
|
||||
[JsonPropertyName("w")] public string Width { get; set; } = string.Empty;
|
||||
[JsonPropertyName("id")] public string Id { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_name")]
|
||||
public class SetGroupNameOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupName>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.RenameGroup(message.GroupId, message.GroupName);
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Text.Json;
|
||||
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.Core.Operation.Converters;
|
||||
using Lagrange.OneBot.Message.Entity;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_portrait")]
|
||||
public class SetGroupPortraitOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotSetGroupPortrait>(SerializerOptions.DefaultOptions) is { } portrait)
|
||||
{
|
||||
var image = CommonResolver.ResolveStream(portrait.File);
|
||||
if (image == null) throw new Exception();
|
||||
|
||||
var imageEntity = new ImageEntity(image);
|
||||
bool result = await context.GroupSetAvatar(portrait.GroupId, imageEntity);
|
||||
return new OneBotResult(null, result ? 0 : 1, "");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Lagrange.Core;
|
||||
using Lagrange.Core.Common.Interface.Api;
|
||||
using Lagrange.Core.Message;
|
||||
using Lagrange.OneBot.Core.Entity.Action;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
using Lagrange.OneBot.Database;
|
||||
using LiteDB;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_reaction")]
|
||||
public class SetGroupReactionOperation(LiteDatabase database) : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotSetGroupReaction>(SerializerOptions.DefaultOptions) is { } data)
|
||||
{
|
||||
var message = (MessageChain)database.GetCollection<MessageRecord>().FindById(data.MessageId);
|
||||
|
||||
bool result = await context.GroupSetMessageReaction(data.GroupId, message.Sequence, data.Code, data.IsAdd);
|
||||
return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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.Group;
|
||||
|
||||
[Operation("set_group_special_title")]
|
||||
public class SetGroupSpecialTitleOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
if (payload.Deserialize<OneBotSetGroupSpecialTitle>(SerializerOptions.DefaultOptions) is { } title)
|
||||
{
|
||||
bool result = await context.GroupSetSpecialTitle(title.GroupId, title.UserId, title.SpecialTitle);
|
||||
return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
using Lagrange.OneBot.Core.Operation.Converters;
|
||||
|
||||
namespace Lagrange.OneBot.Core.Operation.Group;
|
||||
|
||||
[Operation("set_group_whole_ban")]
|
||||
public class SetGroupWholeBanOperation : IOperation
|
||||
{
|
||||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
|
||||
{
|
||||
var message = payload.Deserialize<OneBotSetGroupWholeBan>(SerializerOptions.DefaultOptions);
|
||||
|
||||
if (message != null)
|
||||
{
|
||||
bool _ = await context.MuteGroupGlobal(message.GroupId, message.Enable);
|
||||
return new OneBotResult(null, 0, "ok");
|
||||
}
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user