User:ChristieBot/Messages.py
from dataclasses import dataclass
from enum import Enum
from typing import Optional
import GA_config
class MessageKind(str, Enum):
EDITOR_ERROR = "editor_error"
BOT_ERROR = "bot_error"
DEBUG = "debug"
class MessageScope(str, Enum):
NOMINATION = "nomination"
RUN = "run"
@dataclass
class BotMessage:
kind: MessageKind
scope: MessageScope
short_text: str
source: str
title: Optional[str] = None
page_no: Optional[int] = None
exception_text: Optional[str] = None
# Compatibility fields
nomination_obj: Optional[object] = None
nomination_msgs: Optional[list] = None
gan_error_text: Optional[str] = None
def report_message(ctx, msg: BotMessage):
"""
Central message router.
Runtime-log policy:
- DEBUG messages still print directly.
- EDITOR_ERROR messages do not print by default; they are routed to the
on-wiki error surfaces instead.
- BOT_ERROR messages emit one compact runtime line and are also summarized
to the on-wiki bug page input list.
Transient operational issues are handled separately by
GAN.report_operational_issue(...), which also updates the operational
status page.
"""
del ctx # retained only for backward-compatible call signature
if msg.kind == MessageKind.DEBUG:
print(f"[DEBUG:{msg.source}] {msg.short_text}", flush=True)
return
if msg.kind == MessageKind.EDITOR_ERROR:
# Preserve nomination-local warning behavior
if msg.nomination_obj is not None and hasattr(msg.nomination_obj, "warnings"):
msg.nomination_obj.warnings.append(msg.short_text)
# Also support pre-Nom nomination message accumulation
if msg.nomination_msgs is not None:
msg.nomination_msgs.append(msg.short_text)
# Preserve aggregate GAN errors page input behavior
if msg.gan_error_text is not None:
GA_config.current_errors.append(msg.gan_error_text)
else:
if msg.title is not None and msg.page_no is not None:
GA_config.current_errors.append(
f"[[{msg.title}]] / {msg.page_no}: {msg.short_text}\n"
)
elif msg.title is not None:
GA_config.current_errors.append(
f"[[{msg.title}]]: {msg.short_text}\n"
)
else:
GA_config.current_errors.append(msg.short_text + "\n")
return
if msg.kind == MessageKind.BOT_ERROR:
# Keep runtime output compact. Detailed technical context belongs in
# explicit exception/operational logging, not in routine .out chatter.
print(f"[BOT_ERROR:{msg.source}] {msg.short_text}", flush=True)
summary_line = (
f"ChristieBot encountered an internal error in {msg.source}. "
f"The bot continued running."
)
bug_msg = (
f"{summary_line}\n"
f"Detailed technical information was written to the runtime logs."
)
if bug_msg not in GA_config.current_bug_messages:
GA_config.current_bug_messages.append(bug_msg)
return
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.