diff --git a/XinjingdailyBot.Service/Data/UserService.cs b/XinjingdailyBot.Service/Data/UserService.cs index 73617530..b9cf2b83 100644 --- a/XinjingdailyBot.Service/Data/UserService.cs +++ b/XinjingdailyBot.Service/Data/UserService.cs @@ -585,11 +585,12 @@ private async Task AutoLeaveChat(Chat? msgChat) return (sb.ToString(), keyboard); } - public async Task GetUserBasicInfo(Users dbUser) + public string GetUserBasicInfo(Users dbUser) { var userNick = dbUser.FullName.EscapeHtml(); var level = _levelRepository.GetLevelName(dbUser.Level); var group = _groupRepository.GetGroupName(dbUser.GroupID); + var status = dbUser.IsBan ? "封禁中" : "正常"; int totalPost = dbUser.PostCount - dbUser.ExpiredPostCount; double passPercent = 1.0 * dbUser.AcceptCount / totalPost; @@ -599,6 +600,7 @@ public async Task GetUserBasicInfo(Users dbUser) sb.AppendLine($"用户名: {userNick}"); sb.AppendLine($"用户ID: {dbUser.UserID}"); sb.AppendLine($"用户组: {group}"); + sb.AppendLine($"状态: {status}"); sb.AppendLine($"等级: {level}"); sb.AppendLine($"投稿数量: {totalPost}"); sb.AppendLine($"投稿通过率: {passPercent:0.00%}"); @@ -608,5 +610,44 @@ public async Task GetUserBasicInfo(Users dbUser) return sb.ToString(); } + + public async Task GetUserRank(Users dbUser) + { + var now = DateTime.Now; + var prev30Days = now.AddDays(-30).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second); + + StringBuilder sb = new(); + + if (dbUser.GroupID == 1) + { + if (dbUser.AcceptCount >= 1) + { + const int miniumPost = 10; + + int acceptCountRank = await Queryable().Where(x => !x.IsBan && !x.IsBot && x.GroupID == 1 && x.AcceptCount > dbUser.AcceptCount && x.ModifyAt >= prev30Days).CountAsync() + 1; + + double ratio = 1.0 * dbUser.AcceptCount / dbUser.PostCount; + int acceptRatioRank = await Queryable().Where(x => !x.IsBan && !x.IsBot && x.GroupID == 1 && x.AcceptCount > miniumPost && x.ModifyAt >= prev30Days) + .Select(y => 100.0 * y.AcceptCount / y.PostCount).Where(x => x > ratio).CountAsync() + 1; + + sb.AppendLine($"通过数排名: {acceptCountRank}"); + sb.AppendLine($"通过率排名: {acceptRatioRank}"); + } + else + { + sb.AppendLine("稿件数量太少, 未进入排行榜"); + } + } + else + { + int activeUser = await Queryable().Where(x => !x.IsBan && !x.IsBot && x.ModifyAt >= prev30Days).CountAsync(); + sb.AppendLine($"活跃用户数: {activeUser}"); + + sb.AppendLine($"管理员不参与用户排名"); + sb.AppendLine($"可以使用命令 /userrank 查看总排名"); + } + + return sb.ToString(); + } } } diff --git a/XinjingdailyBot.WebAPI/AssemblyInfo.cs b/XinjingdailyBot.WebAPI/AssemblyInfo.cs index 26c28e19..4e2048b9 100644 --- a/XinjingdailyBot.WebAPI/AssemblyInfo.cs +++ b/XinjingdailyBot.WebAPI/AssemblyInfo.cs @@ -1,7 +1,7 @@ using System.Reflection; [assembly: CLSCompliant(false)] -[assembly: AssemblyVersion("2.0.10.0")] +[assembly: AssemblyVersion("2.0.10.1")] [assembly: AssemblyCopyright("Copyright @ 2023 Chr_")] [assembly: AssemblyProduct("XinjingDaily Bot")]