auth IDs = 13 15
bot user = count_better
+
+# if false, don't strike or delete updates or report incorrectly stricken updates (optional, default true)
enforcing = true
# log messages at or above this severity to standard out; level names and numbers are supported (optional, default
# WARNING); see https://docs.python.org/3/library/logging.html#levels
log level = WARNING
+# if true, don't modify the live thread at all (implies enforcing = false) (optional, default false)
+read-only = false
+
thread ID = abc123
__version__ = importlib.metadata.version(__package__)
-_READ_ONLY: bool = False # suppress any API requests that modify the thread?
-
-
@dataclass
class _Update:
id: str
thread_id: str,
bot_user: str,
enforcing: bool,
+ read_only: bool,
update_retention: dt.timedelta,
logger: logging.Logger,
) -> None:
from strikebot.reddit_api import CorrectionUpdateRequest, DeleteRequest, ReportUpdateRequest, StrikeRequest
- enforcing = enforcing and not _READ_ONLY
+ enforcing = enforcing and not read_only
buffer_ = []
timeline = []
if parts:
parts.append(_format_curr_count(last_valid))
- if not _READ_ONLY:
+ if not read_only:
api_pool.enqueue_request(CorrectionUpdateRequest(thread_id, "\n\n".join(parts)))
for invalid_tu in newly_invalid:
api_pool.enqueue_request(StrikeRequest(thread_id, update.name, update.ts))
update.stricken = True
- if not _READ_ONLY and 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)))
async with message_rx:
slot.update.stricken = True
if isinstance(slot, _TimelineUpdate) and slot.accepted:
logger.info(f"bad strike of {slot.update.id}")
- if not _READ_ONLY:
+ if not read_only:
body = _format_bad_strike_alert(slot.update, thread_id)
api_pool.enqueue_request(CorrectionUpdateRequest(thread_id, body))
else:
api_pool_error_window = dt.timedelta(seconds = main_cfg.getfloat("API pool error window"))
auth_ids = set(map(int, main_cfg["auth IDs"].split()))
bot_user = main_cfg["bot user"]
-enforcing = main_cfg.getboolean("enforcing")
+enforcing = main_cfg.getboolean("enforcing", fallback = True)
raw_log_level = main_cfg.get("log level", "WARNING")
try:
except ValueError:
log_level = raw_log_level
+read_only = main_cfg.getboolean("read-only", fallback = False)
reorder_buffer_time = dt.timedelta(seconds = main_cfg.getfloat("reorder buffer time"))
request_queue_limit = main_cfg.getint("request queue limit")
thread_id = main_cfg["thread ID"]
db_connect_params = {k: getters.get(k, db_cfg.get)(k) for k in db_cfg}
+if read_only and enforcing:
+ raise RuntimeError("can't use read-only mode with enforcing on")
+
+
logger = getLogger(__package__)
logger.setLevel(logging.NOTSET - 1) # NOTSET means inherit from parent; we use handlers to filter
nursery_c.start_soon(ws_pool.conn_refresher_impl)
nursery_c.start_soon(
- count_tracker_impl, message_rx, api_pool, reorder_buffer_time, thread_id, bot_user, enforcing,
+ count_tracker_impl, message_rx, api_pool, reorder_buffer_time, thread_id, bot_user, enforcing, read_only,
update_retention, logger.getChild("track")
)
await ws_pool.init_workers()