Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Nov 23, 2023
1 parent 51f74be commit f50f621
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 42 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.3</Version>
<Version>2.2.4.4</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
10 changes: 5 additions & 5 deletions XinjingdailyBot.Command/AdminCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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($"接受/拒绝: <code>{todayAcceptPost}</code> / <code>{todayRejectPost}</code>");
if (second)
{
var todayAcceptSecondPost = await _postService.CountAcceptedSecondPosts(prev1Day);
var todayAcceptSecondPost = await _postService.CountAcceptedSecondPosts(today);
sb.AppendLine($"接受(二频): <code>{todayAcceptSecondPost}</code>");
}
sb.AppendLine($"通过率: <code>{(todayPost > 0 ? (100 * todayAcceptPost / todayPost).ToString("f2") : "--")}%</code>");
Expand Down
5 changes: 1 addition & 4 deletions XinjingdailyBot.Command/CommonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion XinjingdailyBot.Command/PostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
1 change: 0 additions & 1 deletion XinjingdailyBot.Command/SuperCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public async Task ResponseReCalcPost(Message message)
user.RejectCount = rejectCount;
user.ExpiredPostCount = expiredCount;
user.ReviewCount = reviewCount;
user.ModifyAt = DateTime.Now;

effectCount++;

Expand Down
7 changes: 7 additions & 0 deletions XinjingdailyBot.Interface/Data/IAdvertisePostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ namespace XinjingdailyBot.Interface.Data;
/// </summary>
public interface IAdvertisePostService : IBaseService<AdvertisePosts>
{
/// <summary>
/// 添加广告
/// </summary>
/// <param name="ad"></param>
/// <param name="chatId"></param>
/// <param name="msgId"></param>
/// <returns></returns>
Task AddAdPost(Advertises ad, long chatId, int msgId);

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions XinjingdailyBot.Interface/Data/IAdvertiseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ namespace XinjingdailyBot.Interface.Data;
/// </summary>
public interface IAdvertiseService : IBaseService<Advertises>
{
/// <summary>
/// 创建广告
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
Task CreateAdvertise(Message message);

/// <summary>
/// 获取可用的广告消息
/// </summary>
/// <returns></returns>
Task<Advertises?> GetPostableAdvertise();
/// <summary>
/// 更新广告统计
/// </summary>
/// <param name="ad"></param>
/// <returns></returns>
Task UpdateAdvertiseStatistics(Advertises ad);
}
2 changes: 2 additions & 0 deletions XinjingdailyBot.Interface/Data/IBanRecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface IBanRecordService : IBaseService<BanRecords>
/// <param name="targetUser"></param>
/// <returns></returns>
Task<List<BanRecords>> GetBanRecores(Users targetUser);
Task<List<BanRecords>> GetBanRecores(Users targetUser, DateTime expireTime);

/// <summary>
/// 获取最近封禁/解封记录
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions XinjingdailyBot.Interface/Data/ICmdRecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,28 @@ public interface ICmdRecordService : IBaseService<CmdRecords>
/// <param name="exception"></param>
/// <returns></returns>
Task AddCmdRecord(CallbackQuery query, Users dbUser, bool handled, bool isQuery, string? exception);
/// <summary>
/// 获取命令调用记录
/// </summary>
/// <param name="msgId"></param>
/// <returns></returns>
Task<CmdRecords> FetchCmdRecordByMessageId(int msgId);
/// <summary>
/// 获取错误命令调用数
/// </summary>
/// <param name="startTime"></param>
/// <returns></returns>
Task<int> GetErrorCmdCount(DateTime startTime);
/// <summary>
/// 获取查询命令调用数
/// </summary>
/// <param name="startTime"></param>
/// <returns></returns>
Task<int> GetQueryCmdCount(DateTime startTime);
/// <summary>
/// 获取文本命令调用数
/// </summary>
/// <param name="startTime"></param>
/// <returns></returns>
Task<int> GetTextCmdCount(DateTime startTime);
}
7 changes: 7 additions & 0 deletions XinjingdailyBot.Interface/Data/IDialogueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ namespace XinjingdailyBot.Interface.Data;
/// </summary>
public interface IDialogueService : IBaseService<Dialogue>
{
/// <summary>
/// 获取用户的群组消息记录
/// </summary>
/// <param name="user"></param>
/// <param name="startId"></param>
/// <param name="takeCount"></param>
/// <returns></returns>
Task<List<Dialogue>> FetchUserGroupMessages(Users user, int startId = 0, int takeCount = 30);

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions XinjingdailyBot.Interface/Data/IPostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,26 @@ public interface IPostService : IBaseService<NewPosts>
/// </summary>
/// <returns></returns>
Task<int> CountRejectedPosts();
/// <summary>
/// 获取待审核稿件
/// </summary>
/// <param name="afterTime"></param>
/// <returns></returns>
Task<int> CountReviewingPosts(DateTime afterTime);

/// <summary>
/// 编辑稿件描述
/// </summary>
/// <param name="post"></param>
/// <param name="text"></param>
/// <returns></returns>
Task EditPostText(NewPosts post, string text);
/// <summary>
/// 是否存在指定媒体组ID的稿件
/// </summary>
/// <param name="mediaGroupId"></param>
/// <returns></returns>
Task<bool> IfExistsMediaGroupId(string mediaGroupId);

/// <summary>
/// 从审核回调中获取稿件
Expand All @@ -114,6 +127,12 @@ public interface IPostService : IBaseService<NewPosts>
/// <param name="message"></param>
/// <returns></returns>
Task<NewPosts?> FetchPostFromReplyToMessage(Message message);
/// <summary>
/// 获取计划发布的投稿
/// </summary>
/// <returns></returns>
Task<NewPosts> GetInPlanPost();

/// <summary>
/// 获取最新未审核稿件
/// </summary>
Expand All @@ -125,6 +144,11 @@ public interface IPostService : IBaseService<NewPosts>
/// <param name="postId"></param>
/// <returns></returns>
Task<NewPosts?> GetPostByPostId(int postId);
/// <summary>
/// 获取随机稿件
/// </summary>
/// <returns></returns>
Task<NewPosts?> GetRandomPost();

/// <summary>
/// 处理多媒体投稿(mediaGroup)
Expand Down
12 changes: 12 additions & 0 deletions XinjingdailyBot.Interface/Data/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public interface IUserService : IBaseService<Users>
/// <param name="groupId"></param>
/// <returns></returns>
Task UpdateUserGroupId(Users user, int groupId);
/// <summary>
/// 设置用户通知偏好
/// </summary>
/// <param name="user"></param>
/// <param name="notification"></param>
/// <returns></returns>
Task SetUserNotification(Users user, bool notification);
/// <summary>
/// 设置默认匿名偏好
/// </summary>
/// <param name="user"></param>
/// <param name="preferAnonymous"></param>
/// <returns></returns>
Task SetUserPreferAnonymous(Users user, bool preferAnonymous);
}
15 changes: 6 additions & 9 deletions XinjingdailyBot.Service/Bot/Handler/ChannelPostHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand All @@ -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;
Expand Down Expand Up @@ -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);
});
}
}
Expand All @@ -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);
}

