Skip to content

Commit 147b6c0

Browse files
committed
update
1 parent 3512351 commit 147b6c0

30 files changed

+1092
-1036
lines changed

XinjingdailyBot.Command/AdminCommand.cs

+33-25
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async Task<string> exec()
199199
{
200200
targetUser.IsBan = true;
201201
targetUser.ModifyAt = DateTime.Now;
202-
await _userService.Updateable(targetUser).UpdateColumns(x => new { x.IsBan, x.ModifyAt }).ExecuteCommandAsync();
202+
await _userService.Updateable(targetUser).UpdateColumns(static x => new { x.IsBan, x.ModifyAt }).ExecuteCommandAsync();
203203

204204
var record = new BanRecords {
205205
UserID = targetUser.UserID,
@@ -293,7 +293,7 @@ async Task<string> exec()
293293
{
294294
targetUser.IsBan = false;
295295
targetUser.ModifyAt = DateTime.Now;
296-
await _userService.Updateable(targetUser).UpdateColumns(x => new { x.IsBan, x.ModifyAt }).ExecuteCommandAsync();
296+
await _userService.Updateable(targetUser).UpdateColumns(static x => new { x.IsBan, x.ModifyAt }).ExecuteCommandAsync();
297297

298298
var record = new BanRecords {
299299
UserID = targetUser.UserID,
@@ -386,17 +386,20 @@ async Task<string> exec()
386386
else
387387
{
388388
//获取最近一条解封记录
389-
var lastUnbaned = await _banRecordService.Queryable().Where(x => x.UserID == targetUser.UserID && (x.Type == EBanType.UnBan || x.Type == EBanType.Ban))
390-
.OrderByDescending(x => x.BanTime).FirstAsync();
389+
var lastUnbaned = await _banRecordService.Queryable()
390+
.Where(x => x.UserID == targetUser.UserID && (x.Type == EBanType.UnBan || x.Type == EBanType.Ban))
391+
.OrderByDescending(static x => x.BanTime).FirstAsync();
391392

392393
int warnCount;
393394
if (lastUnbaned == null)
394395
{
395-
warnCount = await _banRecordService.Queryable().Where(x => x.UserID == targetUser.UserID && x.Type == EBanType.Warning).CountAsync();
396+
warnCount = await _banRecordService.Queryable()
397+
.Where(x => x.UserID == targetUser.UserID && x.Type == EBanType.Warning).CountAsync();
396398
}
397399
else
398400
{
399-
warnCount = await _banRecordService.Queryable().Where(x => x.UserID == targetUser.UserID && x.Type == EBanType.Warning && x.BanTime >= lastUnbaned.BanTime).CountAsync();
401+
warnCount = await _banRecordService.Queryable()
402+
.Where(x => x.UserID == targetUser.UserID && x.Type == EBanType.Warning && x.BanTime >= lastUnbaned.BanTime).CountAsync();
400403
}
401404

402405
var record = new BanRecords {
@@ -431,7 +434,7 @@ async Task<string> exec()
431434

432435
targetUser.IsBan = true;
433436
targetUser.ModifyAt = DateTime.Now;
434-
await _userService.Updateable(targetUser).UpdateColumns(x => new { x.IsBan, x.ModifyAt }).ExecuteCommandAsync();
437+
await _userService.Updateable(targetUser).UpdateColumns(static x => new { x.IsBan, x.ModifyAt }).ExecuteCommandAsync();
435438

436439
sb.AppendLine($"受到警告过多, 系统自动封禁该用户");
437440
}
@@ -499,8 +502,9 @@ public async Task ResponseQueryBan(Message message, string[] args)
499502
}
500503
else
501504
{
502-
var records = await _banRecordService.Queryable().Where(x => x.UserID == targetUser.UserID)
503-
.OrderByDescending(x => new { x.BanTime }).ToListAsync();
505+
var records = await _banRecordService.Queryable()
506+
.Where(x => x.UserID == targetUser.UserID)
507+
.OrderByDescending(static x => new { x.BanTime }).ToListAsync();
504508

505509
var status = targetUser.IsBan ? "已封禁" : "正常";
506510
sb.AppendLine($"用户名: {targetUser.HtmlUserLink()}");
@@ -518,9 +522,10 @@ public async Task ResponseQueryBan(Message message, string[] args)
518522
}
519523
else
520524
{
521-
var operators = records.Select(x => x.OperatorUID).Distinct();
525+
var operators = records.Select(static x => x.OperatorUID).Distinct();
522526

523-
var users = await _userService.Queryable().Where(x => operators.Contains(x.UserID)).Distinct().ToListAsync();
527+
var users = await _userService.Queryable()
528+
.Where(x => operators.Contains(x.UserID)).Distinct().ToListAsync();
524529

525530
foreach (var record in records)
526531
{
@@ -826,10 +831,10 @@ public async Task ResponsePostReport(Message message)
826831
sb.AppendLine($"过期投稿: <code>{yearExpiredPost}</code>");
827832
sb.AppendLine($"累计投稿: <code>{yearPost}</code>");
828833

829-
var totalPost = await _postService.Queryable().Where(x => x.Status > EPostStatus.Cancel).CountAsync();
830-
var totalAcceptPost = await _postService.Queryable().Where(x => x.Status == EPostStatus.Accepted).CountAsync();
831-
var totalRejectPost = await _postService.Queryable().Where(x => x.Status == EPostStatus.Rejected).CountAsync();
832-
var totalExpiredPost = await _postService.Queryable().Where(x => x.Status < 0).CountAsync();
834+
var totalPost = await _postService.Queryable().Where(static x => x.Status > EPostStatus.Cancel).CountAsync();
835+
var totalAcceptPost = await _postService.Queryable().Where(static x => x.Status == EPostStatus.Accepted).CountAsync();
836+
var totalRejectPost = await _postService.Queryable().Where(static x => x.Status == EPostStatus.Rejected).CountAsync();
837+
var totalExpiredPost = await _postService.Queryable().Where(static x => x.Status < 0).CountAsync();
833838
var totalChannel = await _channelOptionService.Queryable().CountAsync();
834839
var totalAttachment = await _attachmentService.Queryable().CountAsync();
835840

@@ -843,10 +848,10 @@ public async Task ResponsePostReport(Message message)
843848
sb.AppendLine($"附件总数: <code>{totalAttachment}</code>");
844849

845850
var totalUser = await _userService.Queryable().CountAsync();
846-
var banedUser = await _userService.Queryable().Where(x => x.IsBan).CountAsync();
851+
var banedUser = await _userService.Queryable().Where(static x => x.IsBan).CountAsync();
847852
var weekActiveUser = await _userService.Queryable().Where(x => x.ModifyAt >= prev7Days).CountAsync();
848853
var MonthActiveUser = await _userService.Queryable().Where(x => x.ModifyAt >= prev30Days).CountAsync();
849-
var postedUser = await _userService.Queryable().Where(x => x.PostCount > 0).CountAsync();
854+
var postedUser = await _userService.Queryable().Where(static x => x.PostCount > 0).CountAsync();
850855

851856
sb.AppendLine();
852857
sb.AppendLine("-- 用户统计 --");
@@ -984,8 +989,9 @@ public async Task ResponseUserRank(Message message)
984989
var sb = new StringBuilder();
985990

986991
sb.AppendLine("-- 用户投稿数量排名 --");
987-
var userAcceptCountRank = await _userService.Queryable().Where(x => !x.IsBan && !x.IsBot && x.GroupID == 1 && x.AcceptCount > miniumPost && x.ModifyAt >= prev30Days)
988-
.OrderByDescending(x => x.AcceptCount).Take(topCount).ToListAsync();
992+
var userAcceptCountRank = await _userService.Queryable()
993+
.Where(x => !x.IsBan && !x.IsBot && x.GroupID == 1 && x.AcceptCount > miniumPost && x.ModifyAt >= prev30Days)
994+
.OrderByDescending(static x => x.AcceptCount).Take(topCount).ToListAsync();
989995
if (userAcceptCountRank?.Count > 0)
990996
{
991997
var count = 1;
@@ -1001,8 +1007,9 @@ public async Task ResponseUserRank(Message message)
10011007

10021008
sb.AppendLine();
10031009
sb.AppendLine("-- 管理员投稿数量排名 --");
1004-
var adminAcceptCountRank = await _userService.Queryable().Where(x => !x.IsBan && !x.IsBot && x.GroupID > 1 && x.AcceptCount > miniumPost && x.ModifyAt >= prev30Days)
1005-
.OrderByDescending(x => x.AcceptCount).Take(topCount).ToListAsync();
1010+
var adminAcceptCountRank = await _userService.Queryable()
1011+
.Where(x => !x.IsBan && !x.IsBot && x.GroupID > 1 && x.AcceptCount > miniumPost && x.ModifyAt >= prev30Days)
1012+
.OrderByDescending(static x => x.AcceptCount).Take(topCount).ToListAsync();
10061013
if (adminAcceptCountRank?.Count > 0)
10071014
{
10081015
var count = 1;
@@ -1019,7 +1026,7 @@ public async Task ResponseUserRank(Message message)
10191026
sb.AppendLine();
10201027
sb.AppendLine("-- 管理员审核数量排名 --");
10211028
var adminReviewCountRank = await _userService.Queryable().Where(x => !x.IsBan && !x.IsBot && x.GroupID > 1 && x.ReviewCount > miniumPost && x.ModifyAt >= prev30Days)
1022-
.OrderByDescending(x => x.ReviewCount).Take(topCount).ToListAsync();
1029+
.OrderByDescending(static x => x.ReviewCount).Take(topCount).ToListAsync();
10231030
if (adminReviewCountRank?.Count > 0)
10241031
{
10251032
var count = 1;
@@ -1129,7 +1136,7 @@ async Task<string> exec()
11291136
{
11301137
targetUser.GroupID = groupID;
11311138
targetUser.ModifyAt = DateTime.Now;
1132-
await _userService.Updateable(targetUser).UpdateColumns(x => new { x.GroupID, x.ModifyAt }).ExecuteCommandAsync();
1139+
await _userService.Updateable(targetUser).UpdateColumns(static x => new { x.GroupID, x.ModifyAt }).ExecuteCommandAsync();
11331140

11341141
if (targetUser.PrivateChatID != -1)
11351142
{
@@ -1250,8 +1257,9 @@ public async Task ResponseNuke(Users dbUser, Message message, string[] args)
12501257
}
12511258

12521259
//获取最近一条解封记录
1253-
var lastUnbaned = await _banRecordService.Queryable().Where(x => x.UserID == targetUser.UserID && (x.Type == EBanType.UnBan || x.Type == EBanType.Ban))
1254-
.OrderByDescending(x => x.BanTime).FirstAsync();
1260+
var lastUnbaned = await _banRecordService.Queryable()
1261+
.Where(x => x.UserID == targetUser.UserID && (x.Type == EBanType.UnBan || x.Type == EBanType.Ban))
1262+
.OrderByDescending(static x => x.BanTime).FirstAsync();
12551263

12561264
int warnCount;
12571265
if (lastUnbaned == null)

XinjingdailyBot.Command/CommonCommand.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ public async Task ResponseVersion(Message message)
140140
[TextCmd("MYBAN", EUserRights.None, Description = "查询自己是否被封禁")]
141141
public async Task ResponseMyBan(Users dbUser, Message message)
142142
{
143-
var records = await _banRecordService.Queryable().Where(x => x.UserID == dbUser.UserID)
144-
.OrderByDescending(x => new { x.BanTime }).ToListAsync();
143+
var records = await _banRecordService.Queryable()
144+
.Where(x => x.UserID == dbUser.UserID)
145+
.OrderByDescending(static x => new { x.BanTime }).ToListAsync();
145146

146147
var sb = new StringBuilder();
147148

XinjingdailyBot.Command/NormalCommand.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task ResponseAnonymous(Users dbUser, Message message)
8181
bool anymouse = !dbUser.PreferAnonymous;
8282
dbUser.PreferAnonymous = anymouse;
8383
dbUser.ModifyAt = DateTime.Now;
84-
await _userService.Updateable(dbUser).UpdateColumns(x => new { x.PreferAnonymous, x.ModifyAt }).ExecuteCommandAsync();
84+
await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.PreferAnonymous, x.ModifyAt }).ExecuteCommandAsync();
8585

8686
var mode = anymouse ? "匿名投稿" : "保留来源";
8787
var text = $"后续投稿将默认使用【{mode}】";
@@ -106,7 +106,7 @@ public async Task ResponseNotification(Users dbUser, Message message)
106106
bool notificationg = !dbUser.Notification;
107107
dbUser.Notification = notificationg;
108108
dbUser.ModifyAt = DateTime.Now;
109-
await _userService.Updateable(dbUser).UpdateColumns(x => new { x.Notification, x.ModifyAt }).ExecuteCommandAsync();
109+
await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.Notification, x.ModifyAt }).ExecuteCommandAsync();
110110

111111
var mode = notificationg ? "接收通知" : "静默模式";
112112
var text = $"稿件被审核或者过期时将会尝试通知用户\n当前通知设置: {mode}";
@@ -339,11 +339,11 @@ public async Task QGetRandomPost(Users dbUser, CallbackQuery callbackQuery, stri
339339
var tag = tagId != 0 ? _tagRepository.GetTagById(tagId) : null;
340340

341341
var randomPost = await _postService.Queryable()
342-
.Where(x => x.Status == EPostStatus.Accepted)
343-
.WhereIF(postType == null, x => x.PostType != MessageType.Text)
342+
.Where(static x => x.Status == EPostStatus.Accepted)
343+
.WhereIF(postType == null, static x => x.PostType != MessageType.Text)
344344
.WhereIF(postType != null, x => x.PostType == postType)
345345
.WhereIF(tag != null, x => (x.Tags & tag!.Seg) > 0)
346-
.OrderBy(x => SqlFunc.GetRandom()).FirstAsync();
346+
.OrderBy(static x => SqlFunc.GetRandom()).FirstAsync();
347347

348348
if (randomPost != null)
349349
{

XinjingdailyBot.Command/PostCommand.cs

+21-8
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private async Task SetAnymouse(NewPosts post, CallbackQuery query)
108108
bool anonymous = !post.Anonymous;
109109
post.Anonymous = anonymous;
110110
post.ModifyAt = DateTime.Now;
111-
await _postService.Updateable(post).UpdateColumns(x => new { x.Anonymous, x.ModifyAt }).ExecuteCommandAsync();
111+
await _postService.Updateable(post).UpdateColumns(static x => new { x.Anonymous, x.ModifyAt }).ExecuteCommandAsync();
112112

113113
var keyboard = _markupHelperService.PostKeyboard(anonymous);
114114
await _botClient.EditMessageReplyMarkupAsync(query.Message!, keyboard);
@@ -124,7 +124,8 @@ private async Task CancelPost(NewPosts post, CallbackQuery query)
124124
{
125125
post.Status = EPostStatus.Cancel;
126126
post.ModifyAt = DateTime.Now;
127-
await _postService.Updateable(post).UpdateColumns(x => new { x.Status, x.ModifyAt }).ExecuteCommandAsync();
127+
128+
await _postService.Updateable(post).UpdateColumns(static x => new { x.Status, x.ModifyAt }).ExecuteCommandAsync();
128129

129130
await _botClient.EditMessageTextAsync(query.Message!, Langs.PostCanceled, replyMarkup: null);
130131

@@ -163,10 +164,22 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query)
163164
}
164165

165166
group[i] = attachmentType switch {
166-
MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? post.Text : null, ParseMode = ParseMode.Html },
167-
MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? post.Text : null, ParseMode = ParseMode.Html },
168-
MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)) { Caption = i == 0 ? post.Text : null, ParseMode = ParseMode.Html },
169-
MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)) { Caption = i == attachments.Count - 1 ? post.Text : null, ParseMode = ParseMode.Html },
167+
MessageType.Photo => new InputMediaPhoto(new InputFileId(attachments[i].FileID)) {
168+
Caption = i == 0 ? post.Text : null,
169+
ParseMode = ParseMode.Html
170+
},
171+
MessageType.Audio => new InputMediaAudio(new InputFileId(attachments[i].FileID)) {
172+
Caption = i == 0 ? post.Text : null,
173+
ParseMode = ParseMode.Html
174+
},
175+
MessageType.Video => new InputMediaVideo(new InputFileId(attachments[i].FileID)) {
176+
Caption = i == 0 ? post.Text : null,
177+
ParseMode = ParseMode.Html
178+
},
179+
MessageType.Document => new InputMediaDocument(new InputFileId(attachments[i].FileID)) {
180+
Caption = i == attachments.Count - 1 ? post.Text : null,
181+
ParseMode = ParseMode.Html
182+
},
170183
_ => throw new Exception(),
171184
};
172185
}
@@ -191,7 +204,7 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query)
191204
post.ReviewActionMsgID = manageMsg.MessageId;
192205
post.Status = EPostStatus.Reviewing;
193206
post.ModifyAt = DateTime.Now;
194-
await _postService.Updateable(post).UpdateColumns(x => new {
207+
await _postService.Updateable(post).UpdateColumns(static x => new {
195208
x.ReviewChatID,
196209
x.ReviewMsgID,
197210
x.ReviewActionChatID,
@@ -206,6 +219,6 @@ private async Task ConfirmPost(NewPosts post, Users dbUser, CallbackQuery query)
206219

207220
dbUser.PostCount++;
208221
dbUser.ModifyAt = DateTime.Now;
209-
await _userService.Updateable(dbUser).UpdateColumns(x => new { x.PostCount, x.ModifyAt }).ExecuteCommandAsync();
222+
await _userService.Updateable(dbUser).UpdateColumns(static x => new { x.PostCount, x.ModifyAt }).ExecuteCommandAsync();
210223
}
211224
}

XinjingdailyBot.Command/ReviewCommand.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ async Task<string> exec()
9999
/// <summary>
100100
/// 修改稿件文字说明
101101
/// </summary>
102-
/// <param name="dbUser"></param>
103102
/// <param name="message"></param>
104103
/// <param name="args"></param>
105104
/// <returns></returns>
106105
[TextCmd("EDIT", EUserRights.ReviewPost, Description = "修改稿件文字说明")]
107-
public async Task ResponseEditPost(Users dbUser, Message message, string[] args)
106+
public async Task ResponseEditPost(Message message, string[] args)
108107
{
109108
async Task<string> exec()
110109
{
@@ -136,7 +135,7 @@ async Task<string> exec()
136135
}
137136

138137
post.Text = string.Join(' ', args).Trim();
139-
await _postService.Updateable(post).UpdateColumns(x => new { x.Text }).ExecuteCommandAsync();
138+
await _postService.Updateable(post).UpdateColumns(static x => new { x.Text }).ExecuteCommandAsync();
140139

141140
return "稿件描述已更新";
142141
}
@@ -250,7 +249,7 @@ private async Task SetAnymouse(NewPosts post, CallbackQuery query)
250249
bool anonymous = !post.Anonymous;
251250
post.Anonymous = anonymous;
252251
post.ModifyAt = DateTime.Now;
253-
await _postService.Updateable(post).UpdateColumns(x => new { x.Anonymous, x.ModifyAt }).ExecuteCommandAsync();
252+
await _postService.Updateable(post).UpdateColumns(static x => new { x.Anonymous, x.ModifyAt }).ExecuteCommandAsync();
254253

255254
bool? hasSpoiler = post.CanSpoiler ? post.HasSpoiler : null;
256255

@@ -274,7 +273,7 @@ private async Task SetSpoiler(NewPosts post, CallbackQuery query)
274273

275274
post.HasSpoiler = !post.HasSpoiler;
276275
post.ModifyAt = DateTime.Now;
277-
await _postService.Updateable(post).UpdateColumns(x => new { x.HasSpoiler, x.ModifyAt }).ExecuteCommandAsync();
276+
await _postService.Updateable(post).UpdateColumns(static x => new { x.HasSpoiler, x.ModifyAt }).ExecuteCommandAsync();
278277

279278
await _botClient.AutoReplyAsync(post.HasSpoiler ? "启用遮罩" : "禁用遮罩", query);
280279

@@ -294,7 +293,7 @@ private async Task CancelPost(NewPosts post, CallbackQuery query)
294293
{
295294
post.Status = EPostStatus.Cancel;
296295
post.ModifyAt = DateTime.Now;
297-
await _postService.Updateable(post).UpdateColumns(x => new { x.Status, x.ModifyAt }).ExecuteCommandAsync();
296+
await _postService.Updateable(post).UpdateColumns(static x => new { x.Status, x.ModifyAt }).ExecuteCommandAsync();
298297

299298
await _botClient.EditMessageTextAsync(query.Message!, Langs.PostCanceled, replyMarkup: null);
300299

0 commit comments

Comments
 (0)