Skip to content

Commit

Permalink
Merge pull request #63 from GodLeaveMe/2.4
Browse files Browse the repository at this point in the history
add support for announcement.
  • Loading branch information
ksharperd authored Nov 17, 2022
2 parents 840ee03 + 0c46502 commit 83da008
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Mirai.Net/Data/Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ public enum Events
[EnumMember(Value = "At")]
At,

/// <summary>
/// 命令被执行
/// </summary>
[Description("CommandExecutedEven")]
[EnumMember(Value = "CommandExecutedEven")]
CommandExecuted,

/// <summary>
/// 未知类型的事件
/// </summary>
Expand Down
3 changes: 0 additions & 3 deletions Mirai.Net/Data/Messages/Receivers/TempSyncMessageReceiver.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Mirai.Net.Data.Shared;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Mirai.Net.Data.Messages.Receivers
{
Expand Down
9 changes: 8 additions & 1 deletion Mirai.Net/Data/Sessions/HttpEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ internal enum HttpEndpoints
[Description("memberInfo")] MemberInfo,
[Description("userProfile")] UserProfile,

[Description("anno/list")] GetAnnouncement,
[Description("anno/publish")] PubAnnouncement,
[Description("anno/delete")] DelAnnouncement,

[Description("resp/newFriendRequestEvent")]
NewFriendRequested,

Expand All @@ -60,5 +64,8 @@ internal enum HttpEndpoints
BotInvited,

[Description("messageFromId")]
MessageFromId
MessageFromId,

[Description("cmd/execute")] ExecuteCommand,
[Description("cmd/register")] RegisterCommand
}
53 changes: 53 additions & 0 deletions Mirai.Net/Data/Shared/Announcement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Newtonsoft.Json;

namespace Mirai.Net.Data.Shared
{
/// <summary>
/// 群公告
/// </summary>
public record Announcement
{
/// <summary>
/// 群信息
/// </summary>
[JsonProperty("group")]
public Group Group { get; set; }

/// <summary>
/// 群公告内容
/// </summary>
[JsonProperty("content")]
public string Content { get; set; }

/// <summary>
/// 发布者账号
/// </summary>
[JsonProperty("senderID")]
public string SenderID { get; set; }

/// <summary>
/// 公告唯一id
/// </summary>
[JsonProperty("fid")]
public string Fid { get; set; }

/// <summary>
/// 是否所有群成员已确认
/// </summary>
[JsonProperty("allConfirmed")]
public bool AllConfirmed { get; set; }

/// <summary>
/// 确认群成员人数
/// </summary>
[JsonProperty("confirmedMembersCount")]
public string ConfirmedMembersCount { get; set; }

/// <summary>
/// 发布时间
/// </summary>
[JsonProperty("publicationTime")]
public string PublicationTime { get; set; }

}
}
72 changes: 72 additions & 0 deletions Mirai.Net/Data/Shared/AnnouncementSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Newtonsoft.Json;

namespace Mirai.Net.Data.Shared
{
/// <summary>
/// 群公告设置
/// </summary>
public record AnnouncementSetting
{

/// <summary>
/// 群号
/// </summary>
[JsonProperty("target")]
public string Target { get; set; }

/// <summary>
/// 公告内容
/// </summary>
[JsonProperty("content")]
public string Content { get; set; } = "";

/// <summary>
/// 是否发送给新成员
/// </summary>
[JsonProperty("sendToNewMember")]
public bool SendToNewMember { get; set; } = false;

/// <summary>
/// 是否置顶
/// </summary>
[JsonProperty("pinned")]
public bool Pinned { get; set; } = false;

/// <summary>
/// 是否显示群成员修改群名片的引导
/// </summary>
[JsonProperty("showEditCard")]
public bool ShowEditCard { get; set; } = false;

/// <summary>
/// 是否自动弹出
/// </summary>
[JsonProperty("showPopup")]
public bool ShowPopup { get; set; } = false;

/// <summary>
/// 是否需要群成员确认
/// </summary>
[JsonProperty("requireConfirmation")]
public bool RequireConfirmation { get; set; } = false;

/// <summary>
/// 公告图片url
/// </summary>
[JsonProperty("imageUrl")]
public string ImageUrl { get; set; }

/// <summary>
/// 公告图片本地路径
/// </summary>
[JsonProperty("imagePath")]
public string ImagePath { get; set; }

/// <summary>
/// 公告图片base64编码
/// </summary>
[JsonProperty("imageBase64")]
public string ImageBase64 { get; set; }

}
}
150 changes: 150 additions & 0 deletions Mirai.Net/Sessions/Http/Managers/ConsoleManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Manganese.Array;
using Mirai.Net.Data.Events;
using Mirai.Net.Data.Sessions;
using Mirai.Net.Utils.Internal;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Reactive;
using System.Threading.Tasks;

