Skip to content

Commit

Permalink
Forum, GroupChannel, UserChannel events
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Jan 12, 2025
1 parent 99ed4ed commit a4fe52b
Show file tree
Hide file tree
Showing 21 changed files with 1,100 additions and 66 deletions.
42 changes: 42 additions & 0 deletions src/QQBot.Net.Core/Entities/Threads/IPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace QQBot;

/// <summary>
/// 表示一个通用的论坛主题评论。
/// </summary>
public interface IPost : IEntity<string>
{
/// <summary>
/// 获取此主题评论所属的频道。
/// </summary>
IGuild Guild { get; }

/// <summary>
/// 获取此主题评论所属的论坛子频道。
/// </summary>
IForumChannel Channel { get; }

/// <summary>
/// 获取此主题评论的作者用户的 ID。
/// </summary>
ulong AuthorId { get; }

/// <summary>
/// 获取此主题评论所属的主题的 ID。
/// </summary>
string ThreadId { get; }

/// <summary>
/// 获取此主题的原始内容。
/// </summary>
string RawContent { get; }

/// <summary>
/// 获取此主题评论的富文本内容。
/// </summary>
RichText Content { get; }

/// <summary>
/// 获取此主题评论的创建时间。
/// </summary>
DateTimeOffset CreatedAt { get; }
}
47 changes: 47 additions & 0 deletions src/QQBot.Net.Core/Entities/Threads/IReply.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace QQBot;

/// <summary>
/// 表示一个通用的论坛主题评论回复。
/// </summary>
public interface IReply : IEntity<string>
{
/// <summary>
/// 获取此主题评论回复所属的频道。
/// </summary>
IGuild Guild { get; }

/// <summary>
/// 获取此主题评论回复所属的论坛子频道。
/// </summary>
IForumChannel Channel { get; }

/// <summary>
/// 获取此主题评论回复的作者用户的 ID。
/// </summary>
ulong AuthorId { get; }

/// <summary>
/// 获取此主题评论回复所属的主题的 ID。
/// </summary>
string ThreadId { get; }

/// <summary>
/// 获取此主题评论回复所属的主题评论的 ID。
/// </summary>
string PostId { get; }

/// <summary>
/// 获取此主题的原始内容。
/// </summary>
string RawContent { get; }

/// <summary>
/// 获取此主题评论回复的富文本内容。
/// </summary>
RichText Content { get; }

/// <summary>
/// 获取此主题评论回复的创建时间。
/// </summary>
DateTimeOffset CreatedAt { get; }
}
2 changes: 1 addition & 1 deletion src/QQBot.Net.Core/Entities/Threads/IThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IThread : IEntity<string>, IUpdateable, IDeletable
IGuild Guild { get; }

/// <summary>
/// 获取次主题所属的论坛子频道
/// 获取此主题所属的论坛子频道
/// </summary>
IForumChannel Channel { get; }

Expand Down
18 changes: 18 additions & 0 deletions src/QQBot.Net.Rest/API/Common/PostInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace QQBot.API;

internal class PostInfo
{
[JsonPropertyName("thread_id")]
public required string ThreadId { get; init; }

[JsonPropertyName("post_id")]
public required string PostId { get; init; }

[JsonPropertyName("content")]
public required string Content { get; init; }

[JsonPropertyName("date_time")]
public required DateTimeOffset DateTime { get; init; }
}
21 changes: 21 additions & 0 deletions src/QQBot.Net.Rest/API/Common/ReplyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;

namespace QQBot.API;

internal class ReplyInfo
{
[JsonPropertyName("thread_id")]
public required string ThreadId { get; init; }

[JsonPropertyName("post_id")]
public required string PostId { get; init; }

[JsonPropertyName("reply_id")]
public required string ReplyId { get; init; }

[JsonPropertyName("content")]
public required string Content { get; init; }

[JsonPropertyName("date_time")]
public required DateTimeOffset DateTime { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ internal class AudioOrLiveChannelMemberEvent

[JsonPropertyName("user_id")]
public required ulong UserId { get; init; }
}
}
8 changes: 8 additions & 0 deletions src/QQBot.Net.WebSocket/API/Gateway/AuditType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace QQBot.API.Gateway;

internal enum AuditType
{
Thread = 1,
Post = 2,
Reply = 3
}
18 changes: 18 additions & 0 deletions src/QQBot.Net.WebSocket/API/Gateway/ForumPostEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace QQBot.API.Gateway;

