Skip to content

Commit

Permalink
feat 被拒绝的稿件发布时屏蔽文字内容
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jan 5, 2023
1 parent 49f1b70 commit f5441f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 214 deletions.
213 changes: 2 additions & 211 deletions XinjingdailyBot.Command/ReviewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public async Task HandleQuery(Users dbUser, CallbackQuery callbackQuery)
break;

case "review accept":
await AcceptPost(post, dbUser, callbackQuery);
await _postService.AcceptPost(post, dbUser, callbackQuery);
break;

case "review anymouse":
Expand Down Expand Up @@ -279,7 +279,7 @@ private async Task RejectPostHelper(Posts post, Users dbUser, RejectReason rejec
{
post.Reason = rejectReason;
string reason = _textHelperService.RejectReasonToString(rejectReason);
await RejetPost(post, dbUser, reason);
await _postService.RejetPost(post, dbUser, reason);
}

/// <summary>
Expand Down Expand Up @@ -361,214 +361,5 @@ private async Task SetPostTag(Posts post, BuildInTags tag, CallbackQuery callbac
(hasSpoiler ? _markupHelperService.ReviewKeyboardAWithSpoiler(post.Tags) : _markupHelperService.ReviewKeyboardA(post.Tags));
await _botClient.EditMessageReplyMarkupAsync(callbackQuery.Message!, keyboard);
}

/// <summary>
/// 拒绝投稿
/// </summary>
/// <param name="post"></param>
/// <param name="rejectReason"></param>
/// <returns></returns>
private async Task RejetPost(Posts post, Users dbUser, string rejectReason)
{
post.ReviewerUID = dbUser.UserID;
post.Status = PostStatus.Rejected;
post.ModifyAt = DateTime.Now;
await _postService.Updateable(post).UpdateColumns(x => new { x.Reason, x.ReviewerUID, x.Status, x.ModifyAt }).ExecuteCommandAsync();

Users poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID);

//修改审核群消息
string reviewMsg = _textHelperService.MakeReviewMessage(poster, dbUser, post.Anonymous, rejectReason);
await _botClient.EditMessageTextAsync(_channelService.ReviewGroup.Id, (int)post.ManageMsgID, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);

//拒稿频道发布消息
if (!post.IsMediaGroup)
{
await _botClient.CopyMessageAsync(_channelService.RejectChannel.Id, _channelService.ReviewGroup.Id, (int)post.ReviewMsgID);
}
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++)
{
MessageType attachmentType = attachments[i].Type;
if (attachmentType == MessageType.Unknown)
{
attachmentType = post.PostType;
}
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.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)),
_ => throw new Exception(),
};
}
var _ = await _botClient.SendMediaGroupAsync(_channelService.RejectChannel.Id, group);
//投稿消息组处理 TODO
}

//通知投稿人
string posterMsg = _textHelperService.MakeNotification(rejectReason);
if (poster.Notification)
{
await _botClient.SendTextMessageAsync(post.OriginChatID, posterMsg, replyToMessageId: (int)post.OriginMsgID, allowSendingWithoutReply: true);
}
else
{
await _botClient.EditMessageTextAsync(post.OriginChatID, (int)post.ActionMsgID, posterMsg);
}

poster.RejetCount++;
poster.ModifyAt = DateTime.Now;
await _userService.Updateable(poster).UpdateColumns(x => new { x.RejetCount, x.ModifyAt }).ExecuteCommandAsync();

if (poster.UserID != dbUser.UserID) //非同一个人才增加审核数量
{
dbUser.ReviewCount++;
dbUser.ModifyAt = DateTime.Now;
await _userService.Updateable(dbUser).UpdateColumns(x => new { x.ReviewCount, x.ModifyAt }).ExecuteCommandAsync();
}
}

/// <summary>
/// 接受投稿
/// </summary>
/// <param name="post"></param>
/// <param name="dbUser"></param>
/// <param name="callbackQuery"></param>
/// <returns></returns>
private async Task AcceptPost(Posts post, Users dbUser, CallbackQuery callbackQuery)
{
Users poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID);

string postText = _textHelperService.MakePostText(post, poster);

bool hasSpoiler = post.Tags.HasFlag(BuildInTags.Spoiler);

//发布频道发布消息
if (!post.IsMediaGroup)
{
if (post.Tags.HasFlag(BuildInTags.NSFW))
{
await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, _textHelperService.NSFWWrning, allowSendingWithoutReply: true);
}

Message msg;
if (post.PostType == MessageType.Text)
{
msg = await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, postText, parseMode: ParseMode.Html, disableWebPagePreview: true);
}
else
{
Attachments attachment = await _attachmentService.Queryable().FirstAsync(x => x.PostID == post.Id);

switch (post.PostType)
{
case MessageType.Photo:
msg = await _botClient.SendPhotoAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler);
break;
case MessageType.Audio:
msg = await _botClient.SendAudioAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, title: attachment.FileName);
break;
case MessageType.Video:
msg = await _botClient.SendVideoAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html, hasSpoiler: hasSpoiler);
break;
case MessageType.Document:
msg = await _botClient.SendDocumentAsync(_channelService.AcceptChannel.Id, new InputFileId(attachment.FileID), caption: postText, parseMode: ParseMode.Html);
break;
default:
await _botClient.AutoReplyAsync($"不支持的稿件类型: {post.PostType}", callbackQuery);
return;
}
}
post.PublicMsgID = msg.MessageId;
}
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++)
{
MessageType attachmentType = attachments[i].Type;
if (attachmentType == MessageType.Unknown)
{
attachmentType = post.PostType;
}
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.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? postText : null, ParseMode = ParseMode.Html },
_ => throw new Exception(),
};
}

