From e8e3ed55af02d1d22989787b88e185775b36d7db Mon Sep 17 00:00:00 2001 From: chr_ Date: Sat, 10 Jun 2023 02:16:08 +0800 Subject: [PATCH] update --- Directory.Build.props | 2 +- XinjingdailyBot.Command/NormalCommand.cs | 2 +- XinjingdailyBot.Command/PostCommand.cs | 6 +- .../Localization/Langs.Designer.cs | 8 +- .../Localization/Langs.resx | 8 +- .../Data/IChannelOptionService.cs | 9 + .../Helper/IMarkupHelperService.cs | 2 +- XinjingdailyBot.Model/Models/NewPosts.cs | 2 +- .../Bot/Common/ChannelService.cs | 1 + .../Data/ChannelOptionService.cs | 31 ++ XinjingdailyBot.Service/Data/PostService.cs | 68 ++-- XinjingdailyBot.Service/Data/UserService.cs | 3 +- XinjingdailyBot.Tasks/PlanedPostsTask.cs | 187 ++++++----- .../IPC/Controllers/PostController.cs | 303 +++++++++++++++++- .../ApiAuthenticationMiddleware.cs | 51 ++- .../IPC/Requests/CreatePostRequest.cs | 18 +- .../IPC/Responses/TestTokenResponse.cs | 3 + XinjingdailyBot.WebAPI/nlog.config | 2 +- 18 files changed, 537 insertions(+), 169 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 71ce6045..5cf67cae 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.1.2.0 + 2.1.2.1 diff --git a/XinjingdailyBot.Command/NormalCommand.cs b/XinjingdailyBot.Command/NormalCommand.cs index edc79c10..47d2c718 100644 --- a/XinjingdailyBot.Command/NormalCommand.cs +++ b/XinjingdailyBot.Command/NormalCommand.cs @@ -388,7 +388,7 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri MessageType.Video => _botClient.SendVideoAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard, hasSpoiler: hasSpoiler), MessageType.Voice => _botClient.SendVoiceAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard), MessageType.Document => _botClient.SendDocumentAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard), - MessageType.Animation => _botClient.SendDocumentAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard), + MessageType.Animation => _botClient.SendAnimationAsync(chat, new InputFileId(attachment.FileID), caption: randomPost.Text, parseMode: ParseMode.Html, replyMarkup: keyboard), _ => null, }; diff --git a/XinjingdailyBot.Command/PostCommand.cs b/XinjingdailyBot.Command/PostCommand.cs index e11316c5..f191afad 100644 --- a/XinjingdailyBot.Command/PostCommand.cs +++ b/XinjingdailyBot.Command/PostCommand.cs @@ -180,10 +180,10 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query) Caption = i == attachments.Count - 1 ? post.Text : null, ParseMode = ParseMode.Html }, - _ => throw new Exception(), + _ => throw new Exception("未知的稿件类型"), }; } - var messages = await _botClient.SendMediaGroupAsync(_channelService.ReviewGroup.Id, group); + var messages = await _botClient.SendMediaGroupAsync(_channelService.ReviewGroup, group); reviewMsg = messages.First(); post.ReviewMediaGroupID = reviewMsg.MediaGroupId ?? ""; @@ -196,7 +196,7 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query) bool? hasSpoiler = post.CanSpoiler ? post.HasSpoiler : null; var keyboard = _markupHelperService.ReviewKeyboardA(post.Tags, hasSpoiler); - var manageMsg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, msg, parseMode: ParseMode.Html, disableWebPagePreview: true, replyToMessageId: reviewMsg.MessageId, replyMarkup: keyboard, allowSendingWithoutReply: true); + var manageMsg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup, msg, parseMode: ParseMode.Html, disableWebPagePreview: true, replyToMessageId: reviewMsg.MessageId, replyMarkup: keyboard, allowSendingWithoutReply: true); post.ReviewChatID = reviewMsg.Chat.Id; post.ReviewMsgID = reviewMsg.MessageId; diff --git a/XinjingdailyBot.Infrastructure/Localization/Langs.Designer.cs b/XinjingdailyBot.Infrastructure/Localization/Langs.Designer.cs index c88d8d51..785d1751 100644 --- a/XinjingdailyBot.Infrastructure/Localization/Langs.Designer.cs +++ b/XinjingdailyBot.Infrastructure/Localization/Langs.Designer.cs @@ -61,7 +61,7 @@ internal Langs() { } /// - /// 查找类似 🤔保留来源 的本地化字符串。 + /// 查找类似 当前:🤔保留来源 的本地化字符串。 /// public static string AnymouseOff { get { @@ -70,7 +70,7 @@ public static string AnymouseOff { } /// - /// 查找类似 👻匿名投稿 的本地化字符串。 + /// 查找类似 当前:👻匿名投稿 的本地化字符串。 /// public static string AnymouseOn { get { @@ -331,7 +331,7 @@ public static string TagNSFWOn { } /// - /// 查找类似 🖼️禁用遮罩 的本地化字符串。 + /// 查找类似 当前:🖼️禁用遮罩 的本地化字符串。 /// public static string TagSpoilerOff { get { @@ -340,7 +340,7 @@ public static string TagSpoilerOff { } /// - /// 查找类似 ⚠️开启遮罩 的本地化字符串。 + /// 查找类似 当前:⚠️开启遮罩 的本地化字符串。 /// public static string TagSpoilerOn { get { diff --git a/XinjingdailyBot.Infrastructure/Localization/Langs.resx b/XinjingdailyBot.Infrastructure/Localization/Langs.resx index e83cc849..545f81e3 100644 --- a/XinjingdailyBot.Infrastructure/Localization/Langs.resx +++ b/XinjingdailyBot.Infrastructure/Localization/Langs.resx @@ -187,7 +187,7 @@ #AI怪图 - ⚠️开启遮罩 + 当前:⚠️开启遮罩 #N___ @@ -202,7 +202,7 @@ #A___ - 🖼️禁用遮罩 + 当前:🖼️禁用遮罩 ❌拒绝 @@ -211,10 +211,10 @@ ✅采用 - 👻匿名投稿 + 当前:👻匿名投稿 - 🤔保留来源 + 当前:🤔保留来源 ❌取消 diff --git a/XinjingdailyBot.Interface/Data/IChannelOptionService.cs b/XinjingdailyBot.Interface/Data/IChannelOptionService.cs index 6a0304b3..483683ef 100644 --- a/XinjingdailyBot.Interface/Data/IChannelOptionService.cs +++ b/XinjingdailyBot.Interface/Data/IChannelOptionService.cs @@ -36,6 +36,15 @@ public interface IChannelOptionService : IBaseService /// /// Task FetchChannelOption(Chat channelChat); + /// + /// 获取频道设定 + /// + /// + /// + /// + /// + Task FetchChannelOption(long chatId, string chatTitle, string chatUserName); + /// /// 更新频道设定 /// diff --git a/XinjingdailyBot.Interface/Helper/IMarkupHelperService.cs b/XinjingdailyBot.Interface/Helper/IMarkupHelperService.cs index 94559b12..8b3ef3dc 100644 --- a/XinjingdailyBot.Interface/Helper/IMarkupHelperService.cs +++ b/XinjingdailyBot.Interface/Helper/IMarkupHelperService.cs @@ -11,7 +11,7 @@ public interface IMarkupHelperService /// /// 一行显示的字数 /// - public static readonly int MaxLineCharsTag = 8; + public static readonly int MaxLineCharsTag = 10; /// /// 一行显示的字数 /// diff --git a/XinjingdailyBot.Model/Models/NewPosts.cs b/XinjingdailyBot.Model/Models/NewPosts.cs index dea86e7d..304a57a0 100644 --- a/XinjingdailyBot.Model/Models/NewPosts.cs +++ b/XinjingdailyBot.Model/Models/NewPosts.cs @@ -148,7 +148,7 @@ public sealed record NewPosts : BaseModel, IModifyAt, ICreateAt /// 是否允许遮罩 /// [SugarColumn(IsIgnore = true)] - public bool CanSpoiler => PostType == MessageType.Photo || PostType == MessageType.Video; + public bool CanSpoiler => PostType == MessageType.Photo || PostType == MessageType.Video || PostType == MessageType.Animation; /// /// 拒绝原因(如果拒绝) diff --git a/XinjingdailyBot.Service/Bot/Common/ChannelService.cs b/XinjingdailyBot.Service/Bot/Common/ChannelService.cs index f0ac5794..b2073d65 100644 --- a/XinjingdailyBot.Service/Bot/Common/ChannelService.cs +++ b/XinjingdailyBot.Service/Bot/Common/ChannelService.cs @@ -88,6 +88,7 @@ public async Task InitChannelInfo() catch { _logger.LogError("未找到指定的审核群组, 可以使用 /groupinfo 命令获取群组信息"); + _reviewGroup = new Chat { Id = -1 }; } if (channelOption.UseReviewLogMode) diff --git a/XinjingdailyBot.Service/Data/ChannelOptionService.cs b/XinjingdailyBot.Service/Data/ChannelOptionService.cs index 14d4e394..45f2b88e 100644 --- a/XinjingdailyBot.Service/Data/ChannelOptionService.cs +++ b/XinjingdailyBot.Service/Data/ChannelOptionService.cs @@ -46,6 +46,37 @@ public async Task FetchChannelOption(Chat channelChat) return channel.Option; } + public async Task FetchChannelOption(long chatId,string chatTitle,string chatUserName) + { + var channel = await Queryable().Where(x => x.ChannelID == chatId).FirstAsync(); + if (channel == null) + { + channel = new ChannelOptions { + ChannelID = chatId, + ChannelName = chatUserName ?? "", + ChannelTitle = chatTitle ?? "", + Option = EChannelOption.Normal, + Count = 1, + CreateAt = DateTime.Now, + ModifyAt = DateTime.Now, + }; + await Insertable(channel).ExecuteCommandAsync(); + } + else + { + if (channel.ChannelName != chatUserName || channel.ChannelTitle != chatTitle) + { + channel.ChannelTitle = chatTitle ?? ""; + channel.ChannelName = chatUserName ?? ""; + channel.ModifyAt = DateTime.Now; + } + channel.Count++; + await Updateable(channel).ExecuteCommandAsync(); + } + + return channel.Option; + } + public async Task FetchChannelByTitle(string channelTitle) { var channel = await Queryable().Where(x => x.ChannelTitle == channelTitle).FirstAsync(); diff --git a/XinjingdailyBot.Service/Data/PostService.cs b/XinjingdailyBot.Service/Data/PostService.cs index d9a3a61f..8277c164 100644 --- a/XinjingdailyBot.Service/Data/PostService.cs +++ b/XinjingdailyBot.Service/Data/PostService.cs @@ -450,6 +450,7 @@ public async Task HandleMediaGroupPosts(Users dbUser, Message message) newPost.ReviewMsgID = newPost.OriginMsgID; newPost.ReviewActionChatID = newPost.OriginActionChatID; newPost.ReviewActionMsgID = newPost.OriginActionMsgID; + newPost.ReviewMediaGroupID = mediaGroupId; } postID = await Insertable(newPost).ExecuteReturnIdentityAsync(); @@ -466,15 +467,17 @@ public async Task HandleMediaGroupPosts(Users dbUser, Message message) } } - //更新附件 if (postID > 0) { + //更新附件 var attachment = _attachmentService.GenerateAttachment(message, postID); - if (attachment != null) { await _attachmentService.Insertable(attachment).ExecuteCommandAsync(); } + + //记录媒体组 + await _mediaGroupService.AddPostMediaGroup(message); } } @@ -548,13 +551,14 @@ public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectRea { var attachment = await _attachmentService.Queryable().Where(x => x.PostID == post.Id).FirstAsync(); + var inputFile = new InputFileId(attachment.FileID); var handler = post.PostType switch { - MessageType.Photo => _botClient.SendPhotoAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)), - MessageType.Audio => _botClient.SendAudioAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)), - MessageType.Video => _botClient.SendVideoAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)), - MessageType.Voice => _botClient.SendVoiceAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)), - MessageType.Document => _botClient.SendDocumentAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)), - MessageType.Animation => _botClient.SendAnimationAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)), + MessageType.Photo => _botClient.SendPhotoAsync(_channelService.RejectChannel.Id, inputFile), + MessageType.Audio => _botClient.SendAudioAsync(_channelService.RejectChannel.Id, inputFile), + MessageType.Video => _botClient.SendVideoAsync(_channelService.RejectChannel.Id, inputFile), + MessageType.Voice => _botClient.SendVoiceAsync(_channelService.RejectChannel.Id, inputFile), + MessageType.Document => _botClient.SendDocumentAsync(_channelService.RejectChannel.Id, inputFile), + MessageType.Animation => _botClient.SendAnimationAsync(_channelService.RejectChannel.Id, inputFile), _ => throw new Exception("未知的稿件类型"), }; @@ -575,16 +579,17 @@ public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectRea { attachmentType = post.PostType; } + var inputFile = new InputFileId(attachments[i].FileID); group[i] = attachmentType switch { - MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)), - MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)), - MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)), - MessageType.Voice => new InputMediaAudio(new InputFileId(attachments[i].FileID)), - MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)), + MessageType.Photo => new InputMediaPhoto(inputFile), + MessageType.Audio => new InputMediaAudio(inputFile), + MessageType.Video => new InputMediaVideo(inputFile), + MessageType.Voice => new InputMediaAudio(inputFile), + MessageType.Document => new InputMediaDocument(inputFile), _ => throw new Exception("未知的稿件类型"), }; } - var postMessages = await _botClient.SendMediaGroupAsync(_channelService.RejectChannel.Id, group); + var postMessages = await _botClient.SendMediaGroupAsync(_channelService.RejectChannel, group); var postMessage = postMessages.FirstOrDefault(); if (postMessage != null) @@ -631,11 +636,6 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ { var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID); - if (post.IsDirectPost) - { - poster.PostCount++; - } - ChannelOptions? channel = null; if (post.IsFromChannel) { @@ -665,13 +665,14 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ { var attachment = await _attachmentService.Queryable().FirstAsync(x => x.PostID == post.Id); + var inputFile = new InputFileId(attachment.FileID); var handler = post.PostType switch { - MessageType.Photo => _botClient.SendPhotoAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), - MessageType.Audio => _botClient.SendAudioAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, title: attachment.FileName), - MessageType.Video => _botClient.SendVideoAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), - MessageType.Voice => _botClient.SendVoiceAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html), - MessageType.Document => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html), - MessageType.Animation => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html), + MessageType.Photo => _botClient.SendPhotoAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), + MessageType.Audio => _botClient.SendAudioAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, title: attachment.FileName), + MessageType.Video => _botClient.SendVideoAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), + MessageType.Voice => _botClient.SendVoiceAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html), + MessageType.Document => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html), + MessageType.Animation => _botClient.SendAnimationAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), _ => null, }; @@ -696,13 +697,15 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ { attachmentType = post.PostType; } + + var inputFile = new InputFileId(attachments[i].FileID); group[i] = attachmentType switch { - MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler }, - MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, - MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler }, - MessageType.Voice => new InputMediaVideo(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, - MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)) { Caption = i == attachments.Count - 1 ? postText : null, ParseMode = ParseMode.Html }, - _ => throw new Exception(), + MessageType.Photo => new InputMediaPhoto(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler }, + MessageType.Audio => new InputMediaAudio(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, + MessageType.Video => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler }, + MessageType.Voice => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, + MessageType.Document => new InputMediaDocument(inputFile) { Caption = i == attachments.Count - 1 ? postText : null, ParseMode = ParseMode.Html }, + _ => throw new Exception("未知的稿件类型"), }; } @@ -738,7 +741,7 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ string reviewMsg = _textHelperService.MakeReviewMessage(poster, dbUser, post.Anonymous); await _botClient.EditMessageTextAsync(callbackQuery.Message!, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true); } - else //直接投稿, 在审核群留档 + else // 直接投稿, 在审核群留档 { string reviewMsg = _textHelperService.MakeReviewMessage(poster, post.PublicMsgID, post.Anonymous); var msg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true); @@ -756,7 +759,6 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQ //通知投稿人 string posterMsg = _textHelperService.MakeNotification(post.IsDirectPost, inPlan, post.PublicMsgID); - if (poster.Notification && poster.UserID != dbUser.UserID)//启用通知并且审核与投稿不是同一个人 { //单独发送通知消息 diff --git a/XinjingdailyBot.Service/Data/UserService.cs b/XinjingdailyBot.Service/Data/UserService.cs index f6e3824b..cdb10762 100644 --- a/XinjingdailyBot.Service/Data/UserService.cs +++ b/XinjingdailyBot.Service/Data/UserService.cs @@ -294,8 +294,7 @@ private async Task AutoLeaveChat(Chat? msgChat) //如果是配置文件中指定的管理员就覆盖用户组权限 if (_optionsSetting.Bot.SuperAdmins?.Contains(dbUser.UserID) ?? false) { - var maxGroupID = _groupRepository.GetMaxGroupId(); - dbUser.GroupID = maxGroupID; + dbUser.GroupID = _groupRepository.GetMaxGroupId(); } //根据GroupID设置用户权限信息 (封禁用户区别对待) diff --git a/XinjingdailyBot.Tasks/PlanedPostsTask.cs b/XinjingdailyBot.Tasks/PlanedPostsTask.cs index 262c3271..efbc0753 100644 --- a/XinjingdailyBot.Tasks/PlanedPostsTask.cs +++ b/XinjingdailyBot.Tasks/PlanedPostsTask.cs @@ -1,12 +1,18 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using System.Reflection; using System.Text; using Telegram.Bot; +using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; using XinjingdailyBot.Infrastructure; using XinjingdailyBot.Infrastructure.Attribute; using XinjingdailyBot.Infrastructure.Enums; +using XinjingdailyBot.Interface.Bot.Common; using XinjingdailyBot.Interface.Data; +using XinjingdailyBot.Interface.Helper; +using XinjingdailyBot.Model.Models; +using XinjingdailyBot.Repository; namespace XinjingdailyBot.Tasks; @@ -20,126 +26,153 @@ internal class PlanedPostsTask : IJob private readonly IPostService _postService; private readonly IUserService _userService; private readonly ITelegramBotClient _botClient; + private readonly TagRepository _tagRepository; + private readonly IAttachmentService _attachmentService; + private readonly IChannelService _channelService; + private readonly IChannelOptionService _channelOptionService; + private readonly ITextHelperService _textHelperService; + private readonly IMediaGroupService _mediaGroupService; public PlanedPostsTask( ILogger logger, IPostService postService, IUserService userService, ITelegramBotClient botClient, - IOptions options) + TagRepository tagRepository, + IAttachmentService attachmentService, + IChannelService channelService, + IChannelOptionService channelOptionService, + ITextHelperService textHelperService, + IMediaGroupService mediaGroupService) { _logger = logger; _postService = postService; _userService = userService; _botClient = botClient; - PostExpiredTime = TimeSpan.FromDays(options.Value.Post.PostExpiredTime); + _tagRepository = tagRepository; + _attachmentService = attachmentService; + _channelService = channelService; + _channelOptionService = channelOptionService; + _textHelperService = textHelperService; + _mediaGroupService = mediaGroupService; } - /// - /// 稿件过期时间 - /// - private TimeSpan PostExpiredTime { get; init; } - public async Task Execute(IJobExecutionContext context) { - _logger.LogInformation("开始定时任务, 清理过期稿件任务"); - - var expiredDate = DateTime.Now - PostExpiredTime; + _logger.LogInformation("开始定时任务, 发布定时任务"); - //获取有过期稿件的用户 - var userIDList = await _postService.Queryable() - .Where(x => (x.Status == EPostStatus.Padding || x.Status == EPostStatus.Reviewing) && x.ModifyAt < expiredDate) - .Distinct().Select(x => x.PosterUID).ToListAsync(); + var post = await _postService.Queryable() + .Where(static x => x.Status == EPostStatus.InPlan).FirstAsync(); - if (!userIDList.Any()) + if (post == null) { - _logger.LogInformation("结束定时任务, 没有需要清理的过期稿件"); + _logger.LogInformation("无延时发布稿件"); return; } - _logger.LogInformation("成功获取 {Count} 个有过期稿件的用户", userIDList.Count); + var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID); + if (post.IsDirectPost) + { + poster.PostCount++; + } - foreach (var userID in userIDList) + ChannelOptions? channel = null; + if (post.IsFromChannel) { - //获取过期投稿 - var paddingPosts = await _postService.Queryable() - .Where(x => x.PosterUID == userID && (x.Status == EPostStatus.Padding || x.Status == EPostStatus.Reviewing) && x.ModifyAt < expiredDate) - .ToListAsync(); + channel = await _channelOptionService.FetchChannelByChannelId(post.ChannelID); + } + string postText = _textHelperService.MakePostText(post, poster, channel); + bool hasSpoiler = post.HasSpoiler; - if (!paddingPosts.Any()) + try + { + //发布频道发布消息 + if (!post.IsMediaGroup) { - continue; - } + string? warnText = _tagRepository.GetActivedTagWarnings(post.Tags); + if (!string.IsNullOrEmpty(warnText)) + { + await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, warnText, allowSendingWithoutReply: true); + } - int cTmout = 0, rTmout = 0; - foreach (var post in paddingPosts) - { - if (post.Status == EPostStatus.Padding) + Message? postMessage = null; + if (post.PostType == MessageType.Text) { - post.Status = EPostStatus.ConfirmTimeout; - cTmout++; + postMessage = await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, postText, parseMode: ParseMode.Html, disableWebPagePreview: true); } else { - post.Status = EPostStatus.ReviewTimeout; - rTmout++; - } - post.ModifyAt = DateTime.Now; - - await _postService.Updateable(post).UpdateColumns(static x => new { x.Status, x.ModifyAt }).ExecuteCommandAsync(); - } - - var user = await _userService.Queryable().FirstAsync(x => x.UserID == userID); + var attachment = await _attachmentService.Queryable().FirstAsync(x => x.PostID == post.Id); + + var inputFile = new InputFileId(attachment.FileID); + var handler = post.PostType switch { + MessageType.Photo => _botClient.SendPhotoAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), + MessageType.Audio => _botClient.SendAudioAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, title: attachment.FileName), + MessageType.Video => _botClient.SendVideoAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), + MessageType.Voice => _botClient.SendVoiceAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html), + MessageType.Document => _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html), + MessageType.Animation => _botClient.SendAnimationAsync(_channelService.AcceptChannel.Id, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler), + _ => null, + }; + + if (handler == null) + { + _logger.LogError("不支持的稿件类型: {postType}", post.PostType); + return; + } - if (user == null) - { - _logger.LogInformation("清理了 {userID} 的 {cTmout} / {rTmout} 条确认/审核超时投稿", userID, cTmout, rTmout); + postMessage = await handler; + } + post.PublicMsgID = postMessage?.MessageId ?? -1; } else { - _logger.LogInformation("清理了 {user} 的 {cTmout} / {rTmout} 条确认/审核超时投稿", user.ToString(), cTmout, rTmout); - - //满足条件则通知投稿人 - //1.未封禁 - //2.有PrivateChatID - //3.启用通知 - if (!user.IsBan && user.PrivateChatID > 0 && user.Notification) + var attachments = await _attachmentService.Queryable().Where(x => x.PostID == post.Id).ToListAsync(); + var group = new IAlbumInputMedia[attachments.Count]; + for (int i = 0; i < attachments.Count; i++) { - var sb = new StringBuilder(); - - if (cTmout > 0) + var attachmentType = attachments[i].Type; + if (attachmentType == MessageType.Unknown) { - sb.AppendLine($"你有 {cTmout} 份稿件因为确认超时被清理"); + attachmentType = post.PostType; } - if (rTmout > 0) - { - sb.AppendLine($"你有 {rTmout} 份稿件因为审核超时被清理"); - } + var inputFile = new InputFileId(attachments[i].FileID); + group[i] = attachmentType switch { + MessageType.Photo => new InputMediaPhoto(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler }, + MessageType.Audio => new InputMediaAudio(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, + MessageType.Video => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = hasSpoiler }, + MessageType.Voice => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, + MessageType.Document => new InputMediaDocument(inputFile) { Caption = i == attachments.Count - 1 ? postText : null, ParseMode = ParseMode.Html }, + _ => throw new Exception("未知的稿件类型"), + }; + } - try - { - await _botClient.SendTextMessageAsync(user.PrivateChatID, sb.ToString(), parseMode: ParseMode.Html, disableNotification: true); - await Task.Delay(500); - } - catch (Exception ex) - { - _logger.LogError(ex, "通知消息发送失败, 自动禁用更新"); - user.PrivateChatID = -1; - await Task.Delay(5000); - } + string? warnText = _tagRepository.GetActivedTagWarnings(post.Tags); + if (!string.IsNullOrEmpty(warnText)) + { + await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, warnText, allowSendingWithoutReply: true); } - user.ExpiredPostCount += rTmout; - user.ModifyAt = DateTime.Now; + var postMessages = await _botClient.SendMediaGroupAsync(_channelService.AcceptChannel.Id, group); + post.PublicMsgID = postMessages.First().MessageId; + post.PublishMediaGroupID = postMessages.First().MediaGroupId ?? ""; - //更新用户表 - await _userService.Updateable(user).UpdateColumns(static x => new { - x.PrivateChatID, - x.ExpiredPostCount, - x.ModifyAt - }).ExecuteCommandAsync(); + //记录媒体组消息 + await _mediaGroupService.AddPostMediaGroup(postMessages); } } + finally + { + post.Status = EPostStatus.Accepted; + post.ModifyAt = DateTime.Now; + + await _postService.Updateable(post).UpdateColumns(static x => new { + x.PublicMsgID, + x.PublishMediaGroupID, + x.Status, + x.ModifyAt + }).ExecuteCommandAsync(); + } } } diff --git a/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs b/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs index 144516c7..9d4f7f3b 100644 --- a/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs +++ b/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs @@ -1,7 +1,20 @@ using Microsoft.AspNetCore.Mvc; +using System.Net; +using System.Net.Mail; +using System.Threading.Channels; +using Telegram.Bot; +using Telegram.Bot.Types; +using Telegram.Bot.Types.Enums; +using XinjingdailyBot.Infrastructure.Enums; using XinjingdailyBot.Infrastructure.Extensions; +using XinjingdailyBot.Interface.Bot.Common; +using XinjingdailyBot.Interface.Data; +using XinjingdailyBot.Interface.Helper; +using XinjingdailyBot.Model.Models; +using XinjingdailyBot.Repository; using XinjingdailyBot.WebAPI.IPC.Requests; using XinjingdailyBot.WebAPI.IPC.Responses; +using static System.Net.Mime.MediaTypeNames; namespace XinjingdailyBot.WebAPI.IPC.Controllers; @@ -13,38 +26,79 @@ public sealed class PostController : XjbController { private readonly ILogger _logger; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IPostService _postService; + private readonly IChannelOptionService _channelOptionService; + private readonly IUserService _userService; + private readonly ITelegramBotClient _botClient; + private readonly IChannelService _channelService; + private readonly IMarkupHelperService _markupHelperService; + private readonly ITextHelperService _textHelperService; + private readonly IAttachmentService _attachmentService; + private readonly TagRepository _tagRepository; + private readonly IMediaGroupService _mediaGroupService; /// /// 构造函数 /// /// /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// public PostController( ILogger logger, - IHttpContextAccessor httpContextAccessor) + IHttpContextAccessor httpContextAccessor, + IPostService postService, + IChannelOptionService channelOptionService, + IUserService userService, + ITelegramBotClient botClient, + IChannelService channelService, + IMarkupHelperService markupHelperService, + ITextHelperService textHelperService, + IAttachmentService attachmentService, + TagRepository tagRepository, + IMediaGroupService mediaGroupService) { _logger = logger; _httpContextAccessor = httpContextAccessor; + _postService = postService; + _channelOptionService = channelOptionService; + _userService = userService; + _botClient = botClient; + _channelService = channelService; + _markupHelperService = markupHelperService; + _textHelperService = textHelperService; + _attachmentService = attachmentService; + _tagRepository = tagRepository; + _mediaGroupService = mediaGroupService; } /// /// 连接测试 /// /// - [HttpGet("[action]")] [HttpPost("[action]")] public ActionResult> TestToken() { - var user = _httpContextAccessor.GetUser(); + var dbUser = _httpContextAccessor.GetUser(); var response = new GenericResponse { Code = 0, Message = "成功", Result = new TestTokenResponse { - UID = user.Id, - UserID = user.UserID, - UserName = user.UserName, - NickName = user.FullName, + UID = dbUser.Id, + UserID = dbUser.UserID, + UserName = dbUser.UserName, + NickName = dbUser.FullName, + UserRight = dbUser.Right, + GroupId = dbUser.GroupID, } }; @@ -57,23 +111,238 @@ public ActionResult> TestToken() /// /// [HttpPost("[action]")] - public async Task>> CreatePost([FromForm] CreatePostRequest post) + public async Task>> CreatePost([FromForm] CreatePostRequest post) { - var user = _httpContextAccessor.GetUser(); + var dbUser = _httpContextAccessor.GetUser(); + if (!dbUser.Right.HasFlag(EUserRights.DirectPost)) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.Forbidden, + Message = "当前用户没有直接发布权限, 无法通过 IPC 投稿", + }); + } - await Task.Delay(200); + var userChatId = dbUser.PrivateChatID; + if (userChatId == -1) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.InternalServerError, + Message = "当前用户没有私聊过机器人, 无法接受投稿", + }); + } - _logger.LogInformation("{post}", post); + var reviewGroup = _channelService.ReviewGroup; + if (reviewGroup.Id == -1) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.InternalServerError, + Message = "未设置审核群组, 无法接受投稿", + }); + } - var response = new GenericResponse { - Code = 0, - Message = "成功", - Result = new CreatePostResponse { - PostType = post.PostType, - MediaCount = post.Media?.Count ?? 0 + var mediaCount = post.Media?.Count ?? 0; + bool hasMedia = post.Media != null; + switch (post.PostType) + { + case MessageType.Text: + case MessageType.Photo: + case MessageType.Audio: + case MessageType.Video: + case MessageType.Voice: + case MessageType.Document: + break; + case MessageType.Animation: + if (mediaCount > 1) + { + mediaCount = 1; + } + break; + default: + return BadRequest(new GenericResponse { + Code = HttpStatusCode.BadRequest, + Message = "不支持的稿件类型" + }); + } + + bool fromChannel; + if (!string.IsNullOrEmpty(post.ChannelName) && !string.IsNullOrEmpty(post.ChannelTitle) && post.ChannelID != 0 && post.ChannelMsgID != 0) + { + // 如果消息来自频道就更新频道信息 + var option = await _channelOptionService.FetchChannelOption(post.ChannelID, post.ChannelTitle, post.ChannelName); + if (option == EChannelOption.AutoReject) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.Forbidden, + Message = "当前频道禁止投稿", + }); } + + fromChannel = option == EChannelOption.Normal; + } + else + { + fromChannel = false; + } + + var postText = _textHelperService.PureText(post.Text); + int newTags = _tagRepository.FetchTags(post.Text); + + var newPost = new NewPosts { + OriginChatID = userChatId, + OriginActionChatID = userChatId, + ReviewChatID = userChatId, + ReviewActionChatID = userChatId, + Anonymous = dbUser.PreferAnonymous, + Text = postText, + RawText = post.Text ?? "", + ChannelID = fromChannel ? post.ChannelID : -1, + ChannelMsgID = fromChannel ? post.ChannelMsgID : -1, + Status = EPostStatus.Reviewing, + PostType = post.PostType, + Tags = newTags, + HasSpoiler = post.HasSpoiler, + PosterUID = dbUser.UserID, + }; + + var newPostId = await _postService.Insertable(newPost).ExecuteReturnIdentityAsync(); + + Message? originMsg = null; + + if (post.PostType == MessageType.Text) // 纯文本消息 + { + if (string.IsNullOrEmpty(postText)) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.BadRequest, + Message = "文本类型投稿的Text字段不允许为空", + }); + } + + originMsg = await _botClient.SendTextMessageAsync(userChatId, postText, disableNotification: true, disableWebPagePreview: false); + + } + else if (post.Media != null && mediaCount == 1) // 非媒体组消息 + { + var fileStream = post.Media[0].OpenReadStream(); + var fileName = (post.MediaNames?.Any() == true && !string.IsNullOrEmpty(post.MediaNames[0])) ? post.MediaNames[0] : "Media"; + + var inputFile = new InputFileStream(fileStream, fileName); + var handler = post.PostType switch { + MessageType.Photo => _botClient.SendPhotoAsync(userChatId, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: post.HasSpoiler), + MessageType.Audio => _botClient.SendAudioAsync(userChatId, inputFile, caption: postText, parseMode: ParseMode.Html, title: fileName), + MessageType.Video => _botClient.SendVideoAsync(userChatId, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: post.HasSpoiler), + MessageType.Voice => _botClient.SendVoiceAsync(userChatId, inputFile, caption: postText, parseMode: ParseMode.Html), + MessageType.Document => _botClient.SendDocumentAsync(userChatId, inputFile, caption: postText, parseMode: ParseMode.Html), + MessageType.Animation => _botClient.SendAnimationAsync(userChatId, inputFile, caption: postText, parseMode: ParseMode.Html, hasSpoiler: post.HasSpoiler), + _ => null, + }; + + if (handler == null) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.BadRequest, + Message = "不支持的稿件类型" + }); + } + + originMsg = await handler; + + // 记录Attachment + var attachment = _attachmentService.GenerateAttachment(originMsg, newPostId); + if (attachment != null) + { + await _attachmentService.Insertable(attachment).ExecuteCommandAsync(); + } + else + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.InternalServerError, + Message = "生成附件失败" + }); + } + } + else if (post.Media != null && mediaCount > 1) // 媒体组消息 + { + post.MediaNames ??= new List(); + + for (int i = post.MediaNames.Count; i < mediaCount; i++) + { + post.MediaNames.Add($"Media {i}"); + } + + var group = new IAlbumInputMedia[mediaCount]; + for (int i = 0; i < mediaCount; i++) + { + var fileStream = post.Media[i].OpenReadStream(); + var fileName = !string.IsNullOrEmpty(post.MediaNames[i]) ? post.MediaNames[i] : "Media"; + + var inputFile = new InputFileStream(fileStream, fileName); + group[i] = post.PostType switch { + MessageType.Photo => new InputMediaPhoto(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = post.HasSpoiler }, + MessageType.Audio => new InputMediaAudio(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, + MessageType.Video => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html, HasSpoiler = post.HasSpoiler }, + MessageType.Voice => new InputMediaVideo(inputFile) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html }, + MessageType.Document => new InputMediaDocument(inputFile) { Caption = i == mediaCount - 1 ? postText : null, ParseMode = ParseMode.Html }, + _ => throw new Exception("未知的稿件类型"), + }; + } + + var messages = await _botClient.SendMediaGroupAsync(userChatId, group); + originMsg = messages.First(); + + // 记录Attachment + var attachments = messages.Select(x => _attachmentService.GenerateAttachment(x, newPostId)).ToList(); + await _attachmentService.Storageable(attachments!).ExecuteCommandAsync(); + + // 记录媒体组消息 + await _mediaGroupService.AddPostMediaGroup(messages); + + newPost.OriginMediaGroupID = originMsg.MediaGroupId ?? ""; + newPost.ReviewMediaGroupID = originMsg.MediaGroupId ?? ""; + } + + if (originMsg == null) + { + return BadRequest(new GenericResponse { + Code = HttpStatusCode.BadRequest, + Message = "非文本类型投稿的Media字段不允许为空", + }); + } + + var keyboard = _markupHelperService.ReviewKeyboardA(newTags, post.HasSpoiler); + string msg = _textHelperService.MakeReviewMessage(dbUser, newPost.Anonymous); + + var actionMsg = await _botClient.SendTextMessageAsync(userChatId, msg, parseMode: ParseMode.Html, disableWebPagePreview: true, replyToMessageId: originMsg.MessageId, replyMarkup: keyboard, allowSendingWithoutReply: true); + + newPost.Id = newPostId; + newPost.OriginMsgID = originMsg.MessageId; + newPost.ReviewMsgID = originMsg.MessageId; + newPost.OriginActionMsgID = actionMsg.MessageId; + newPost.ReviewActionMsgID = actionMsg.MessageId; + newPost.ModifyAt = DateTime.Now; + + await _postService.Updateable(newPost).UpdateColumns(static x => new { + x.ReviewMsgID, + x.OriginActionMsgID, + x.ReviewActionMsgID, + x.OriginMediaGroupID, + x.ReviewMediaGroupID, + x.ModifyAt + }).ExecuteCommandAsync(); + + dbUser.PostCount++; + dbUser.ModifyAt = DateTime.Now; + await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.PostCount, x.ModifyAt }).ExecuteCommandAsync(); + + var response = new GenericResponse { + Code = HttpStatusCode.OK, + Message = "成功", + Success = true, + Result = newPost, }; return Ok(response); } + + } diff --git a/XinjingdailyBot.WebAPI/IPC/Middlewares/ApiAuthenticationMiddleware.cs b/XinjingdailyBot.WebAPI/IPC/Middlewares/ApiAuthenticationMiddleware.cs index 6f2596ac..1e62502f 100644 --- a/XinjingdailyBot.WebAPI/IPC/Middlewares/ApiAuthenticationMiddleware.cs +++ b/XinjingdailyBot.WebAPI/IPC/Middlewares/ApiAuthenticationMiddleware.cs @@ -1,7 +1,12 @@ +using Microsoft.Extensions.Options; +using System.Configuration; using System.Net; +using Telegram.Bot.Types; +using XinjingdailyBot.Infrastructure; using XinjingdailyBot.Infrastructure.Attribute; using XinjingdailyBot.Interface.Data; using XinjingdailyBot.Model.Models; +using XinjingdailyBot.Repository; using XinjingdailyBot.WebAPI.IPC.Responses; namespace XinjingdailyBot.WebAPI.IPC.Middlewares; @@ -28,6 +33,8 @@ public sealed class ApiAuthenticationMiddleware : IMiddleware private readonly ILogger _logger; private readonly IUserService _userService; private readonly IUserTokenService _userTokenService; + private readonly GroupRepository _groupRepository; + private readonly HashSet? _superAdmins; /// /// 构造函数 @@ -35,14 +42,20 @@ public sealed class ApiAuthenticationMiddleware : IMiddleware /// /// /// + /// + /// public ApiAuthenticationMiddleware( ILogger logger, IUserService userService, - IUserTokenService userTokenService) + IUserTokenService userTokenService, + GroupRepository groupRepository, + IOptions configuration) { _logger = logger; _userService = userService; _userTokenService = userTokenService; + _groupRepository = groupRepository; + _superAdmins = configuration.Value.Bot.SuperAdmins; } /// @@ -68,17 +81,9 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next) var response = new GenericResponse { Code = HttpStatusCode.Unauthorized, Success = false, + Message = (user == null) ? "Token无效" : "用户已封禁", }; - if (user == null) - { - response.Message = "Token无效"; - } - else - { - response.Message = "用户已封禁"; - } - await context.Response.WriteAsJsonAsync(response).ConfigureAwait(false); } @@ -91,13 +96,31 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next) return null; } - var user = await _userTokenService.VerifyToken(guid); + var dbUser = await _userTokenService.VerifyToken(guid); - if (user != null && !user.IsBan) + if (dbUser != null && !dbUser.IsBan) { - context.Items.Add("Users", user); + //如果是配置文件中指定的管理员就覆盖用户组权限 + if (_superAdmins?.Contains(dbUser.UserID) ?? false) + { + dbUser.GroupID = _groupRepository.GetMaxGroupId(); + } + + //根据GroupID设置用户权限信息 (封禁用户区别对待) + var group = _groupRepository.GetGroupById(dbUser.GroupID); + + if (group != null) + { + dbUser.Right = group.DefaultRight; + context.Items.Add("Users", dbUser); + } + else + { + _logger.LogError("读取用户 {dbUser} 权限组 {GroupID} 失败", dbUser, dbUser.GroupID); + return null; + } } - return user; + return dbUser; } } diff --git a/XinjingdailyBot.WebAPI/IPC/Requests/CreatePostRequest.cs b/XinjingdailyBot.WebAPI/IPC/Requests/CreatePostRequest.cs index a85c414f..2175a1e1 100644 --- a/XinjingdailyBot.WebAPI/IPC/Requests/CreatePostRequest.cs +++ b/XinjingdailyBot.WebAPI/IPC/Requests/CreatePostRequest.cs @@ -16,15 +16,14 @@ public sealed record CreatePostRequest [DefaultValue("")] public string? Text { get; set; } /// - /// 匿名投稿 - /// - [DefaultValue(false)] - public bool Anonymous { get; set; } - /// /// 多媒体文件 /// public IFormFileCollection? Media { get; set; } /// + /// 多媒体文件名 + /// + public IList? MediaNames { get; set; } + /// /// 消息类型 /// [DefaultValue(MessageType.Unknown)] @@ -34,12 +33,11 @@ public sealed record CreatePostRequest /// [DefaultValue(false)] public bool HasSpoiler { get; set; } - /// /// 频道ID /// - [DefaultValue(-1)] - public long ChannelID { get; set; } = -1; + [DefaultValue(0)] + public long ChannelID { get; set; } = 0; /// /// 频道ID @ /// @@ -53,8 +51,8 @@ public sealed record CreatePostRequest /// /// 转发消息ID /// - [DefaultValue(-1)] - public long ChannelMsgID { get; set; } = -1; + [DefaultValue(0)] + public long ChannelMsgID { get; set; } = 0; } diff --git a/XinjingdailyBot.WebAPI/IPC/Responses/TestTokenResponse.cs b/XinjingdailyBot.WebAPI/IPC/Responses/TestTokenResponse.cs index 3dd569ee..4161d3b8 100644 --- a/XinjingdailyBot.WebAPI/IPC/Responses/TestTokenResponse.cs +++ b/XinjingdailyBot.WebAPI/IPC/Responses/TestTokenResponse.cs @@ -1,4 +1,5 @@ using Telegram.Bot.Types.Enums; +using XinjingdailyBot.Infrastructure.Enums; namespace XinjingdailyBot.WebAPI.IPC.Responses; @@ -11,4 +12,6 @@ public sealed record TestTokenResponse public long UserID { get; set; } public int UID { get; set; } public string NickName { get; set; } + public EUserRights UserRight { get; set; } + public int GroupId { get; set; } } diff --git a/XinjingdailyBot.WebAPI/nlog.config b/XinjingdailyBot.WebAPI/nlog.config index 469bc811..56fd99ce 100644 --- a/XinjingdailyBot.WebAPI/nlog.config +++ b/XinjingdailyBot.WebAPI/nlog.config @@ -87,7 +87,7 @@ - +