From d0ee6a5401b45c213bf1c6669cbceeaa60892300 Mon Sep 17 00:00:00 2001 From: Chr_ Date: Wed, 29 Nov 2023 21:28:43 +0800 Subject: [PATCH] UPDATE --- Directory.Build.props | 2 +- XinjingdailyBot.Infrastructure/OptionsSetting.cs | 4 ++++ .../Bot/Common/ChannelService.cs | 2 +- XinjingdailyBot.Service/Data/DialogueService.cs | 16 ++++++++++++++-- XinjingdailyBot.Service/Data/PostService.cs | 5 +++-- .../XinjingdailyBot.WebAPI.csproj | 1 + XinjingdailyBot.WebAPI/appsettings.json | 3 ++- XinjingdailyBot.sln | 6 ++++++ docker-compose.dcproj | 16 ++++++++++++++++ docker-compose.override.yml | 9 +++++++++ docker-compose.yml | 8 ++++++++ launchSettings.json | 11 +++++++++++ 12 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 docker-compose.dcproj create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.yml create mode 100644 launchSettings.json diff --git a/Directory.Build.props b/Directory.Build.props index be318cd0..456e073d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 2.2.4.6 + 2.2.4.7 diff --git a/XinjingdailyBot.Infrastructure/OptionsSetting.cs b/XinjingdailyBot.Infrastructure/OptionsSetting.cs index aa1e2879..1f7d2b3f 100644 --- a/XinjingdailyBot.Infrastructure/OptionsSetting.cs +++ b/XinjingdailyBot.Infrastructure/OptionsSetting.cs @@ -85,6 +85,10 @@ public sealed record BotOption /// 二级菜单 /// public bool PostSecondMenu { get; set; } + /// + /// 文本稿件发布时是否启用链接预览 + /// + public bool EnableWebPagePreview { get; set; } } /// diff --git a/XinjingdailyBot.Service/Bot/Common/ChannelService.cs b/XinjingdailyBot.Service/Bot/Common/ChannelService.cs index a569780a..e1e81f41 100644 --- a/XinjingdailyBot.Service/Bot/Common/ChannelService.cs +++ b/XinjingdailyBot.Service/Bot/Common/ChannelService.cs @@ -21,7 +21,7 @@ internal class ChannelService : IChannelService public Chat? LogChannel { get; private set; } public Chat CommentGroup { get; private set; } = new(); public Chat SubGroup { get; private set; } = new(); - public Chat SecondCommentGroup { get; private set; } = new(); + public Chat? SecondCommentGroup { get; private set; } public Chat AcceptChannel { get; private set; } = new(); public Chat? SecondChannel { get; private set; } public Chat RejectChannel { get; private set; } = new(); diff --git a/XinjingdailyBot.Service/Data/DialogueService.cs b/XinjingdailyBot.Service/Data/DialogueService.cs index dc6350da..aff1ada5 100644 --- a/XinjingdailyBot.Service/Data/DialogueService.cs +++ b/XinjingdailyBot.Service/Data/DialogueService.cs @@ -1,16 +1,21 @@ +using Microsoft.Extensions.DependencyInjection; using SqlSugar; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; using XinjingdailyBot.Infrastructure.Attribute; +using XinjingdailyBot.Interface.Bot.Common; using XinjingdailyBot.Interface.Data; using XinjingdailyBot.Model.Models; +using XinjingdailyBot.Service.Bot.Common; using XinjingdailyBot.Service.Data.Base; namespace XinjingdailyBot.Service.Data; /// [AppService(typeof(IDialogueService), LifeTime.Transient)] -internal sealed class DialogueService(ISqlSugarClient context) : BaseService(context), IDialogueService +internal sealed class DialogueService( + ISqlSugarClient context, + IChannelService _channelService) : BaseService(context), IDialogueService { public async Task RecordMessage(Message message) { @@ -45,8 +50,15 @@ public async Task RecordMessage(Message message) public Task> FetchUserGroupMessages(Users user, int startId = 0, int takeCount = 30) { + var groupIds = new List{ + _channelService.SubGroup.Id, + _channelService.CommentGroup.Id, + _channelService.ReviewGroup.Id, + _channelService.SecondCommentGroup?.Id ?? -1, + }.ToHashSet(); + return Queryable() - .Where(x => x.UserID == user.UserID && x.ChatID <= -1000000000000 && x.Id < startId) + .Where(x => x.UserID == user.UserID && groupIds.Contains(x.ChatID)) .WhereIF(startId != 0, x => x.Id < startId) .OrderByDescending(x => x.Id) .Take(takeCount) diff --git a/XinjingdailyBot.Service/Data/PostService.cs b/XinjingdailyBot.Service/Data/PostService.cs index da71e071..9ef0e3ce 100644 --- a/XinjingdailyBot.Service/Data/PostService.cs +++ b/XinjingdailyBot.Service/Data/PostService.cs @@ -36,6 +36,7 @@ internal sealed class PostService( ISqlSugarClient _context) : BaseService(_context), IPostService { private readonly OptionsSetting.PostOption _postOption = options.Value.Post; + private readonly bool _enableWebPagePreview = options.Value.Bot.EnableWebPagePreview; public async Task CheckPostLimit(Users dbUser, Message? message = null, CallbackQuery? query = null) { @@ -704,7 +705,7 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, bool seco Message? postMessage = null; if (post.PostType == MessageType.Text) { - postMessage = await _botClient.SendTextMessageAsync(acceptChannel, postText, parseMode: ParseMode.Html, disableWebPagePreview: true); + postMessage = await _botClient.SendTextMessageAsync(acceptChannel, postText, parseMode: ParseMode.Html, disableWebPagePreview: !_enableWebPagePreview); } else { @@ -792,7 +793,7 @@ public async Task AcceptPost(NewPosts post, Users dbUser, bool inPlan, bool seco else // 直接投稿, 在审核群留档 { string reviewMsg = _textHelperService.MakeReviewMessage(poster, post.Anonymous, second, publicMsg); - var msg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: true); + var msg = await _botClient.SendTextMessageAsync(_channelService.ReviewGroup.Id, reviewMsg, parseMode: ParseMode.Html, disableWebPagePreview: !_enableWebPagePreview); post.ReviewMsgID = msg.MessageId; } diff --git a/XinjingdailyBot.WebAPI/XinjingdailyBot.WebAPI.csproj b/XinjingdailyBot.WebAPI/XinjingdailyBot.WebAPI.csproj index 1e749080..a3a547d4 100644 --- a/XinjingdailyBot.WebAPI/XinjingdailyBot.WebAPI.csproj +++ b/XinjingdailyBot.WebAPI/XinjingdailyBot.WebAPI.csproj @@ -3,6 +3,7 @@ Exe Linux + ..\docker-compose.dcproj diff --git a/XinjingdailyBot.WebAPI/appsettings.json b/XinjingdailyBot.WebAPI/appsettings.json index d83f0a1a..0b478518 100644 --- a/XinjingdailyBot.WebAPI/appsettings.json +++ b/XinjingdailyBot.WebAPI/appsettings.json @@ -26,7 +26,8 @@ "AutoLeaveOtherGroup": false, "SuperAdmins": [], "EnablePlanPost": false, - "PostSecondMenu": false + "PostSecondMenu": false, + "EnableWebPagePreview": false }, // 频道设置 "Channel": { diff --git a/XinjingdailyBot.sln b/XinjingdailyBot.sln index 84f4418b..bf297203 100644 --- a/XinjingdailyBot.sln +++ b/XinjingdailyBot.sln @@ -61,6 +61,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XinjingdailyBot.Command", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XinjingdailyBot.Tasks", "XinjingdailyBot.Tasks\XinjingdailyBot.Tasks.csproj", "{6880F608-F263-473C-9B04-7C9F9972C1ED}" EndProject +Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{25B96B87-1072-4E7D-BD32-2D521731009D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -99,6 +101,10 @@ Global {6880F608-F263-473C-9B04-7C9F9972C1ED}.Debug|Any CPU.Build.0 = Debug|Any CPU {6880F608-F263-473C-9B04-7C9F9972C1ED}.Release|Any CPU.ActiveCfg = Release|Any CPU {6880F608-F263-473C-9B04-7C9F9972C1ED}.Release|Any CPU.Build.0 = Release|Any CPU + {25B96B87-1072-4E7D-BD32-2D521731009D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25B96B87-1072-4E7D-BD32-2D521731009D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25B96B87-1072-4E7D-BD32-2D521731009D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25B96B87-1072-4E7D-BD32-2D521731009D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/docker-compose.dcproj b/docker-compose.dcproj new file mode 100644 index 00000000..250f412a --- /dev/null +++ b/docker-compose.dcproj @@ -0,0 +1,16 @@ + + + + 2.1 + Linux + False + 25b96b87-1072-4e7d-bd32-2d521731009d + + + + docker-compose.yml + + + + + \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 00000000..b90df8bc --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,9 @@ +version: '3.4' + +services: + xinjingdailybot.webapi: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_HTTP_PORTS=8080 + ports: + - "8080" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..9deac610 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.4' + +services: + xinjingdailybot.webapi: + image: ${DOCKER_REGISTRY-}xinjingdailybotwebapi + build: + context: . + dockerfile: XinjingdailyBot.WebAPI/Dockerfile diff --git a/launchSettings.json b/launchSettings.json new file mode 100644 index 00000000..5320aaf4 --- /dev/null +++ b/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "Docker Compose": { + "commandName": "DockerCompose", + "commandVersion": "1.0", + "serviceActions": { + "xinjingdailybot.webapi": "StartDebugging" + } + } + } +} \ No newline at end of file