internal class ForumPostEvent
{
[JsonPropertyName("guild_id")]
public required ulong GuildId { get; init; }

[JsonPropertyName("channel_id")]
public required ulong ChannelId { get; init; }

[JsonPropertyName("author_id")]
public required ulong AuthorId { get; init; }

[JsonPropertyName("post_info")]
public required PostInfo PostInfo { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Text.Json.Serialization;
using QQBot.Net.Converters;

namespace QQBot.API.Gateway;

internal class ForumPublishAuditResultEvent
{
[JsonPropertyName("guild_id")]
public required ulong GuildId { get; init; }

[JsonPropertyName("channel_id")]
public required ulong ChannelId { get; init; }

[JsonPropertyName("author_id")]
public required ulong AuthorId { get; init; }

[JsonPropertyName("thread_id")]
public required string? ThreadId { get; init; }

[JsonPropertyName("post_id")]
public required string? PostId { get; init; }

[JsonPropertyName("reply_id")]
public required string? ReplyId { get; init; }

[JsonPropertyName("type")]
public AuditType AuditType { get; init; }

[JsonPropertyName("result")]
[NumberBooleanConverter]
public bool Failed { get; init; }

[JsonPropertyName("err_msg")]
public string? ErrorMessage { get; init; }
}
18 changes: 18 additions & 0 deletions src/QQBot.Net.WebSocket/API/Gateway/ForumReplyEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace QQBot.API.Gateway;

internal class ForumReplyEvent
{
[JsonPropertyName("guild_id")]
public required ulong GuildId { get; init; }

[JsonPropertyName("channel_id")]
public required ulong ChannelId { get; init; }

[JsonPropertyName("author_id")]
public required ulong AuthorId { get; init; }

[JsonPropertyName("reply_info")]
public required ReplyInfo ReplyInfo { get; set; }
}
18 changes: 18 additions & 0 deletions src/QQBot.Net.WebSocket/API/Gateway/ForumThreadEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace QQBot.API.Gateway;

internal class ForumThreadEvent
{
[JsonPropertyName("guild_id")]
public required ulong GuildId { get; init; }

[JsonPropertyName("channel_id")]
public required ulong ChannelId { get; init; }

[JsonPropertyName("author_id")]
public required ulong AuthorId { get; init; }

[JsonPropertyName("thread_info")]
public required ThreadInfo ThreadInfo { get; set; }
}
15 changes: 15 additions & 0 deletions src/QQBot.Net.WebSocket/API/Gateway/GroupBotEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;

namespace QQBot.API.Gateway;

internal class GroupBotEvent
{
[JsonPropertyName("group_openid")]
public required Guid GroupOpenid { get; init; }

[JsonPropertyName("op_member_openid")]
public required string OpMemberOpenId { get; init; }

[JsonPropertyName("timestamp")]
public required int Timestamp { get; init; }
}
12 changes: 12 additions & 0 deletions src/QQBot.Net.WebSocket/API/Gateway/UserBotEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace QQBot.API.Gateway;

internal class UserBotEvent
{
[JsonPropertyName("openid")]
public required Guid OpenId { get; init; }

[JsonPropertyName("timestamp")]
public required int Timestamp { get; init; }
}
12 changes: 6 additions & 6 deletions src/QQBot.Net.WebSocket/Entities/Channels/SocketUserChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public class SocketUserChannel : SocketChannel, IUserChannel, ISocketPrivateChan
public new Guid Id { get; }

/// <inheritdoc cref="QQBot.IDMChannel.Recipient" />
public SocketUser Recipient { get; }
public SocketUser? Recipient { get; }

/// <inheritdoc />
public IReadOnlyCollection<SocketMessage> CachedMessages => [];

/// <inheritdoc />
internal SocketUserChannel(QQBotSocketClient client, Guid id, SocketUser recipient)
internal SocketUserChannel(QQBotSocketClient client, Guid id, SocketUser? recipient)
: base(client, id.ToIdString())
{
Id = id;
Recipient = recipient;
}

internal static SocketUserChannel Create(QQBotSocketClient client, ClientState state, Guid id, SocketUser recipient)
internal static SocketUserChannel Create(QQBotSocketClient client, ClientState state, Guid id, SocketUser? recipient)
{
SocketUserChannel channel = new(client, id, recipient);
return channel;
Expand All @@ -51,7 +51,7 @@ public Task<IUserMessage> SendMessageAsync(string? content = null, IMarkdown? ma
/// <inheritdoc />
protected override SocketUser? GetUserInternal(string id)
{
if (id == Recipient.Id) return Recipient;
if (id == Recipient?.Id) return Recipient;
return id == Client.CurrentUser?.Id.ToIdString() ? Client.CurrentUser : null;
}

Expand All @@ -60,14 +60,14 @@ public Task<IUserMessage> SendMessageAsync(string? content = null, IMarkdown? ma
#region ISocketPrivateChannel

/// <inheritdoc />
IReadOnlyCollection<SocketUser> ISocketPrivateChannel.Recipients => [Recipient];
IReadOnlyCollection<SocketUser> ISocketPrivateChannel.Recipients => Recipient is not null ? [Recipient] : [];

#endregion

#region IPrivateChannel

/// <inheritdoc />
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => [Recipient];
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => Recipient is not null ? [Recipient] : [];

#endregion

Expand Down
Loading

0 comments on commit a4fe52b

Please sign in to comment.