From cd6875119d9add825c8fce5f5e7a120e6e61ada0 Mon Sep 17 00:00:00 2001 From: Chr_ Date: Tue, 15 Aug 2023 14:31:25 +0800 Subject: [PATCH] update --- Directory.Build.props | 2 +- XinjingdailyBot.Tasks/ReviewStatusTask.cs | 96 +---------------------- 2 files changed, 2 insertions(+), 96 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index fc420310..5070a6cd 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.1.5.1 + 2.1.5.2 diff --git a/XinjingdailyBot.Tasks/ReviewStatusTask.cs b/XinjingdailyBot.Tasks/ReviewStatusTask.cs index 6fd6deee..88986527 100644 --- a/XinjingdailyBot.Tasks/ReviewStatusTask.cs +++ b/XinjingdailyBot.Tasks/ReviewStatusTask.cs @@ -15,7 +15,7 @@ namespace XinjingdailyBot.Tasks; /// /// 定期发布稿件处理 /// -[Job("0 0 0 * * ?")] +//[Job("0 0 0 * * ?")] internal class ReviewStatusTask : IJob { private readonly ILogger _logger; @@ -60,103 +60,9 @@ public async Task Execute(IJobExecutionContext context) var post = await _postService.Queryable() .Where(static x => x.Status == EPostStatus.InPlan).FirstAsync(); - if (post == null) - { - _logger.LogInformation("无延时发布稿件"); - return; - } - - var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID); - if (post.IsDirectPost) - { - poster.PostCount++; - } - - ChannelOptions? channel = null; - if (post.IsFromChannel) - { - channel = await _channelOptionService.FetchChannelByChannelId(post.ChannelID); - } - string postText = _textHelperService.MakePostText(post, poster, channel); - bool hasSpoiler = post.HasSpoiler; - try { - //发布频道发布消息 - if (!post.IsMediaGroup) - { - string? warnText = _tagRepository.GetActivedTagWarnings(post.Tags); - if (!string.IsNullOrEmpty(warnText)) - { - await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, warnText, allowSendingWithoutReply: true); - } - - Message? postMessage = null; - if (post.PostType == MessageType.Text) - { - postMessage = await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, postText, parseMode: ParseMode.Html, disableWebPagePreview: true); - } - else - { - 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; - } - - postMessage = await handler; - } - post.PublicMsgID = postMessage?.MessageId ?? -1; - } - else - { - 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 attachmentType = attachments[i].Type; - if (attachmentType == MessageType.Unknown) - { - attachmentType = post.PostType; - } - - 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("未知的稿件类型"), - }; - } - - string? warnText = _tagRepository.GetActivedTagWarnings(post.Tags); - if (!string.IsNullOrEmpty(warnText)) - { - await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, warnText, allowSendingWithoutReply: true); - } - - var postMessages = await _botClient.SendMediaGroupAsync(_channelService.AcceptChannel.Id, group); - post.PublicMsgID = postMessages.First().MessageId; - post.PublishMediaGroupID = postMessages.First().MediaGroupId ?? ""; - //记录媒体组消息 - await _mediaGroupService.AddPostMediaGroup(postMessages); - } } finally {