Skip to content

Commit

Permalink
continue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Nov 10, 2024
1 parent 788e58c commit 61a65ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions Bot/Clash/Phaser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private static void Init()
IEnumerable<IGrouping<long, MainRequirement>> eachLatestReq = MainRequirement.FetchEachLatest()
.GroupBy(req => req.EndTime);
long currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
// Store new req objects to be inserted later
List<MainRequirement> insertReqs = [];

Check warning on line 62 in Bot/Clash/Phaser.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CollectionNeverQueried.Local] Content of collection 'insertReqs' is only updated but never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Clash/Phaser.cs(62,31)

foreach (IGrouping<long, MainRequirement> reqGroup in eachLatestReq)
{
Expand All @@ -66,20 +68,23 @@ private static void Init()
{
foreach (MainRequirement req in reqGroup)
{
req.Passed = Pass.Overdue;
req.Update();
insertReqs.Add(SetPass(req, Pass.Overdue));
}

continue;
}

// Very rare - now has req to check, update their pass status
if (reqGroup.Key == currentTime)
{

foreach (MainRequirement req in reqGroup)
{
insertReqs.Add(CheckReq(req));
}
}
}

Task.Delay(-1);
Task.Delay(-1).Wait();

IEnumerable<IGrouping<long, Main>> donationGroups = Main.FetchAll()
.GroupBy(static d => d.Checked)
Expand Down Expand Up @@ -120,6 +125,25 @@ private static void Init()
Console.WriteLine("[Donate25] Inited");
}

/// Sets a req object's pass status, execute Update and returns the next due req.
private static MainRequirement SetPass(MainRequirement req, Pass pass)
{
req.Passed = pass;
req.Update();
return new(req.MainId, req.EndTime + CheckPeriod);
}

/// When a req is due, use this function to determine whether it passed and failed.
/// It will also call SetPass()
private static MainRequirement CheckReq(MainRequirement req)
{
bool donate25 = req.Donated >= 25;
bool raid1 = req.Raided > 0;

bool passed = donate25 || raid1;
return SetPass(req, passed ? Pass.Passed : Pass.Failed);
}

private static void AltAdded(Main altMain, Main mainMain)
{
string altId = altMain.AccountId, mainId = mainMain.AccountId;
Expand Down
2 changes: 1 addition & 1 deletion Bot/Sql/MainRequirement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MainRequirement() : this("", 0) { }

internal override int Update()
{
List<MainRequirement>? result = s_db.Query<MainRequirement>("UPDATE MainRequirement SET Pass = ?, Donated = ?, Raided = ? WHERE MainId = ? AND EndTime = ?", Passed, Donated, Raided, MainId, EndTime);
List<MainRequirement>? result = s_db.Query<MainRequirement>("UPDATE MainRequirement SET Passed = ?, Donated = ?, Raided = ? WHERE MainId = ? AND EndTime = ?", Passed, Donated, Raided, MainId, EndTime);
return result.Count;
}

Expand Down

0 comments on commit 61a65ea

Please sign in to comment.