From afae43915c8ed78e3a7b6f144312d4b8c85f5638 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Tue, 27 Sep 2022 23:26:22 -0500 Subject: [PATCH] Disqualify stricken updates from validity on ingest & resync --- strikebot/src/strikebot/__init__.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/strikebot/src/strikebot/__init__.py b/strikebot/src/strikebot/__init__.py index 77be977..daa9944 100644 --- a/strikebot/src/strikebot/__init__.py +++ b/strikebot/src/strikebot/__init__.py @@ -1,4 +1,4 @@ -"""Count tracking logic.""" +"""Count tracking logic and bot's external interface.""" from contextlib import nullcontext as nullcontext from dataclasses import dataclass @@ -143,12 +143,12 @@ async def count_tracker_impl( or ( update.number is not None and (pred is None or pred.number is None or update.can_follow(pred)) + and not update.stricken ) ) logger.debug("{} {} -> {}".format("accepted" if tu.accepted else "rejected", pred, update)) if tu.accepted: # resync subsequent updates - newly_valid = [] newly_invalid = [] resync_last_valid = update converged = False @@ -158,14 +158,16 @@ async def count_tracker_impl( if last_valid: converged = True elif scan_tu.update.number is not None: - accept = resync_last_valid.number is None or scan_tu.update.can_follow(resync_last_valid) - if accept and scan_tu.accepted: + accept = ( + (resync_last_valid.number is None or scan_tu.update.can_follow(resync_last_valid)) + and not scan_tu.update.stricken + ) + if accept: + assert scan_tu.accepted + resync_last_valid = scan_tu.update # resync would have no effect past this point if last_valid: converged = True - elif accept: - newly_valid.append(scan_tu) - resync_last_valid = scan_tu.update elif scan_tu.accepted: newly_invalid.append(scan_tu) if scan_tu.update is last_valid: @@ -180,12 +182,6 @@ async def count_tracker_impl( last_valid = resync_last_valid parts = [] - if newly_valid: - parts.append( - "The following counts are valid:\n\n" - + "\n".join(" - " + _format_update_ref(tu.update, thread_id) for tu in newly_valid) - ) - unstrikable = [tu for tu in newly_invalid if tu.update.stricken] if unstrikable: parts.append( @@ -207,7 +203,7 @@ async def count_tracker_impl( if enforcing: api_pool.enqueue_request(StrikeRequest(thread_id, invalid_tu.update.name, invalid_tu.update.ts)) invalid_tu.update.stricken = True - elif update.count_attempt: + elif update.count_attempt and not update.stricken: if enforcing: api_pool.enqueue_request(StrikeRequest(thread_id, update.name, update.ts)) update.stricken = True -- 2.30.2