|
11 | 11 |
|
12 | 12 | from zhenxun.services.cache.runtime_cache import is_cache_ready |
13 | 13 | from zhenxun.services.log import logger |
14 | | -from zhenxun.services.message_load import is_overloaded, signal_overload |
| 14 | +from zhenxun.services.message_load import is_overloaded |
15 | 15 | from zhenxun.utils.utils import get_entity_ids |
16 | 16 |
|
17 | 17 | from .auth.config import LOGGER_COMMAND |
18 | | -from .auth.exception import SkipPluginException |
19 | 18 | from .auth_checker import ( |
20 | 19 | LimitManager, |
21 | 20 | _get_event_cache, |
22 | 21 | auth, |
23 | | - auth_ban_fast, |
24 | | - auth_precheck, |
25 | 22 | route_precheck, |
26 | 23 | ) |
27 | 24 |
|
28 | 25 | _SKIP_AUTH_PLUGINS = {"chat_history", "chat_message"} |
29 | 26 | _BOT_CONNECT_TS: float | None = None |
30 | 27 | _AUTH_QUEUE_MAXSIZE = 200 |
31 | | -_AUTH_QUEUE_HIGH_WATER = 160 |
32 | | -_AUTH_OVERLOAD_WINDOW = 5.0 |
33 | 28 | _AUTH_QUEUE: asyncio.Queue[tuple[Matcher, Event, Bot, Uninfo, UniMsg]] = asyncio.Queue( |
34 | 29 | maxsize=_AUTH_QUEUE_MAXSIZE |
35 | 30 | ) |
@@ -107,41 +102,30 @@ async def _auth_preprocessor( |
107 | 102 | ): |
108 | 103 | if event.get_type() == "message" and not is_cache_ready(): |
109 | 104 | raise IgnoredException("cache not ready ignore") |
110 | | - if _skip_auth_for_plugin(matcher): |
111 | | - return |
112 | 105 | start_time = time.time() |
113 | 106 | entity = get_entity_ids(session) |
114 | | - event_cache = _get_event_cache(event, session, entity) |
| 107 | + _get_event_cache(event, session, entity) |
| 108 | + |
115 | 109 | if await route_precheck(matcher, event, session, message): |
116 | 110 | return |
117 | | - try: |
118 | | - await auth_ban_fast(matcher, event, bot, session) |
119 | | - except SkipPluginException as exc: |
120 | | - logger.info(str(exc), LOGGER_COMMAND, session=session) |
121 | | - raise IgnoredException("ban fast ignore") from exc |
122 | | - try: |
123 | | - await auth_precheck(matcher, event, bot, session, message) |
124 | | - except SkipPluginException as exc: |
125 | | - logger.info(str(exc), LOGGER_COMMAND, session=session) |
126 | | - raise IgnoredException("precheck ignore") from exc |
127 | | - |
128 | | - if event_cache is not None and event_cache.get("route_skip") is True: |
129 | | - if not is_overloaded(): |
130 | | - logger.debug("route miss skip auth task", LOGGER_COMMAND) |
| 111 | + if _skip_auth_for_plugin(matcher): |
131 | 112 | return |
132 | 113 |
|
133 | 114 | try: |
134 | | - _AUTH_QUEUE.put_nowait((matcher, event, bot, session, message)) |
135 | | - except asyncio.QueueFull: |
136 | | - signal_overload(_AUTH_OVERLOAD_WINDOW) |
137 | | - now = time.monotonic() |
138 | | - global _LAST_DROP_LOG |
139 | | - if now - _LAST_DROP_LOG > 1.0: |
140 | | - _LAST_DROP_LOG = now |
141 | | - logger.warning("auth queue full, skip auth task", LOGGER_COMMAND) |
142 | | - return |
143 | | - if _AUTH_QUEUE.qsize() >= _AUTH_QUEUE_HIGH_WATER: |
144 | | - signal_overload(_AUTH_OVERLOAD_WINDOW) |
| 115 | + await auth( |
| 116 | + matcher, |
| 117 | + event, |
| 118 | + bot, |
| 119 | + session, |
| 120 | + message, |
| 121 | + skip_ban=False, |
| 122 | + ) |
| 123 | + except IgnoredException: |
| 124 | + raise |
| 125 | + except Exception as exc: |
| 126 | + logger.error("auth check failed", LOGGER_COMMAND, e=exc) |
| 127 | + raise IgnoredException("auth failed") from exc |
| 128 | + |
145 | 129 | now = time.monotonic() |
146 | 130 | last_log = getattr(_auth_preprocessor, "_last_log", 0.0) |
147 | 131 | if now - last_log > 1.0 and not is_overloaded(): |
|
0 commit comments