diff --git a/Directory.Build.props b/Directory.Build.props index 70b38d63..642ded0a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.2.4.3 + 2.2.4.4 diff --git a/XinjingdailyBot.Command/AdminCommand.cs b/XinjingdailyBot.Command/AdminCommand.cs index 268f3d2b..f8d54fd9 100644 --- a/XinjingdailyBot.Command/AdminCommand.cs +++ b/XinjingdailyBot.Command/AdminCommand.cs @@ -770,7 +770,7 @@ public async Task QResponseCancelSearchUser(CallbackQuery callbackQuery, string[ public async Task ResponsePostReport(Message message) { var now = DateTime.Now; - var prev1Day = now.AddDays(-1).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); + var today = now.AddDays(-1).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); var prev7Days = now.AddDays(-7).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); var prev30Days = now.AddDays(-30).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); var monthStart = now.AddDays(1 - now.Day).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); @@ -780,15 +780,15 @@ public async Task ResponsePostReport(Message message) var sb = new StringBuilder(); - var todayPost = await _postService.CountAllPosts(prev1Day); - var todayAcceptPost = await _postService.CountAcceptedPosts(prev1Day); - var todayRejectPost = await _postService.CountRejectedPosts(prev1Day); + var todayPost = await _postService.CountAllPosts(today); + var todayAcceptPost = await _postService.CountAcceptedPosts(today); + var todayRejectPost = await _postService.CountRejectedPosts(today); sb.AppendLine("-- 24小时投稿统计 --"); sb.AppendLine($"接受/拒绝: {todayAcceptPost} / {todayRejectPost}"); if (second) { - var todayAcceptSecondPost = await _postService.CountAcceptedSecondPosts(prev1Day); + var todayAcceptSecondPost = await _postService.CountAcceptedSecondPosts(today); sb.AppendLine($"接受(二频): {todayAcceptSecondPost}"); } sb.AppendLine($"通过率: {(todayPost > 0 ? (100 * todayAcceptPost / todayPost).ToString("f2") : "--")}%"); diff --git a/XinjingdailyBot.Command/CommonCommand.cs b/XinjingdailyBot.Command/CommonCommand.cs index f0e31f6b..a6da066a 100644 --- a/XinjingdailyBot.Command/CommonCommand.cs +++ b/XinjingdailyBot.Command/CommonCommand.cs @@ -148,10 +148,7 @@ public async Task ResponseVersion(Message message) public async Task ResponseMyBan(Users dbUser, Message message) { var expireTime = DateTime.Now.AddDays(-WarnDuration); - - var records = await _banRecordService.Queryable() - .Where(x => x.UserID == dbUser.UserID && (x.Type != EBanType.Warning || x.BanTime > expireTime)) - .ToListAsync(); + var records = await _banRecordService.GetBanRecores(dbUser, expireTime); var sb = new StringBuilder(); diff --git a/XinjingdailyBot.Command/PostCommand.cs b/XinjingdailyBot.Command/PostCommand.cs index 7b5d0659..72b255eb 100644 --- a/XinjingdailyBot.Command/PostCommand.cs +++ b/XinjingdailyBot.Command/PostCommand.cs @@ -221,7 +221,6 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query) await _botClient.EditMessageTextAsync(query.Message!, Langs.ThanksForSendingPost, replyMarkup: null); dbUser.PostCount++; - dbUser.ModifyAt = DateTime.Now; await _userService.UpdateUserPostCount(dbUser); } } diff --git a/XinjingdailyBot.Command/SuperCommand.cs b/XinjingdailyBot.Command/SuperCommand.cs index ee31dd7d..e8e7ab1f 100644 --- a/XinjingdailyBot.Command/SuperCommand.cs +++ b/XinjingdailyBot.Command/SuperCommand.cs @@ -272,7 +272,6 @@ public async Task ResponseReCalcPost(Message message) user.RejectCount = rejectCount; user.ExpiredPostCount = expiredCount; user.ReviewCount = reviewCount; - user.ModifyAt = DateTime.Now; effectCount++; diff --git a/XinjingdailyBot.Interface/Data/IAdvertisePostService.cs b/XinjingdailyBot.Interface/Data/IAdvertisePostService.cs index 122bbd70..9d7ab570 100644 --- a/XinjingdailyBot.Interface/Data/IAdvertisePostService.cs +++ b/XinjingdailyBot.Interface/Data/IAdvertisePostService.cs @@ -8,6 +8,13 @@ namespace XinjingdailyBot.Interface.Data; /// public interface IAdvertisePostService : IBaseService { + /// + /// 添加广告 + /// + /// + /// + /// + /// Task AddAdPost(Advertises ad, long chatId, int msgId); /// diff --git a/XinjingdailyBot.Interface/Data/IAdvertiseService.cs b/XinjingdailyBot.Interface/Data/IAdvertiseService.cs index 203cb52f..a756412e 100644 --- a/XinjingdailyBot.Interface/Data/IAdvertiseService.cs +++ b/XinjingdailyBot.Interface/Data/IAdvertiseService.cs @@ -9,6 +9,11 @@ namespace XinjingdailyBot.Interface.Data; /// public interface IAdvertiseService : IBaseService { + /// + /// 创建广告 + /// + /// + /// Task CreateAdvertise(Message message); /// @@ -16,5 +21,10 @@ public interface IAdvertiseService : IBaseService /// /// Task GetPostableAdvertise(); + /// + /// 更新广告统计 + /// + /// + /// Task UpdateAdvertiseStatistics(Advertises ad); } diff --git a/XinjingdailyBot.Interface/Data/IBanRecordService.cs b/XinjingdailyBot.Interface/Data/IBanRecordService.cs index ee53930f..79bd3026 100644 --- a/XinjingdailyBot.Interface/Data/IBanRecordService.cs +++ b/XinjingdailyBot.Interface/Data/IBanRecordService.cs @@ -34,6 +34,8 @@ public interface IBanRecordService : IBaseService /// /// Task> GetBanRecores(Users targetUser); + Task> GetBanRecores(Users targetUser, DateTime expireTime); + /// /// 获取最近封禁/解封记录 /// diff --git a/XinjingdailyBot.Interface/Data/ICmdRecordService.cs b/XinjingdailyBot.Interface/Data/ICmdRecordService.cs index 70c5cafb..b55dcae5 100644 --- a/XinjingdailyBot.Interface/Data/ICmdRecordService.cs +++ b/XinjingdailyBot.Interface/Data/ICmdRecordService.cs @@ -29,8 +29,28 @@ public interface ICmdRecordService : IBaseService /// /// Task AddCmdRecord(CallbackQuery query, Users dbUser, bool handled, bool isQuery, string? exception); + /// + /// 获取命令调用记录 + /// + /// + /// Task FetchCmdRecordByMessageId(int msgId); + /// + /// 获取错误命令调用数 + /// + /// + /// Task GetErrorCmdCount(DateTime startTime); + /// + /// 获取查询命令调用数 + /// + /// + /// Task GetQueryCmdCount(DateTime startTime); + /// + /// 获取文本命令调用数 + /// + /// + /// Task GetTextCmdCount(DateTime startTime); } diff --git a/XinjingdailyBot.Interface/Data/IDialogueService.cs b/XinjingdailyBot.Interface/Data/IDialogueService.cs index a57349a5..cfaba267 100644 --- a/XinjingdailyBot.Interface/Data/IDialogueService.cs +++ b/XinjingdailyBot.Interface/Data/IDialogueService.cs @@ -9,6 +9,13 @@ namespace XinjingdailyBot.Interface.Data; /// public interface IDialogueService : IBaseService { + /// + /// 获取用户的群组消息记录 + /// + /// + /// + /// + /// Task> FetchUserGroupMessages(Users user, int startId = 0, int takeCount = 30); /// diff --git a/XinjingdailyBot.Interface/Data/IPostService.cs b/XinjingdailyBot.Interface/Data/IPostService.cs index f25a50c8..65b30980 100644 --- a/XinjingdailyBot.Interface/Data/IPostService.cs +++ b/XinjingdailyBot.Interface/Data/IPostService.cs @@ -94,6 +94,13 @@ public interface IPostService : IBaseService /// /// Task CountRejectedPosts(); + /// + /// 获取待审核稿件 + /// + /// + /// + Task CountReviewingPosts(DateTime afterTime); + /// /// 编辑稿件描述 /// @@ -101,6 +108,12 @@ public interface IPostService : IBaseService /// /// Task EditPostText(NewPosts post, string text); + /// + /// 是否存在指定媒体组ID的稿件 + /// + /// + /// + Task IfExistsMediaGroupId(string mediaGroupId); /// /// 从审核回调中获取稿件 @@ -114,6 +127,12 @@ public interface IPostService : IBaseService /// /// Task FetchPostFromReplyToMessage(Message message); + /// + /// 获取计划发布的投稿 + /// + /// + Task GetInPlanPost(); + /// /// 获取最新未审核稿件 /// @@ -125,6 +144,11 @@ public interface IPostService : IBaseService /// /// Task GetPostByPostId(int postId); + /// + /// 获取随机稿件 + /// + /// + Task GetRandomPost(); /// /// 处理多媒体投稿(mediaGroup) diff --git a/XinjingdailyBot.Interface/Data/IUserService.cs b/XinjingdailyBot.Interface/Data/IUserService.cs index 50a1add8..200929b0 100644 --- a/XinjingdailyBot.Interface/Data/IUserService.cs +++ b/XinjingdailyBot.Interface/Data/IUserService.cs @@ -159,6 +159,18 @@ public interface IUserService : IBaseService /// /// Task UpdateUserGroupId(Users user, int groupId); + /// + /// 设置用户通知偏好 + /// + /// + /// + /// Task SetUserNotification(Users user, bool notification); + /// + /// 设置默认匿名偏好 + /// + /// + /// + /// Task SetUserPreferAnonymous(Users user, bool preferAnonymous); } diff --git a/XinjingdailyBot.Service/Bot/Handler/ChannelPostHandler.cs b/XinjingdailyBot.Service/Bot/Handler/ChannelPostHandler.cs index a293c559..c71e7872 100644 --- a/XinjingdailyBot.Service/Bot/Handler/ChannelPostHandler.cs +++ b/XinjingdailyBot.Service/Bot/Handler/ChannelPostHandler.cs @@ -112,8 +112,7 @@ public async Task OnTextChannelPostReceived(Users dbUser, Message message) //增加通过数量 dbUser.AcceptCount++; - dbUser.ModifyAt = DateTime.Now; - await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.AcceptCount, x.ModifyAt }).ExecuteCommandAsync(); + await _userService.UpdateUserPostCount(dbUser); } public async Task OnMediaChannelPostReceived(Users dbUser, Message message) @@ -168,13 +167,12 @@ public async Task OnMediaChannelPostReceived(Users dbUser, Message message) if (attachment != null) { - await _attachmentService.Insertable(attachment).ExecuteCommandAsync(); + await _attachmentService.CreateAttachment(attachment); } //增加通过数量 dbUser.AcceptCount++; - dbUser.ModifyAt = DateTime.Now; - await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.AcceptCount, x.ModifyAt }).ExecuteCommandAsync(); + await _userService.UpdateUserPostCount(dbUser); } /// @@ -191,7 +189,7 @@ public async Task OnMediaGroupChannelPostReceived(Users dbUser, Message message) MediaGroupIDs.TryAdd(mediaGroupId, -1); - bool exists = await _postService.Queryable().AnyAsync(x => x.OriginMediaGroupID == mediaGroupId); + bool exists = await _postService.IfExistsMediaGroupId(mediaGroupId); if (!exists) { long channelId = -1, channelMsgId = -1; @@ -249,8 +247,7 @@ public async Task OnMediaGroupChannelPostReceived(Users dbUser, Message message) //增加通过数量 dbUser.AcceptCount++; - dbUser.ModifyAt = DateTime.Now; - await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.AcceptCount, x.ModifyAt }).ExecuteCommandAsync(); + await _userService.UpdateUserPostCount(dbUser); }); } } @@ -261,7 +258,7 @@ public async Task OnMediaGroupChannelPostReceived(Users dbUser, Message message) var attachment = _attachmentService.GenerateAttachment(message, postID); if (attachment != null) { - await _attachmentService.Insertable(attachment).ExecuteCommandAsync(); + await _attachmentService.CreateAttachment(attachment); } //记录媒体组 diff --git a/XinjingdailyBot.Service/Bot/Handler/InlineQueryHandler.cs b/XinjingdailyBot.Service/Bot/Handler/InlineQueryHandler.cs index 979cef8a..8a8a5c62 100644 --- a/XinjingdailyBot.Service/Bot/Handler/InlineQueryHandler.cs +++ b/XinjingdailyBot.Service/Bot/Handler/InlineQueryHandler.cs @@ -1,4 +1,3 @@ -using SqlSugar; using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; @@ -40,16 +39,14 @@ public async Task OnInlineQueryReceived(Users dbUser, InlineQuery query) for (int i = 0; i < 10; i++) { - var randomPost = await _postService.Queryable() - .Where(static x => x.Status == EPostStatus.Accepted && x.PostType == MessageType.Photo) - .OrderBy(static x => SqlFunc.GetRandom()).Take(1).FirstAsync(); + var randomPost = await _postService.GetRandomPost(); if (randomPost == null) { break; } - var postAttachment = await _attachmentService.Queryable().Where(x => x.PostID == randomPost.Id).FirstAsync(); + var postAttachment = await _attachmentService.FetchAttachmentByPostId(randomPost.Id); var keyboard = _markupHelperService.LinkToOriginPostKeyboard(randomPost); results.Add(new InlineQueryResultCachedPhoto(i.ToString(), postAttachment.FileID) { Title = randomPost.Text, diff --git a/XinjingdailyBot.Service/Data/BanRecordService.cs b/XinjingdailyBot.Service/Data/BanRecordService.cs index 01158656..f5e1c161 100644 --- a/XinjingdailyBot.Service/Data/BanRecordService.cs +++ b/XinjingdailyBot.Service/Data/BanRecordService.cs @@ -50,6 +50,13 @@ public Task> GetBanRecores(Users targetUser) .OrderByDescending(static x => new { x.BanTime }).ToListAsync(); } + public Task> GetBanRecores(Users targetUser, DateTime expireTime) + { + return Queryable() + .Where(x => x.UserID == targetUser.UserID && (x.Type != EBanType.Warning || x.BanTime > expireTime)) + .ToListAsync(); + } + public async Task GetLatestBanRecord(long userId) { return await Queryable() diff --git a/XinjingdailyBot.Service/Data/DialogueService.cs b/XinjingdailyBot.Service/Data/DialogueService.cs index a4cf1e7e..4d01239a 100644 --- a/XinjingdailyBot.Service/Data/DialogueService.cs +++ b/XinjingdailyBot.Service/Data/DialogueService.cs @@ -49,6 +49,11 @@ public async Task RecordMessage(Message message) public Task> FetchUserGroupMessages(Users user, int startId = 0, int takeCount = 30) { - return Queryable().Where(x => x.UserID == user.UserID && x.ChatID <= -1000000000000 && x.Id > startId).Take(takeCount).ToListAsync(); + return Queryable() + .Where(x => x.UserID == user.UserID && x.ChatID <= -1000000000000 && x.Id < startId) + .WhereIF(startId != 0, x => x.Id < startId) + .OrderByDescending(x => x.Id) + .Take(takeCount) + .ToListAsync(); } } diff --git a/XinjingdailyBot.Service/Data/PostService.cs b/XinjingdailyBot.Service/Data/PostService.cs index 3ab09aed..1c6ab71c 100644 --- a/XinjingdailyBot.Service/Data/PostService.cs +++ b/XinjingdailyBot.Service/Data/PostService.cs @@ -638,13 +638,11 @@ public async Task RejectPost(NewPosts post, Users dbUser, RejectReasons rejectRe } poster.RejectCount++; - poster.ModifyAt = DateTime.Now; await _userService.UpdateUserPostCount(poster); if (poster.UserID != dbUser.UserID) //非同一个人才增加审核数量 { dbUser.ReviewCount++; - dbUser.ModifyAt = DateTime.Now; await _userService.UpdateUserPostCount(dbUser); } } @@ -856,14 +854,12 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, bool seco if (poster.UserID != dbUser.UserID) { dbUser.ReviewCount++; - dbUser.ModifyAt = DateTime.Now; await _userService.UpdateUserPostCount(dbUser); } } else { poster.PostCount++; - poster.ModifyAt = DateTime.Now; await _userService.UpdateUserPostCount(poster); } } @@ -1088,6 +1084,11 @@ public Task CountExpiredPosts(DateTime afterTime) return Queryable().Where(x => x.CreateAt >= afterTime && x.Status < 0).CountAsync(); } + public Task CountReviewingPosts(DateTime afterTime) + { + return Queryable().Where(x => x.CreateAt >= afterTime && x.Status == EPostStatus.Reviewing).CountAsync(); + } + public Task RevocationPost(NewPosts post) { post.Status = EPostStatus.Revocation; @@ -1122,4 +1123,21 @@ public Task SetPostSpoiler(NewPosts post, bool spoiler) post.ModifyAt = DateTime.Now; return Updateable(post).UpdateColumns(static x => new { x.HasSpoiler, x.ModifyAt }).ExecuteCommandAsync(); } + + public Task IfExistsMediaGroupId(string mediaGroupId) + { + return Queryable().AnyAsync(x => x.OriginMediaGroupID == mediaGroupId); + } + + public async Task GetRandomPost() + { + return await Queryable() + .Where(static x => x.Status == EPostStatus.Accepted && x.PostType == MessageType.Photo) + .OrderBy(static x => SqlFunc.GetRandom()).FirstAsync(); + } + + public Task GetInPlanPost() + { + return Queryable().Where(static x => x.Status == EPostStatus.InPlan).FirstAsync(); + } } diff --git a/XinjingdailyBot.Service/Data/UserService.cs b/XinjingdailyBot.Service/Data/UserService.cs index 6b07f4ee..2d6ed8b8 100644 --- a/XinjingdailyBot.Service/Data/UserService.cs +++ b/XinjingdailyBot.Service/Data/UserService.cs @@ -811,6 +811,7 @@ public async Task UpdateUserPostCount(Users targerUser) targerUser.Experience = CalcUserExp(targerUser); var level = _levelRepository.GetLevelByExp(targerUser.Experience); targerUser.Level = level?.Id ?? 1; + targerUser.ModifyAt = DateTime.Now; await Updateable(targerUser).UpdateColumns(static x => new { x.Experience, diff --git a/XinjingdailyBot.Tasks/PlanedPostsTask.cs b/XinjingdailyBot.Tasks/PlanedPostsTask.cs index 6676988f..f3bdc6c6 100644 --- a/XinjingdailyBot.Tasks/PlanedPostsTask.cs +++ b/XinjingdailyBot.Tasks/PlanedPostsTask.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Logging; using XinjingdailyBot.Infrastructure.Attribute; -using XinjingdailyBot.Infrastructure.Enums; using XinjingdailyBot.Interface.Data; namespace XinjingdailyBot.Tasks; @@ -26,8 +25,7 @@ public async Task Execute(IJobExecutionContext context) { _logger.LogInformation("开始定时任务, 发布定时稿件"); - var post = await _postService.Queryable() - .Where(static x => x.Status == EPostStatus.InPlan).FirstAsync(); + var post = await _postService.GetInPlanPost(); if (post == null) { diff --git a/XinjingdailyBot.Tasks/ReviewStatusTask.cs b/XinjingdailyBot.Tasks/ReviewStatusTask.cs index 5b97516b..8761f3db 100644 --- a/XinjingdailyBot.Tasks/ReviewStatusTask.cs +++ b/XinjingdailyBot.Tasks/ReviewStatusTask.cs @@ -47,14 +47,15 @@ public async Task Execute(IJobExecutionContext context) var now = DateTime.Now; var today = now.AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); - var todayPost = await _postService.Queryable().Where(x => x.CreateAt >= today && x.Status > EPostStatus.Cancel).CountAsync(); - var todayAcceptPost = await _postService.Queryable().Where(x => x.CreateAt >= today && x.Status == EPostStatus.Accepted).CountAsync(); - var todayRejectPost = await _postService.Queryable().Where(x => x.CreateAt >= today && x.Status == EPostStatus.Rejected).CountAsync(); - var todayPaddingPost = await _postService.Queryable().Where(x => x.CreateAt >= today && x.Status == EPostStatus.Reviewing).CountAsync(); + + var todayPost = await _postService.CountAllPosts(today); + var todayAcceptPost = await _postService.CountAcceptedPosts(today); + var todayRejectPost = await _postService.CountRejectedPosts(today); + var todayPaddingPost = await _postService.CountReviewingPosts(today); if (_channelService.HasSecondChannel) { - var todayAcceptSecondPost = await _postService.Queryable().Where(x => x.CreateAt >= today && x.Status == EPostStatus.AcceptedSecond).CountAsync(); + var todayAcceptSecondPost = await _postService.CountAcceptedSecondPosts(today); todayAcceptPost += todayAcceptSecondPost; } diff --git a/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs b/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs index c9a312cb..be0bba39 100644 --- a/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs +++ b/XinjingdailyBot.WebAPI/IPC/Controllers/PostController.cs @@ -325,7 +325,6 @@ public async Task>> CreatePost([FromForm] }).ExecuteCommandAsync(); dbUser.PostCount++; - dbUser.ModifyAt = DateTime.Now; await _userService.UpdateUserPostCount(dbUser); var response = new GenericResponse { @@ -564,8 +563,7 @@ public async Task>> EditReviewMessage([Fr }).ExecuteCommandAsync(); dbUser.PostCount++; - dbUser.ModifyAt = DateTime.Now; - await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.PostCount, x.ModifyAt }).ExecuteCommandAsync(); + await _userService.UpdateUserPostCount(dbUser); var response = new GenericResponse { Code = HttpStatusCode.OK,