Skip to content

Commit

Permalink
UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Nov 29, 2023
1 parent 7f3cb5b commit d0ee6a5
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.2.4.6</Version>
<Version>2.2.4.7</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions XinjingdailyBot.Infrastructure/OptionsSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public sealed record BotOption
/// 二级菜单
/// </summary>
public bool PostSecondMenu { get; set; }
/// <summary>
/// 文本稿件发布时是否启用链接预览
/// </summary>
public bool EnableWebPagePreview { get; set; }
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion XinjingdailyBot.Service/Bot/Common/ChannelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 14 additions & 2 deletions XinjingdailyBot.Service/Data/DialogueService.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <inheritdoc cref="IDialogueService"/>
[AppService(typeof(IDialogueService), LifeTime.Transient)]
internal sealed class DialogueService(ISqlSugarClient context) : BaseService<Dialogue>(context), IDialogueService
internal sealed class DialogueService(
ISqlSugarClient context,
IChannelService _channelService) : BaseService<Dialogue>(context), IDialogueService
{
public async Task RecordMessage(Message message)
{
Expand Down Expand Up @@ -45,8 +50,15 @@ public async Task RecordMessage(Message message)

public Task<List<Dialogue>> FetchUserGroupMessages(Users user, int startId = 0, int takeCount = 30)
{
var groupIds = new List<long>{
_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)
Expand Down
5 changes: 3 additions & 2 deletions XinjingdailyBot.Service/Data/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal sealed class PostService(
ISqlSugarClient _context) : BaseService<NewPosts>(_context), IPostService
{
private readonly OptionsSetting.PostOption _postOption = options.Value.Post;
private readonly bool _enableWebPagePreview = options.Value.Bot.EnableWebPagePreview;

public async Task<bool> CheckPostLimit(Users dbUser, Message? message = null, CallbackQuery? query = null)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions XinjingdailyBot.WebAPI/XinjingdailyBot.WebAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion XinjingdailyBot.WebAPI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"AutoLeaveOtherGroup": false,
"SuperAdmins": [],
"EnablePlanPost": false,
"PostSecondMenu": false
"PostSecondMenu": false,
"EnableWebPagePreview": false
},
// 频道设置
"Channel": {
Expand Down
6 changes: 6 additions & 0 deletions XinjingdailyBot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.dcproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<DockerPublishLocally>False</DockerPublishLocally>
<ProjectGuid>25b96b87-1072-4e7d-bd32-2d521731009d</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.4'

services:
xinjingdailybot.webapi:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=8080
ports:
- "8080"
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.4'

services:
xinjingdailybot.webapi:
image: ${DOCKER_REGISTRY-}xinjingdailybotwebapi
build:
context: .
dockerfile: XinjingdailyBot.WebAPI/Dockerfile
11 changes: 11 additions & 0 deletions launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"Docker Compose": {
"commandName": "DockerCompose",
"commandVersion": "1.0",
"serviceActions": {
"xinjingdailybot.webapi": "StartDebugging"
}
}
}
}

0 comments on commit d0ee6a5

Please sign in to comment.