if (post.Tags.HasFlag(BuildInTags.NSFW))
{
await _botClient.SendTextMessageAsync(_channelService.AcceptChannel.Id, _textHelperService.NSFWWrning, allowSendingWithoutReply: true);
}

var messages = await _botClient.SendMediaGroupAsync(_channelService.AcceptChannel.Id, group);
post.PublicMsgID = messages.First().MessageId;
}

await _botClient.AutoReplyAsync("稿件已发布", callbackQuery);

post.ReviewerUID = dbUser.UserID;
post.Status = PostStatus.Accepted;
post.ModifyAt = DateTime.Now;

//修改审核群消息
if (!post.IsDirectPost) // 非直接投稿
{
string reviewMsg = _textHelperService.MakeReviewMessage(poster, dbUser, post.Anonymous);
await _botClient.EditMessageTextAsync(callbackQuery.Message!, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);
}
else //直接投稿, 在审核群留档
{
string reviewMsg = _textHelperService.MakeReviewMessage(poster, post.PublicMsgID, post.Anonymous);
var msg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true);
post.ReviewMsgID = msg.MessageId;
}

await _postService.Updateable(post).UpdateColumns(x => new { x.ReviewMsgID, x.PublicMsgID, x.ReviewerUID, x.Status, x.ModifyAt }).ExecuteCommandAsync();

//通知投稿人
string posterMsg = _textHelperService.MakeNotification(post.IsDirectPost, post.PublicMsgID);

if (poster.Notification && poster.UserID != dbUser.UserID)//启用通知并且审核与投稿不是同一个人
{//单独发送通知消息
await _botClient.SendTextMessageAsync(post.OriginChatID, posterMsg, parseMode: ParseMode.Html, replyToMessageId: (int)post.OriginMsgID, allowSendingWithoutReply: true, disableWebPagePreview: true);
}
else
{//静默模式, 不单独发送通知消息
await _botClient.EditMessageTextAsync(post.OriginChatID, (int)post.ActionMsgID, posterMsg, ParseMode.Html, disableWebPagePreview: true);
}

//增加通过数量
poster.AcceptCount++;
poster.ModifyAt = DateTime.Now;
await _userService.Updateable(poster).UpdateColumns(x => new { x.AcceptCount, x.ModifyAt }).ExecuteCommandAsync();

if (!post.IsDirectPost) //增加审核数量
{
if (poster.UserID != dbUser.UserID)
{
dbUser.ReviewCount++;
dbUser.ModifyAt = DateTime.Now;
await _userService.Updateable(dbUser).UpdateColumns(x => new { x.ReviewCount, x.ModifyAt }).ExecuteCommandAsync();
}
}
else
{
poster.PostCount++;
poster.ModifyAt = DateTime.Now;
await _userService.Updateable(poster).UpdateColumns(x => new { x.PostCount, x.ModifyAt }).ExecuteCommandAsync();
}
}
}
}
21 changes: 19 additions & 2 deletions XinjingdailyBot.Service/Data/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,24 @@ public async Task RejetPost(Posts post, Users dbUser, string rejectReason)
//拒稿频道发布消息
if (!post.IsMediaGroup)
{
await _botClient.CopyMessageAsync(_channelService.RejectChannel.Id, _channelService.ReviewGroup.Id, (int)post.ReviewMsgID);
if (post.PostType != MessageType.Text)
{
var attachment = await _attachmentService.Queryable().Where(x => x.PostID == post.Id).FirstAsync();

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.Document => _botClient.SendDocumentAsync(_channelService.RejectChannel.Id, new InputFileId(attachment.FileID)),
_ => throw new Exception("未知的稿件类型"),
};

if (handler != null)
{
await handler;
}
}
}
else
{
Expand All @@ -523,7 +540,7 @@ public async Task RejetPost(Posts post, Users dbUser, string rejectReason)
MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)),
MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)),
MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)),
_ => throw new Exception(),
_ => throw new Exception("未知的稿件类型"),
};
}
var _ = await _botClient.SendMediaGroupAsync(_channelService.RejectChannel.Id, group);
Expand Down
2 changes: 1 addition & 1 deletion XinjingdailyBot.WebAPI/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;

[assembly: CLSCompliant(false)]
[assembly: AssemblyVersion("2.0.3.2")]
[assembly: AssemblyVersion("2.0.3.3")]

[assembly: AssemblyCopyright("Copyright @ 2022 Chr_")]
[assembly: AssemblyProduct("XinjingDaily Bot")]
Expand Down

0 comments on commit f5441f7

Please sign in to comment.