Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Aug 15, 2023
1 parent 4cf282f commit cd68751
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.1.5.1</Version>
<Version>2.1.5.2</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
96 changes: 1 addition & 95 deletions XinjingdailyBot.Tasks/ReviewStatusTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace XinjingdailyBot.Tasks;
/// <summary>
/// 定期发布稿件处理
/// </summary>
[Job("0 0 0 * * ?")]
//[Job("0 0 0 * * ?")]
internal class ReviewStatusTask : IJob
{
private readonly ILogger<ReviewStatusTask> _logger;
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit cd68751

Please sign in to comment.