From: Jakob Cornell Date: Thu, 21 Jul 2022 03:07:55 +0000 (-0500) Subject: Add live thread read-only switch for local testing X-Git-Tag: strikebot-0.0.7~28 X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=62b7306ad5d1da49de5f4ea050526a1d3caadaf5;p=counting.git Add live thread read-only switch for local testing --- diff --git a/src/strikebot/__init__.py b/src/strikebot/__init__.py index d75d4d1..7c37d14 100644 --- a/src/strikebot/__init__.py +++ b/src/strikebot/__init__.py @@ -19,6 +19,9 @@ from strikebot.updates import Command, parse_update __version__ = importlib.metadata.version(__package__) +_READ_ONLY: bool = False # suppress any API requests that modify the thread? + + @dataclass class _Update: id: str @@ -101,6 +104,8 @@ async def count_tracker_impl( ) -> None: from strikebot.reddit_api import CorrectionUpdateRequest, DeleteRequest, ReportUpdateRequest, StrikeRequest + enforcing = enforcing and not _READ_ONLY + buffer_ = [] timeline = [] last_valid: Optional[_Update] = None @@ -194,7 +199,8 @@ async def count_tracker_impl( if parts: parts.append(_format_curr_count(last_valid)) - api_pool.enqueue_request(CorrectionUpdateRequest(thread_id, "\n\n".join(parts))) + if not _READ_ONLY: + api_pool.enqueue_request(CorrectionUpdateRequest(thread_id, "\n\n".join(parts))) for invalid_tu in newly_invalid: if not invalid_tu.update.stricken: @@ -206,7 +212,7 @@ async def count_tracker_impl( api_pool.enqueue_request(StrikeRequest(thread_id, update.name, update.ts)) update.stricken = True - if update.command is Command.REPORT: + if not _READ_ONLY and update.command is Command.REPORT: api_pool.enqueue_request(ReportUpdateRequest(thread_id, body = _format_curr_count(last_valid))) with message_rx: @@ -262,8 +268,9 @@ async def count_tracker_impl( slot.update.stricken = True if isinstance(slot, _TimelineUpdate) and slot.accepted: logger.info(f"bad strike of {slot.update.id}") - body = _format_bad_strike_alert(slot.update, thread_id) - api_pool.enqueue_request(CorrectionUpdateRequest(thread_id, body)) + if not _READ_ONLY: + body = _format_bad_strike_alert(slot.update, thread_id) + api_pool.enqueue_request(CorrectionUpdateRequest(thread_id, body)) else: pending_strikes.add(msg.data["payload"])