Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
更新: 签到流程优化;
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanray committed Aug 30, 2020
1 parent 1374bbd commit 69c033d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cx-auto-sign/WorkCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json.Linq;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
Expand All @@ -14,6 +15,10 @@ namespace cx_auto_sign
[Command(Description = "工作模式, 监听签到任务并自动签到")]
class WorkCommand : CommandBase
{
/// <summary>
/// 班级的群聊ID - 上一次查询的签到任务数量
/// </summary>
private Dictionary<string, int> CidCountPair = new Dictionary<string, int>();

protected override async Task<int> OnExecuteAsync(CommandLineApplication app)
{
Expand Down Expand Up @@ -64,15 +69,25 @@ protected override async Task<int> OnExecuteAsync(CommandLineApplication app)
var cidStr = Encoding.ASCII.GetString(cid);
Log.Information("收到来自 {cidStr} 的消息", cidStr);
// 签到流程
Log.Information("正在签到中...");
var course = Courses.Where(x => x.ChatId == cidStr).FirstOrDefault();
if (course is null) return;
Log.Information("获取课程 {courseName} 的签到任务...", course.CourseName);
var signTasks = await client.GetSignTasksAsync(course.CourseId, course.ClassId);
foreach (var task in signTasks)
if (!CidCountPair.ContainsKey(cidStr)) CidCountPair.Add(cidStr, -1);
if (CidCountPair[cidStr] != signTasks.Count)
{
await client.SignAsync(task);
Log.Information("正在签到课程 {courseName} 的所有签到任务...", course.CourseName);
foreach (var task in signTasks)
{
await client.SignAsync(task);
}
CidCountPair[cidStr] = signTasks.Count;
Log.Information("已完成该课程所有签到");
}
else
{
Log.Information("课程 {courseName} 没有新的签到任务", course.CourseName);
}
Log.Information("已完成该课程所有签到");
}
}
Expand Down

0 comments on commit 69c033d

Please sign in to comment.