-"""Count tracking logic."""
+"""Count tracking logic and bot's external interface."""
from contextlib import nullcontext as nullcontext
from dataclasses import dataclass
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
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:
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(
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