Add live thread read-only switch for local testing
authorJakob Cornell <jakob+gpg@jcornell.net>
Thu, 21 Jul 2022 03:07:55 +0000 (22:07 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Thu, 21 Jul 2022 03:31:08 +0000 (22:31 -0500)
src/strikebot/__init__.py

index d75d4d1163479ee4b11b6aafd6f24b2e6246c356..7c37d140408f1f419a2cee25b04d8ab9ccf3cca8 100644 (file)
@@ -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"])