From ce7050e13ed053eed6401984d0f39770d661f473 Mon Sep 17 00:00:00 2001 From: Chr_ Date: Thu, 17 Aug 2023 23:07:45 +0800 Subject: [PATCH] misc --- Directory.Build.props | 2 +- XinjingdailyBot.Command/SuperCommand.cs | 9 ++- .../Bot/Handler/ICommandHandler.cs | 3 +- .../Bot/Handler/CommandHandler.cs | 15 +++- XinjingdailyBot.Service/Data/PostService.cs | 72 +++++++++++++++---- 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 62930665..c44c0120 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.1.5.4 + 2.1.6.0 diff --git a/XinjingdailyBot.Command/SuperCommand.cs b/XinjingdailyBot.Command/SuperCommand.cs index e5532181..e14e6e83 100644 --- a/XinjingdailyBot.Command/SuperCommand.cs +++ b/XinjingdailyBot.Command/SuperCommand.cs @@ -221,10 +221,17 @@ async Task exec() [TextCmd("COMMAND", EUserRights.SuperCmd, Description = "设置命令菜单")] public async Task ResponseCommand(Message message) { - bool result = await _commandHandler.GetCommandsMenu(); + bool result = await _commandHandler.SetCommandsMenu(); await _botClient.SendCommandReply(result ? "设置菜单成功" : "设置菜单失败", message, autoDelete: false); } + [TextCmd("CLEARCOMMAND", EUserRights.SuperCmd, Description = "设置命令菜单")] + public async Task ResponseClearCommand(Message message) + { + bool result = await _commandHandler.ClearCommandsMenu(); + await _botClient.SendCommandReply(result ? "清除菜单成功" : "清除菜单失败", message, autoDelete: false); + } + /// /// 重新计算用户投稿数量 /// diff --git a/XinjingdailyBot.Interface/Bot/Handler/ICommandHandler.cs b/XinjingdailyBot.Interface/Bot/Handler/ICommandHandler.cs index 3f069ce9..760dbc48 100644 --- a/XinjingdailyBot.Interface/Bot/Handler/ICommandHandler.cs +++ b/XinjingdailyBot.Interface/Bot/Handler/ICommandHandler.cs @@ -19,7 +19,7 @@ public interface ICommandHandler /// 设置菜命令单 /// /// - Task GetCommandsMenu(); + Task SetCommandsMenu(); /// /// 注册命令 /// @@ -39,4 +39,5 @@ public interface ICommandHandler /// /// Task OnQueryCommandReceived(Users dbUser, CallbackQuery query); + Task ClearCommandsMenu(); } diff --git a/XinjingdailyBot.Service/Bot/Handler/CommandHandler.cs b/XinjingdailyBot.Service/Bot/Handler/CommandHandler.cs index b023519b..acf0c41f 100644 --- a/XinjingdailyBot.Service/Bot/Handler/CommandHandler.cs +++ b/XinjingdailyBot.Service/Bot/Handler/CommandHandler.cs @@ -449,7 +449,7 @@ public string GetAvilabeCommands(Users dbUser) } } - public async Task GetCommandsMenu() + public async Task SetCommandsMenu() { var cmds = new List(); @@ -474,6 +474,7 @@ void AddCommands(EUserRights right) AddCommands(EUserRights.None); AddCommands(EUserRights.NormalCmd); + await _botClient.SetMyCommandsAsync(cmds, null); await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllPrivateChats()); await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllGroupChats()); @@ -484,4 +485,16 @@ void AddCommands(EUserRights right) await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeChatAdministrators { ChatId = _channelService.ReviewGroup.Id }); return true; } + + public async Task ClearCommandsMenu() + { + var cmds = new List(); + + await _botClient.SetMyCommandsAsync(cmds); + await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllPrivateChats()); + await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllGroupChats()); + await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeAllChatAdministrators()); + await _botClient.SetMyCommandsAsync(cmds, new BotCommandScopeChatAdministrators { ChatId = _channelService.ReviewGroup.Id }); + return true; + } } diff --git a/XinjingdailyBot.Service/Data/PostService.cs b/XinjingdailyBot.Service/Data/PostService.cs index c53b2310..502a3d5c 100644 --- a/XinjingdailyBot.Service/Data/PostService.cs +++ b/XinjingdailyBot.Service/Data/PostService.cs @@ -527,21 +527,29 @@ public async Task SetPostTag(NewPosts post, string payload, CallbackQuery callba public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectReason) { - post.RejectReason = rejectReason.Name; - post.CountReject = rejectReason.IsCount; - post.ReviewerUID = dbUser.UserID; - post.Status = EPostStatus.Rejected; - post.ModifyAt = DateTime.Now; - await Updateable(post).UpdateColumns(static x => new { - x.RejectReason, - x.CountReject, - x.ReviewerUID, - x.Status, - x.ModifyAt - }).ExecuteCommandAsync(); - var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID); + if (poster.IsBan) + { + await RejectIfBan(post, poster, dbUser, null); + return; + } + else + { + post.RejectReason = rejectReason.Name; + post.CountReject = rejectReason.IsCount; + post.ReviewerUID = dbUser.UserID; + post.Status = EPostStatus.Rejected; + post.ModifyAt = DateTime.Now; + await Updateable(post).UpdateColumns(static x => new { + x.RejectReason, + x.CountReject, + x.ReviewerUID, + x.Status, + x.ModifyAt + }).ExecuteCommandAsync(); + } + //修改审核群消息 string reviewMsg = _textHelperService.MakeReviewMessage(poster, dbUser, post.Anonymous, rejectReason.FullText); await _botClient.EditMessageTextAsync(post.ReviewActionChatID, (int)post.ReviewActionMsgID, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true); @@ -634,10 +642,48 @@ public async Task RejetPost(NewPosts post, Users dbUser, RejectReasons rejectRea } } + /// + /// 拒绝封禁用户的投稿 + /// + /// + /// + /// + /// + /// + private async Task RejectIfBan(NewPosts post, Users poster, Users reviewer, CallbackQuery? callbackQuery) + { + post.RejectReason = "封禁自动拒绝"; + post.CountReject = true; + post.ReviewerUID = reviewer.UserID; + post.Status = EPostStatus.Rejected; + post.ModifyAt = DateTime.Now; + await Updateable(post).UpdateColumns(static x => new { + x.RejectReason, + x.CountReject, + x.ReviewerUID, + x.Status, + x.ModifyAt + }).ExecuteCommandAsync(); + + if (callbackQuery != null) + { + await _botClient.AutoReplyAsync("此用户已被封禁,无法通过审核", callbackQuery); + + string reviewMsg = _textHelperService.MakeReviewMessage(poster, reviewer, post.Anonymous, "此用户已被封禁"); + await _botClient.EditMessageTextAsync(callbackQuery.Message!, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true); + } + } + public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, CallbackQuery callbackQuery) { var poster = await _userService.Queryable().FirstAsync(x => x.UserID == post.PosterUID); + if (poster.IsBan) + { + await RejectIfBan(post, poster, dbUser, callbackQuery); + return; + } + ChannelOptions? channel = null; if (post.IsFromChannel) {