//记录媒体组
Expand Down
7 changes: 2 additions & 5 deletions XinjingdailyBot.Service/Bot/Handler/InlineQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using SqlSugar;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions XinjingdailyBot.Service/Data/BanRecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public Task<List<BanRecords>> GetBanRecores(Users targetUser)
.OrderByDescending(static x => new { x.BanTime }).ToListAsync();
}

public Task<List<BanRecords>> GetBanRecores(Users targetUser, DateTime expireTime)
{
return Queryable()
.Where(x => x.UserID == targetUser.UserID && (x.Type != EBanType.Warning || x.BanTime > expireTime))
.ToListAsync();
}

public async Task<BanRecords?> GetLatestBanRecord(long userId)
{
return await Queryable()
Expand Down
7 changes: 6 additions & 1 deletion XinjingdailyBot.Service/Data/DialogueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public async Task RecordMessage(Message message)

public Task<List<Dialogue>> 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();
}
}
26 changes: 22 additions & 4 deletions XinjingdailyBot.Service/Data/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -1088,6 +1084,11 @@ public Task<int> CountExpiredPosts(DateTime afterTime)
return Queryable().Where(x => x.CreateAt >= afterTime && x.Status < 0).CountAsync();
}

public Task<int> CountReviewingPosts(DateTime afterTime)
{
return Queryable().Where(x => x.CreateAt >= afterTime && x.Status == EPostStatus.Reviewing).CountAsync();
}

public Task RevocationPost(NewPosts post)
{
post.Status = EPostStatus.Revocation;
Expand Down Expand Up @@ -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<bool> IfExistsMediaGroupId(string mediaGroupId)
{
return Queryable().AnyAsync(x => x.OriginMediaGroupID == mediaGroupId);
}

public async Task<NewPosts?> GetRandomPost()
{
return await Queryable()
.Where(static x => x.Status == EPostStatus.Accepted && x.PostType == MessageType.Photo)
.OrderBy(static x => SqlFunc.GetRandom()).FirstAsync();
}

public Task<NewPosts> GetInPlanPost()
{
return Queryable().Where(static x => x.Status == EPostStatus.InPlan).FirstAsync();
}
}
Loading

0 comments on commit f50f621

Please sign in to comment.