namespace Mirai.Net.Sessions.Http.Managers
{

/// <summary>
/// 控制台管理器
/// </summary>
/// 在功能稳定前保持可见性为 internal
[Experimental]
#if DEBUG
public static class ConsoleManager
#else
internal static class ConsoleManager
#endif
{

/// <summary>
/// 内部小把戏
/// </summary>
/// 在功能稳定前使用此方法加入内部事件类型
static ConsoleManager()
{
var field = typeof(ReflectionUtils).GetField("EventBases", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
if (field != null)
{
if (field.GetValue(null) == null)
{
field.SetValue(null, ReflectionUtils.GetDefaultInstances<EventBase>("Mirai.Net.Data.Events.Concretes"));
}
var eventBases = field.GetValue(null);
((IEnumerable<EventBase>)eventBases).Add(new EventBase[] { new CommandExecutedEvent() });
}
}

/// <summary>
/// 执行命令
/// </summary>
/// <param name="command">
/// <para>命令与参数</para>
/// <para>控制台支持以不同消息类型作为指令的参数, 执行命令需要以消息类型作为参数, 若执行纯文本的命令, 构建多个文本格式的消息控制台会将第一个消息作为指令名, 后续消息作为参数</para>
/// </param>
/// <returns></returns>
public static async Task ExecuteCommandAsync(object[] command)
{
await HttpEndpoints.ExecuteCommand.PostJsonAsync(command);
}

/// <summary>
/// <para>注册命令</para>
/// <para>注册的命令会直接覆盖已有的指令(包括控制台内置的指令)</para>
/// </summary>
/// <param name="name">指令名</param>
/// <param name="usage">使用说明</param>
/// <param name="description">命令描述</param>
/// <returns></returns>
public static async Task RegisterCommandAsync(string name, string usage, string description)
{
await HttpEndpoints.RegisterCommand.PostJsonAsync(new
{
name,
usage,
description
});
}

/// <summary>
/// <para>注册命令</para>
/// <para>注册的命令会直接覆盖已有的指令(包括控制台内置的指令)</para>
/// </summary>
/// <param name="command">命令</param>
/// <returns></returns>
public static async Task RegisterCommandAsync(Command command)
{
await HttpEndpoints.RegisterCommand.PostJsonAsync(command);
}

/// <summary>
/// 命令
/// </summary>
/// 在功能稳定前保持此类为内部类
public record Command
{

/// <summary>
/// 指令名
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// 指令别名
/// </summary>
[JsonProperty("alias")]
public string[] Alias { get; set; }

/// <summary>
/// 使用说明
/// </summary>
[JsonProperty("usage")]
public string Usage { get; set; }

/// <summary>
/// 命令描述
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }
}

/// <summary>
/// 命令被执行
/// </summary>
/// 在功能稳定前保持此类为内部类
public record CommandExecutedEvent : EventBase
{
/// <summary>
/// 事件类型
/// </summary>
public override Events Type { get; set; } = Events.CommandExecuted;

/// <summary>
/// 命令名称
/// </summary>
[JsonProperty("name")] public string Name { get; private set; }

/// <summary>
/// 发送命令的好友, 从控制台发送为 null
/// </summary>
[JsonProperty("friend")] public string FriendId { get; private set; }

/// <summary>
/// 发送命令的群成员, 从控制台发送为 nul
/// </summary>
[JsonProperty("member")] public string MemberId { get; private set; }

/// <summary>
/// 指令的参数, 以消息类型传递
/// </summary>
[JsonProperty("args")] public dynamic Args { get; private set; }
}

}
}
Loading

0 comments on commit 83da008

Please sign in to comment.